-
Notifications
You must be signed in to change notification settings - Fork 1k
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
separate dataloader generator from sampler generator #789
separate dataloader generator from sampler generator #789
Conversation
The documentation is not available anymore as the PR was closed or merged. |
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.
Thanks for diving into this! Just have one main comment but it's looking great already! Very clean fix!
This PR currently will break accelerate/src/accelerate/data_loader.py Line 653 in 37b2aa0
accelerate/src/accelerate/data_loader.py Line 658 in 37b2aa0
accelerate/src/accelerate/data_loader.py Line 677 in 37b2aa0
(Of course accelerate/src/accelerate/data_loader.py Line 698 in 37b2aa0
This code duplication (for finding the sampler) also impairs readability instead of improving readability. batch_sampler = self.sampler if isinstance(self.sampler, BatchSampler) else self.batch_sampler
sampler = (
batch_sampler.batch_sampler.sampler
if hasattr(batch_sampler, "batch_sampler")
else batch_sampler.sampler
)
if hasattr(sampler, "generator"):
generator = sampler.generator
synchronize_rng_states(self.rng_types, generator) I believe what needs to be synchronized is IterableDataset's generator(according to |
@YouJiacheng I am not seeing any breaks in all the lines you mention, which are completely orthogonal to the change suggested. As for the code duplication, let us worry about readability as maintainers :-) We cannot store the generator as a private attribute as it is fetched in two different functions. |
By "break", I means that these lines will become useless. And for |
Ah!, I get what you mean, thanks for clarifying! We should indeed make the difference between the The check on |
It's hard to explain my proposal using text. So I open a parallel PR to show the code.(It is somewhat "pseudocode"/proof of concept, since I didn't test it). |
@YouJiacheng Thanks for taking the time to draft a PR to show your points, it's much clearer this way! I think we need to merge the two PRs somehow as they both contain important things the other has not. |
Co-Authored-By: YouJiacheng <1503679330@qq.com> Co-Authored-By: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
What does this PR do?
sampler.generator
andloader.generator
to leave loader's generator unsynchronized by default. #786Example script for testing the updated code:
Output logs (num_workers=4 and pay attention to the
random_augmentation
data which isn't same across GPUs, hence solving the issue mentioned):