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

remove trainer hidden state | sanity refactor [2 / n] #7507

Merged
merged 12 commits into from
May 17, 2021

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented May 12, 2021

What does this PR do?

Follow up to #7437 with more writable state removed from trainer:

  • Trainer.hiddens
  • Trainer.split_idx
  • multiple_trainloader_mode does not belong in TrainLoop

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented May 12, 2021

Codecov Report

Merging #7507 (44c08d5) into master (a584196) will decrease coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #7507   +/-   ##
======================================
- Coverage      92%     92%   -0%     
======================================
  Files         196     196           
  Lines       12828   12827    -1     
======================================
- Hits        11825   11808   -17     
- Misses       1003    1019   +16     

@awaelchli awaelchli added this to the v1.4 milestone May 12, 2021
@awaelchli awaelchli marked this pull request as ready for review May 12, 2021 19:23
@awaelchli awaelchli added the ready PRs ready to be merged label May 12, 2021
@awaelchli awaelchli requested a review from ananthsub May 12, 2021 19:23
@@ -1619,7 +1619,7 @@ def get_progress_bar_dict(self):
module_tbptt_enabled = self.truncated_bptt_steps > 0
trainer_tbptt_enabled = self.trainer.truncated_bptt_steps is not None and self.trainer.truncated_bptt_steps > 0
if module_tbptt_enabled or trainer_tbptt_enabled:
tqdm_dict["split_idx"] = self.trainer.split_idx
tqdm_dict["split_idx"] = self.trainer.train_loop.split_idx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is get_progress_bar_dict still needed on the lightning module? wouldn't things come from self.log ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's for users to override and customize the default elements in the progress bar. Like how the version number is displayed or apparently the split index here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not something one could customize through self.log directly I would say.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it customization we would want to push to a custom progress bar callback instead of being part of the core module?

Copy link
Contributor

@carmocca carmocca May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom progress bar callback instead of being part of the core module?

IMO yes for maximum separation of concerns

But people might complain about having to define a custom progress bar just for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one could argue maybe the split_idx is not very useful to display in the progbar but still I would keep the hook


self.global_step = 0
self.current_epoch = 0
self.trainer.should_stop = False

self.total_batch_idx = 0
self.batch_idx = 0
self.split_idx = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • is this meant to be writable from the outside? should these be made available as properties instead?
  • while going through this, could you add a comment for what split_idx means for contributors who go through this code later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no but for now I follow the above pattern and the major goal is to define this state strictly on the loop, not the trainer anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while going through this, could you add a comment for what split_idx means for contributors who go through this code later?

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay added comments

pytorch_lightning/trainer/training_loop.py Show resolved Hide resolved
@@ -1619,7 +1619,7 @@ def get_progress_bar_dict(self):
module_tbptt_enabled = self.truncated_bptt_steps > 0
trainer_tbptt_enabled = self.trainer.truncated_bptt_steps is not None and self.trainer.truncated_bptt_steps > 0
if module_tbptt_enabled or trainer_tbptt_enabled:
tqdm_dict["split_idx"] = self.trainer.split_idx
tqdm_dict["split_idx"] = self.trainer.train_loop.split_idx
Copy link
Contributor

@carmocca carmocca May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom progress bar callback instead of being part of the core module?

IMO yes for maximum separation of concerns

But people might complain about having to define a custom progress bar just for this

pytorch_lightning/trainer/training_loop.py Show resolved Hide resolved
@awaelchli awaelchli enabled auto-merge (squash) May 13, 2021 00:48
@awaelchli awaelchli disabled auto-merge May 13, 2021 00:48
@awaelchli awaelchli enabled auto-merge (squash) May 13, 2021 00:48
@mergify mergify bot removed the has conflicts label May 13, 2021
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@awaelchli awaelchli merged commit 6e6e29a into master May 17, 2021
@awaelchli awaelchli deleted the refactor/trainer-state-sanity-1 branch May 17, 2021 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready PRs ready to be merged refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants