Skip to content

[fix] Shuffle dataset for each epoch#1082

Draft
mignonjia wants to merge 3 commits intohao-ai-lab:mainfrom
mignonjia:mhuo-fixshuffle
Draft

[fix] Shuffle dataset for each epoch#1082
mignonjia wants to merge 3 commits intohao-ai-lab:mainfrom
mignonjia:mhuo-fixshuffle

Conversation

@mignonjia
Copy link
Collaborator

The current implementation access the dataset following the same order for each epoch.

Add shuffle at the beginning of each epoch.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mignonjia, 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 enhances the dataset loading mechanism by introducing the ability to shuffle data at the beginning of each training epoch. Previously, the dataset order remained static across epochs, which could lead to biases in model training. The new implementation ensures that data samples are presented in a randomized order for every epoch, improving the robustness and generalization capabilities of models trained using this dataset. This functionality is configurable via a new parameter and command-line argument.

Highlights

  • Dataset Shuffling Control: Introduced a new reshuffle_each_epoch parameter to ParquetMapStyleDataset and related functions, allowing explicit control over whether the dataset order is randomized at the start of each epoch.
  • Epoch-based Randomization: Modified the dataset's index building logic to incorporate the current epoch number into the random seed, ensuring a unique data permutation for every epoch when shuffling is enabled.
  • External Epoch Management: Added a set_epoch method to ParquetMapStyleDataset, providing a mechanism to update the dataset's internal epoch counter and trigger a re-shuffling of indices.
  • CLI Argument for Shuffling: Exposed the reshuffle_each_epoch functionality as a command-line argument (--reshuffle-each-epoch) in fastvideo_args.py, making it configurable during training runs.
  • Refactored Index Building: The logic for constructing dataset indices has been moved into a dedicated _build_indices method for better organization and reusability, especially for epoch-based reshuffling.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • fastvideo/dataset/parquet_dataset_map_style.py
    • Added reshuffle_each_epoch: bool = True to the __init__ method of ParquetMapStyleDataset.
    • Refactored the index generation logic into a new private method _build_indices(self, epoch: int).
    • Modified the random number generator's seed to include the epoch number (self.seed + epoch) within _build_indices to ensure different permutations each epoch.
    • Introduced a set_epoch(self, epoch: int) method that calls _build_indices if reshuffle_each_epoch is enabled.
    • Updated LatentsParquetMapStyleDataset and build_parquet_map_style_dataloader to accept and pass the new reshuffle_each_epoch argument to the underlying dataset.
    • Corrected the handling of dataset_size when drop_first_row is true by using a local variable dataset_size to avoid permanently altering self.dataset_size.
  • fastvideo/fastvideo_args.py
    • Added reshuffle_each_epoch: bool = True to the TrainingArgs class.
    • Included a new command-line argument --reshuffle-each-epoch with StoreBoolean action to control this feature.
Activity
  • The pull request was opened by mignonjia to fix an issue where the dataset was not shuffled across epochs, leading to a static access order.
  • The proposed solution is to add shuffling at the beginning of each epoch to improve data randomness.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a feature to reshuffle the dataset at each epoch, which is important for improving model training. The changes correctly modify DP_SP_BatchSampler to use an epoch-dependent seed for shuffling and introduce a set_epoch method to trigger this. The configuration is also updated via TrainingArgs to control this behavior. The implementation is clean and also improves the existing code by avoiding in-place modification of self.dataset_size.

My main feedback is that for this feature to be effective, the set_epoch method on the dataloader's sampler must be called at the beginning of each epoch. I've added a specific comment with a suggestion to add a docstring to the set_epoch method to make its usage clear and to highlight that the call is currently missing in the training loop.

@mignonjia mignonjia marked this pull request as ready for review February 8, 2026 23:54
@mignonjia mignonjia marked this pull request as draft February 9, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant