fix: Use DistributedSampler for dataloader instead of splitting dataset#456
fix: Use DistributedSampler for dataloader instead of splitting dataset#456garrett4wade merged 10 commits intomainfrom
Conversation
Summary of ChangesHello @dhh1995, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness and correctness of distributed training by addressing a critical flaw in how datasets were previously split across multiple processes. By transitioning to Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a critical issue in distributed training where uneven dataset splitting could cause processes to hang. The solution of replacing manual dataset splitting with torch.utils.data.DistributedSampler is a solid approach and has been applied consistently across most of the example scripts. This is a great improvement for the stability and correctness of distributed training. I've identified a few critical issues in the implementation: a couple of dataset loading functions were missed during the refactoring, which will lead to runtime errors, and there's a logical error in the new create_dataloader utility. Once these are addressed, the PR will be in excellent shape.
|
In addition:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the dataset loading mechanism to use torch.utils.data.DistributedSampler instead of manually splitting datasets with split_dataset_by_node. This is a solid improvement that correctly addresses the issue of uneven data distribution across ranks, which could cause training to hang.
I've identified a few critical issues where the refactoring was incomplete, leading to NameError or TypeError in some dataset loading functions. I've also pointed out one function that was missed during the refactoring. Please address these points to ensure the stability and consistency of the new data loading pipeline.
Overall, great work on centralizing the distributed data loading logic!
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the dataset loading logic to use DistributedSampler instead of manually splitting datasets, which is a great improvement to prevent training hangs in distributed setups. The changes are extensive and correctly applied across most of the example scripts. However, I've identified three critical issues that will cause runtime errors and need to be addressed: a broken fallback in the new get_custom_dataset function, an oversight in updating one of the dataset helper functions (get_geometry3k_sft_dataset), and a NameError in another (get_torl_data_rl_dataset). Once these are fixed, the PR should be in good shape.
…et (inclusionAI#456) * use DistributedSampler and update get_custom_dataset interface * apply changes to all other examples * fix remaining datasets based on gemini review
Issue
When splitting datasets among different ranks, the len(dataloader) could be different.
This could lead to the training process getting stuck.
Example
255 data points, batch_size=64, world_size=8, and batch_size on each rank is
64 / 8 = 8.Then steps_per_epoch should be
255 // 64 = 3when drop_last is true.However, when using split_dataset_by_node to split the dataset, ranks 0-6 receive 32 data points, and rank 7 receives 31.
Then, when using dataloader for these split datasets, the rank 7 gets
steps_per_epoch=3(because31 // 8 = 3whendrop_lastis true) while others getsteps_per_epoch=4.Solution
We use DistributedSampler instead to sample a distributed batch.
This PR applies this change to all examples.