-
Notifications
You must be signed in to change notification settings - Fork 759
[Feature] add tensorbard support to the training framework #811
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
Open
lyuwen
wants to merge
6
commits into
allenai:main
Choose a base branch
from
lyuwen:feature-tensorbard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e3fa07
[feature] enable logging to tensorbard
lyuwen c2cf78f
Merge branch 'allenai:main' into feature-tensorbard
lyuwen 36e3030
Make tensorboard logger an abject of the Trainer class instead of a
lyuwen 74f32d8
rename log_to_tensorbard to tensorboard_path
lyuwen 104e515
fixed a typo
lyuwen 121aae1
Merge branch 'main' into feature-tensorbard
lyuwen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import os.path as osp | ||
| from torch.utils.tensorboard import SummaryWriter | ||
|
|
||
|
|
||
| # create a new class inheriting from SummaryWriter | ||
| class NewSummaryWriter(SummaryWriter): | ||
|
|
||
| def __init__(self, log_dir=None, comment="", **kwargs): | ||
| super().__init__(log_dir, comment, **kwargs) | ||
|
|
||
|
|
||
| # create a new function that will take dictionary as input | ||
| # and uses built-in add_scalar() function | ||
| # that function combines all plots into one subgroup by a tag | ||
| def add_scalar_dict(self, dictionary, global_step, tag=None): | ||
| for name, val in dictionary.items(): | ||
| if tag is not None: | ||
| name = osp.join(tag, name) | ||
| self.add_scalar(name, val, global_step) | ||
|
|
||
|
|
||
| writer = None | ||
|
lyuwen marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def init(log_dir=None): | ||
| global writer | ||
| writer = NewSummaryWriter(log_dir=log_dir) | ||
|
|
||
|
|
||
| def log(dictionary, global_step, tag=None): | ||
| global writer | ||
| if writer is None: | ||
| return | ||
| writer.add_scalar_dict(dictionary, global_step, tag) | ||
|
|
||
|
|
||
| def write_args_to_tensorboard(args, iteration, prefix=""): | ||
| """Write arguments to tensorboard.""" | ||
| global writer | ||
| if writer: | ||
| if prefix: | ||
| prefix = f"{prefix}." | ||
| for arg in args.keys(): | ||
| arg_text = f"{prefix}{arg}" | ||
| if isinstance(args[arg], dict): | ||
| write_args_to_tensorboard(args[arg], iteration, prefix=arg_text) | ||
| else: | ||
| writer.add_text(arg_text, str(args[arg]), global_step=iteration) | ||
|
|
||
|
|
||
| def finish(): | ||
| global writer | ||
| if writer is None: | ||
| return | ||
| writer.close() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.