Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Fix DDP support #1182

Merged
merged 18 commits into from
Feb 22, 2022
Merged

Fix DDP support #1182

merged 18 commits into from
Feb 22, 2022

Conversation

ethanwharris
Copy link
Collaborator

@ethanwharris ethanwharris commented Feb 21, 2022

What does this PR do?

Fixes #1153

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • 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?
  • Did you write any new necessary tests? [not needed for typos/docs]
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@ethanwharris ethanwharris added the bug / fix Something isn't working label Feb 21, 2022
@ethanwharris ethanwharris added this to the 0.7.x milestone Feb 21, 2022
@codecov
Copy link

codecov bot commented Feb 21, 2022

Codecov Report

Merging #1182 (d598948) into master (a396e26) will increase coverage by 0.01%.
The diff coverage is 83.78%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1182      +/-   ##
==========================================
+ Coverage   90.92%   90.94%   +0.01%     
==========================================
  Files         283      284       +1     
  Lines       12701    12687      -14     
==========================================
- Hits        11549    11538      -11     
+ Misses       1152     1149       -3     
Flag Coverage Δ
unittests 90.94% <83.78%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
flash/core/data/io/input.py 93.95% <ø> (+1.01%) ⬆️
flash/image/classification/model.py 81.03% <0.00%> (ø)
flash/image/segmentation/model.py 92.94% <0.00%> (ø)
flash/text/classification/model.py 93.33% <0.00%> (ø)
flash/text/question_answering/input.py 95.12% <0.00%> (ø)
flash/text/seq2seq/core/input.py 97.29% <0.00%> (ø)
flash/core/trainer.py 91.20% <85.71%> (-1.03%) ⬇️
flash/core/data/io/transform_predictions.py 100.00% <100.00%> (ø)
flash/text/question_answering/model.py 91.89% <100.00%> (-0.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a396e26...d598948. Read the comment docs.

@Borda Borda added the Priority label Feb 21, 2022
@ethanwharris ethanwharris marked this pull request as ready for review February 21, 2022 16:58
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

do we have already removed the hardcoded run only on one GPU?

flash/core/trainer.py Outdated Show resolved Hide resolved
flash/core/trainer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@krshrimali krshrimali left a comment

Choose a reason for hiding this comment

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

Thanks, @ethanwharris for working on this! LGTM. Have a couple of questions, but shouldn't block merging this PR.

Asking for my knowledge, what really fixed the issue?

tests/examples/test_scripts.py Outdated Show resolved Hide resolved
Comment on lines +44 to +48
predictions = predict_step(*args, **kwargs)
if predictions is not None:
predictions = self.output_transform(predictions)
predictions = [self.output(prediction) for prediction in predictions]
return predictions
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, when do you think predictions would be None? Should that be counted as a failure? Or a warning be raised that the OutputTransform and Output instances passed were not used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there are some cases where it can be None but not sure, it may just be within our tests that it can be None. But yeah, could be better to have an error there

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll also see if there is a possibility that predictions can be None, but for now - I guess we can merge this PR and create a small follow-up PR if required (for the error).

Comment on lines -303 to -338
def __getstate__(self):
"""Temporarily override pickle behaviour.

TODO: New DataPipeline should avoid this being pickled.
"""
state = self.__dict__.copy()
state.pop("data")
if "data_iter" in state:
state.pop("data_iter")
return state

def __setstate__(self, newstate):
"""Temporarily override pickle behaviour.

TODO: New DataPipeline should avoid this being pickled.
"""
newstate["data"] = None
self.__dict__.update(newstate)

def __copy__(self):
"""The default copy implementation seems to use ``__getstate__`` and ``__setstate__`` so we override it
here with a custom implementation to ensure that it includes the data list."""
cls = self.__class__
result = cls.__new__(cls)
result.__dict__.update(self.__dict__)
return result

def __deepcopy__(self, memo):
"""The default deepcopy implementation seems to use ``__getstate__`` and ``__setstate__`` so we override it
here with a custom implementation to ensure that it includes the data list."""
cls = self.__class__
result = cls.__new__(cls)
memo[id(self)] = result
for k, v in self.__dict__.items():
setattr(result, k, deepcopy(v, memo))
return result
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@krshrimali This is the main fix. We used to have a bug where the data was accidentally included in the checkpoint. We patched that by adding this overrides. But then DDP spawn needs to pickle the data to send it to each process so this causes problems. We refactored away the bit that got this included in the checkpoint so now can be safely removed 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thank you so much for the explanation, @ethanwharris!

@ethanwharris ethanwharris merged commit 5cf1321 into master Feb 22, 2022
@ethanwharris ethanwharris deleted the bugfix/ddp branch February 22, 2022 19:28
ethanwharris added a commit that referenced this pull request Mar 1, 2022
Co-authored-by: Jirka Borovec <[email protected]>
ethanwharris added a commit that referenced this pull request Mar 1, 2022
Co-authored-by: Jirka Borovec <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug / fix Something isn't working Priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Summarization example raises "Total length of Dataloader across ranks is zero" when on >1 GPUs
3 participants