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

move batch to device before sending it to hooks #7378

Merged
merged 80 commits into from
Jul 5, 2021
Merged

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented May 5, 2021

What does this PR do?

Fixes #7377
Fixes #6990

In the loops we have the following structure:

on_train_batch_start(batch)  # master: batch on CPU, this PR: batch is on GPU
accelerator.training_step(batch) # master: batch gets moved to GPU here, this PR: batch is already on GPU here
on_train_batch_end(batch)  # master: batch on CPU, this PR: batch is on GPU

Test fails on master.

Open to suggestions for a more elegant way to test.

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 🙃

@awaelchli awaelchli added bug Something isn't working feature Is an improvement or enhancement labels May 5, 2021
@awaelchli awaelchli added this to the v1.4 milestone May 5, 2021
@codecov
Copy link

codecov bot commented May 5, 2021

Codecov Report

Merging #7378 (542efbd) into master (8193bae) will decrease coverage by 5%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #7378    +/-   ##
=======================================
- Coverage      93%     88%    -5%     
=======================================
  Files         212     212            
  Lines       13720   13716     -4     
=======================================
- Hits        12751   12070   -681     
- Misses        969    1646   +677     

@awaelchli awaelchli changed the title [wip] move batch to device before sending it to hooks [wip] [blocked by #7394] move batch to device before sending it to hooks May 6, 2021
@awaelchli awaelchli changed the title [wip] [blocked by #7394] move batch to device before sending it to hooks move batch to device before sending it to hooks May 6, 2021
@mergify mergify bot removed the has conflicts label Jul 1, 2021
@awaelchli awaelchli force-pushed the bugfix/batch-device branch from d987d90 to a787df5 Compare July 1, 2021 19:19
This reverts commit a6e6101.

Revert "debug"

This reverts commit 5ddeaec.

debug


debug


Revert "debug"

This reverts commit 605be74.

Revert "Revert "debug""

This reverts commit a7612d5.

debug


x


x


x


s


tol


x


tol
@awaelchli awaelchli force-pushed the bugfix/batch-device branch from 00dd96a to c712b62 Compare July 1, 2021 19:31
@awaelchli awaelchli changed the title move batch to device before sending it to hooks [wip] move batch to device before sending it to hooks Jul 1, 2021
Copy link
Contributor Author

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

Re-requesting review from all. Since the creation of this PR we moved to the new loop API.

benchmarks/test_basic_parity.py Show resolved Hide resolved
@mergify mergify bot removed the has conflicts label Jul 2, 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 !

pytorch_lightning/accelerators/accelerator.py Show resolved Hide resolved
@tchaton tchaton enabled auto-merge (squash) July 5, 2021 08:31
@tchaton tchaton merged commit ea5cfd2 into master Jul 5, 2021
@tchaton tchaton deleted the bugfix/batch-device branch July 5, 2021 08:31
Copy link
Contributor

@kaushikb11 kaushikb11 left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature Is an improvement or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

on_train_batch_end receives batch on CPU Eliminate redundant device moves for callbacks
9 participants