Skip to content

Conversation

@guapisolo
Copy link
Collaborator

@guapisolo guapisolo commented Jan 24, 2026

Some people have concern about miles's data packing logic will reduce accuracy. So add this CI.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @guapisolo, 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 introduces a comprehensive test suite to verify the integrity of the data packing mechanism. It specifically addresses concerns regarding potential accuracy degradation by comparing loss computations using both packed and traditionally padded data. The new tests cover various scenarios, including distributed training setups with context parallelism, thereby bolstering confidence in the data processing pipeline's reliability.

Highlights

  • New Test File for Data Packing Accuracy: A new test file, test_packed_vs_padded_loss.py, has been added to validate the accuracy of the data packing logic.
  • Loss Calculation Equivalence: The tests specifically compare loss calculations between packed and traditionally padded data to ensure numerical consistency and prevent accuracy reduction.
  • Context Parallelism Testing: Test cases are included to verify the data packing logic's correctness even when context parallelism is enabled, using mocked Megatron-LM utilities.
  • Ruff Configuration Update: The pyproject.toml file was updated to include a new [tool.ruff.lint] section, likely for configuring linting rules.
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 valuable test suite to verify the correctness of data packing logic by comparing its loss calculations against a standard padded data approach. The tests are well-designed, covering various scenarios including different tensor parallelism sizes and context parallelism, which significantly increases confidence in the data packing implementation. The update to pyproject.toml is also a good modernization of the configuration. I've identified a couple of minor areas for improvement within the new test code to enhance its robustness and clarity.

Comment on lines +55 to +56
if mask.sum() == 0:
mask[0] = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There's a potential IndexError here if response_len is 0. In that case, mask would be an empty tensor, mask.sum() would be 0, and mask[0] = 1 would raise an error. While the current test cases use positive response_len values, making this helper function more robust to handle a response_len of 0 would be good practice for future use.

Suggested change
if mask.sum() == 0:
mask[0] = 1
if response_len > 0 and mask.sum() == 0:
mask[0] = 1

Comment on lines +223 to +226
for cp_rank in range(cp_size):
monkeypatch.setattr(mpu, "get_context_parallel_world_size", lambda: cp_size)
monkeypatch.setattr(mpu, "get_context_parallel_rank", lambda cp_rank=cp_rank: cp_rank)
monkeypatch.setattr(mpu, "get_tensor_model_parallel_world_size", lambda: tp_size)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The monkeypatch.setattr calls for get_context_parallel_world_size and get_tensor_model_parallel_world_size are setting constant values within the loop. These can be moved outside the loop. This refactoring improves clarity by separating the setup that is constant across loop iterations from the setup that changes, and it avoids redundant calls.

Suggested change
for cp_rank in range(cp_size):
monkeypatch.setattr(mpu, "get_context_parallel_world_size", lambda: cp_size)
monkeypatch.setattr(mpu, "get_context_parallel_rank", lambda cp_rank=cp_rank: cp_rank)
monkeypatch.setattr(mpu, "get_tensor_model_parallel_world_size", lambda: tp_size)
monkeypatch.setattr(mpu, "get_context_parallel_world_size", lambda: cp_size)
monkeypatch.setattr(mpu, "get_tensor_model_parallel_world_size", lambda: tp_size)
for cp_rank in range(cp_size):
monkeypatch.setattr(mpu, "get_context_parallel_rank", lambda cp_rank=cp_rank: cp_rank)

@guapisolo guapisolo changed the title Add data packing test CI: Add data packing test Jan 24, 2026
@guapisolo guapisolo marked this pull request as draft January 24, 2026 03:31
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