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

Loop specialization #8226

Merged
merged 171 commits into from
Jul 19, 2021
Merged

Loop specialization #8226

merged 171 commits into from
Jul 19, 2021

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Jun 30, 2021

What does this PR do?

Enables loop specialization through a connect mechanism.
Three main use cases:

A) Set loop directly on the trainer:

class MyFitLoop(FitLoop):
    # this loop has no nested loops
    ...

trainer = Trainer()
trainer.fit_loop = MyFitLoop()

B) Connect child loops to the main loop (nesting):

class MyFitLoop(FitLoop):
    # this loop defines subloops
    
    def connect(self, child0, child1):
        self.child0 = child0
        ...

trainer = Trainer()
fit_loop = MyFitLoop()
child_loop = MyChildLoop()
fit_loop.connect(child_loop)

trainer.fit_loop = fit_loop

C) Connect a custom loop to an existing Lightning loop:

class CustomBatchLoop(TrainingBatchLoop):
    # this loop is a custom implementation of the Lightning built-in batch loop
    ...

trainer = Trainer()
my_batch_loop = CustomBatchLoop()
trainer.fit_loop.epoch_loop.connect(my_batch_loop)

Setting the trainer references is handled internally by Lightning. The user does NOT connect the trainer directly to the loop.

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?

I made sure I had fun coding 🙃

@pep8speaks
Copy link

pep8speaks commented Jun 30, 2021

Hello @awaelchli! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-07-19 11:55:06 UTC

@codecov
Copy link

codecov bot commented Jun 30, 2021

Codecov Report

Merging #8226 (8a58e01) into master (7bb810f) will increase coverage by 0%.
The diff coverage is 97%.

@@           Coverage Diff           @@
##           master   #8226    +/-   ##
=======================================
  Coverage      92%     92%            
=======================================
  Files         217     217            
  Lines       14094   14341   +247     
=======================================
+ Hits        13001   13236   +235     
- Misses       1093    1105    +12     

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.

Hey @ananthsub @awaelchli, what are your thoughts there ?

@awaelchli awaelchli changed the title Loop specialization [WIP] Loop specialization Jul 16, 2021
Base automatically changed from add_progress_tracking_on_loops to master July 19, 2021 08:31
@awaelchli awaelchli marked this pull request as ready for review July 19, 2021 10:05
@awaelchli awaelchli modified the milestones: v1.3.x, v1.4 Jul 19, 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.

Looks neat !

@Borda Borda added the feature Is an improvement or enhancement label Jul 19, 2021
@mergify mergify bot added the ready PRs ready to be merged label Jul 19, 2021
Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com>
@awaelchli awaelchli enabled auto-merge (squash) July 19, 2021 13:08
@awaelchli awaelchli merged commit 7d93d70 into master Jul 19, 2021
@awaelchli awaelchli deleted the refactor/loops/customization-1 branch July 19, 2021 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Includes a design discussion feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants