Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context manager for common event metadata. #745

Open
tillahoffmann opened this issue Jan 9, 2025 · 2 comments
Open

Context manager for common event metadata. #745

tillahoffmann opened this issue Jan 9, 2025 · 2 comments

Comments

@tillahoffmann
Copy link

I often have code that looks like this.

writer.add_scalar("foo", some_value, global_step=step)
writer.add_scalar("bar", another_value, global_step=step)
writer.add_scalar("baz", yet_another_value, global_step=step)

There is some repetition with specifying the global_step, and I often forget to specify the step which leads to unexpected results in tensorboard (that's of course a user error). It might be possible to address both using a context manager like so.

with writer.use_global_step(step):
    writer.add_scalar("foo", some_value)
    writer.add_scalar("bar", another_value)
    writer.add_scalar("baz", yet_another_value)

Where global_step now defaults to whatever is specified as the argument to use_global_step (or a better function name). It would also be possible to incorporate the walltime parameter with a signature like use_metadata(*, global_step=None, walltime=None), where the user can specify global_step, walltime, or both.

Is this of interest? Happy to send a PR if so.

Thank you for the great library!

@lanpa
Copy link
Owner

lanpa commented Jan 10, 2025

@tillahoffmann Please sent a PR! I recently changed the package config of this repository to uv, hope that doesn't mess things up while developing new features.

tillahoffmann added a commit to tillahoffmann/tensorboardX that referenced this issue Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@tillahoffmann @lanpa and others