-
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
Add branch condition for calling move to device in prefetch (FSDP 3/n) #6342
Conversation
|
||
@pytest.mark.parametrize('move_to_device_pre_dispatch_enabled', [True, False]) | ||
@mock.patch('pytorch_lightning.plugins.DDPPlugin.model_to_device') | ||
def test_move_to_device_in_pre_dispatch(mock_model_to_device, tmpdir, move_to_device_pre_dispatch_enabled): |
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.
Two things:
- Would've liked to add a spawn test but mocks don't seem to carry across to new processes?
- Can I combine patch and parametrize?
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.
- Nope, you'd have to create the mock in each process
- What do you mean? Having different mocks for each parametrize? I don't think so
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.
You might be able to do so with a callback, applying the patch context manager.
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.
You can make patch conditional on parametrize. with the return object.
Codecov Report
@@ Coverage Diff @@
## master #6342 +/- ##
=======================================
+ Coverage 91% 92% +1%
=======================================
Files 160 161 +1
Lines 11408 11476 +68
=======================================
+ Hits 10384 10547 +163
+ Misses 1024 929 -95 |
@property | ||
def call_move_to_device_hook_in_pre_dispatch(self) -> bool: | ||
""" | ||
Call the ``model_to_device`` function within pre_dispatch if this is set to True. | ||
Useful for when plugin would like to call model_to_device at another time, or skip the call. | ||
""" | ||
return True |
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.
Should this be in ParallelPlugin
?
): | ||
model = BoringModel() | ||
trainer = Trainer( | ||
default_root_dir=tmpdir, fast_dev_run=True, accelerator='ddp', plugins=DDPPlugin(), num_processes=1 |
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.
Why do you need to pass DDPPlugin
?
|
||
@pytest.mark.parametrize('move_to_device_pre_dispatch_enabled', [True, False]) | ||
@mock.patch('pytorch_lightning.plugins.DDPPlugin.model_to_device') | ||
def test_move_to_device_in_pre_dispatch(mock_model_to_device, tmpdir, move_to_device_pre_dispatch_enabled): |
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.
- Nope, you'd have to create the mock in each process
- What do you mean? Having different mocks for each parametrize? I don't think so
Co-authored-by: Carlos Mocholí <[email protected]>
Hey @SeanNaren. Any updates ? |
Given how little now exists in the pre_dispatch function after #6506, we don't need this anymore :) |
What does this PR do?
Adds an additional property to the DDP/DDP Spawn Plugin that allows plugins that extend DDP to disable moving model to device. In FSDP this is required since we can only move to device after configure_ddp is called, which would require overriding this function pre_dispatch. Also fixed an issue where spawning the DDP Plugin was not possible because we missed copying a default setter.
Fixes #<issue_number>
Before submitting
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:
Did you have fun?
Make sure you had fun coding 🙃