-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Make default tqdm dict overridable #749
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,23 +679,9 @@ def training_tqdm_dict(self): | |
"""Read-only for tqdm metrics. | ||
:return: | ||
""" | ||
tqdm_dict = { | ||
'loss': '{0:.3f}'.format(self.avg_loss), | ||
'batch_idx': '{}'.format(self.batch_idx), | ||
} | ||
ref_model = self.model if not self.data_parallel else self.model.module | ||
|
||
if self.truncated_bptt_steps is not None: | ||
tqdm_dict['split_idx'] = self.split_idx | ||
|
||
if self.logger is not None and self.logger.version is not None: | ||
tqdm_dict['v_num'] = self.logger.version | ||
|
||
tqdm_dict.update(self.tqdm_metrics) | ||
|
||
if self.on_gpu: | ||
tqdm_dict['gpu'] = '{}'.format(torch.cuda.current_device()) | ||
|
||
return tqdm_dict | ||
return dict(**ref_model.get_tqdm_dict(), **self.tqdm_metrics) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would go with if self.tqdm_metrics == None:
return ref_model.get_tqdm_dict()
else:
return self.tqdm_metrics so that that the default dict can be completely overloaded There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is already can be completely overloaded :) So if you return an empty dict in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, sorry for the noise, I thought that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, now it can be found as one of the methods of |
||
|
||
@property | ||
def tng_tqdm_dic(self): | ||
|
@@ -853,7 +839,7 @@ def run_pretrain_routine(self, model): | |
pbar = tqdm(desc='Validation sanity check', | ||
total=self.num_sanity_val_steps * len(self.get_val_dataloaders()), | ||
leave=False, position=2 * self.process_position, | ||
disable=not self.show_progress_bar, dynamic_ncols=True, unit='batch') | ||
disable=not self.show_progress_bar, dynamic_ncols=True) | ||
self.main_progress_bar = pbar | ||
# dummy validation progress bar | ||
self.val_progress_bar = tqdm(disable=True) | ||
|
@@ -871,7 +857,7 @@ def run_pretrain_routine(self, model): | |
|
||
# init progress bar | ||
pbar = tqdm(leave=True, position=2 * self.process_position, | ||
disable=not self.show_progress_bar, dynamic_ncols=True, unit='batch', | ||
disable=not self.show_progress_bar, dynamic_ncols=True, | ||
file=sys.stdout) | ||
self.main_progress_bar = pbar | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it as property like a
tqdm_params
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, at first I made it property. But then I accidentally found out that it will cause misleading error messages, if there is an attribute error in the user code. What I mean, if you make
Then after
you will get
I don't know how to fix it, but it seems to be the known issue: https://stackoverflow.com/questions/15348331/why-does-property-decorator-show-object-has-no-attribute
Overall, I decided to stay without property, so the user gets the clear error message if there is some error in his code.