Skip to content

[loss refactor] [1] add snapshot test on loss functions#752

Open
yueming-yuan wants to merge 7 commits intomainfrom
loss_refactor/test
Open

[loss refactor] [1] add snapshot test on loss functions#752
yueming-yuan wants to merge 7 commits intomainfrom
loss_refactor/test

Conversation

@yueming-yuan
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 of loss function development by introducing a new snapshot testing framework. It also integrates a novel REINFORCE-based loss function designed for asynchronous reinforcement learning, accompanied by an example script to showcase its application.

Highlights

  • New Loss Function: Introduced reinforce_icepop_loss.py, implementing REINFORCE with double-sided importance sampling masking for asynchronous reinforcement learning.
  • Snapshot Testing Framework: Implemented a comprehensive snapshot testing utility (loss_test_utils.py) and a pytest-based test suite (test_loss_snapshot.py) to ensure bitwise identical outputs for loss functions across various configurations.
  • Example Script: Added run_glm47_flash_async_icepop.py to demonstrate the usage of the new reinforce_icepop_loss in an asynchronous GLM-4.7-Flash training setup.
  • Documentation: Provided a README.md for the loss snapshot tests, detailing quick start instructions and how to add new test configurations.
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.

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 new REINFORCE + double-sided IS masking loss function (reinforce_icepop_loss.py) and integrates it into an example script (run_glm47_flash_async_icepop.py). It also adds comprehensive snapshot tests for various loss functions, ensuring their outputs remain consistent across changes. The new loss function implementation appears correct and follows standard practices for gradient handling and metric reporting. The snapshot testing framework is well-designed for reproducibility and thoroughness. However, there are several hardcoded configuration values in the example script that could be made more flexible, and a dependency installation uses a specific commit hash which can be fragile.

Comment on lines +29 to +31
U.exec_command(
"pip install git+https://github.com/huggingface/transformers.git@76732b4e7120808ff989edbd16401f61fa6a0afa"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The pip install command uses a specific commit hash for huggingface/transformers. Relying on a specific commit hash can be fragile, as the commit might be force-pushed or the repository structure could change, leading to build failures. It's generally better to pin to a stable version tag or a well-maintained branch if possible, or include this as a dependency in a requirements.txt file with a version range.

If a specific version is absolutely necessary, consider adding a comment explaining why this particular commit is used.

Comment on lines +17 to +23
num_gpus_per_node: int = 8
hardware: Literal["H200"] = "H200"
enable_eval: bool = True
extra_args: str = ""
data_dir: str = "/root/datasets"
model_dir: str = "/root/models"
megatron_path: str = "/root/Megatron-LM"
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 num_gpus_per_node, hardware, data_dir, model_dir, and megatron_path are hardcoded in the ScriptArgs dataclass. Hardcoding these values makes the script less portable across different environments or setups. It would be more robust to allow these to be configurable via environment variables or command-line arguments, especially the paths.

For example, data_dir and model_dir could default to environment variables like os.getenv("MILES_DATA_DIR", "/root/datasets").

)

# tp=4 because GLM-4.7-Flash has 20 attention heads (tp must divide num_heads)
sglang_args = (
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 --rollout-num-gpus-per-engine 4 argument is hardcoded, with a comment indicating it's derived from the model's attention heads (tp must divide num_heads). To adhere to the general rule of avoiding hardcoded model dimensions and deriving them from configuration, this value should ideally be calculated programmatically based on the num_heads of GLM-4.7-Flash rather than being a magic number.

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