Skip to content

don't create a reference model if grpo beta is 0.0#2983

Merged
winglian merged 1 commit into
mainfrom
grpo-beta-zero-no-ref-model
Jul 27, 2025
Merged

don't create a reference model if grpo beta is 0.0#2983
winglian merged 1 commit into
mainfrom
grpo-beta-zero-no-ref-model

Conversation

@winglian

@winglian winglian commented Jul 27, 2025

Copy link
Copy Markdown
Collaborator

Description

see https://github.com/huggingface/trl/blob/23ea671c5e7c83031c617171741ceabbf3fe18cc/trl/trainer/grpo_trainer.py#L726-L728

We can save memory here if not doing kl-divergence

Motivation and Context

How has this been tested?

Screenshots (if appropriate)

Types of changes

Social Handles (Optional)

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of reference model loading during reinforcement learning training, ensuring the reference model is not loaded when using GRPO RL type with a beta value of zero.

@coderabbitai

coderabbitai Bot commented Jul 27, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The update refines the logic within the setup_reference_model function in src/axolotl/train.py. It introduces a conditional check to determine whether to load a reference model based on the RL type and the trl.beta parameter, specifically skipping the reference model when using GRPO with trl.beta set to zero.

Changes

File(s) Change Summary
src/axolotl/train.py Adjusted setup_reference_model to conditionally load the reference model based on RL type and parameters.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7ea140 and 7347550.

📒 Files selected for processing (1)
  • src/axolotl/train.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: NanoCode012
PR: axolotl-ai-cloud/axolotl#2952
File: src/axolotl/common/datasets.py:125-125
Timestamp: 2025-07-22T08:27:00.129Z
Learning: GRPO (cfg.rl == "grpo" or cfg.rl is RLType.GRPO) should be excluded from dataset label checking during preprocessing, while other RL methods should continue to have this functionality available.
src/axolotl/train.py (1)

Learnt from: NanoCode012
PR: #2952
File: src/axolotl/common/datasets.py:125-125
Timestamp: 2025-07-22T08:27:00.129Z
Learning: GRPO (cfg.rl == "grpo" or cfg.rl is RLType.GRPO) should be excluded from dataset label checking during preprocessing, while other RL methods should continue to have this functionality available.

🧬 Code Graph Analysis (1)
src/axolotl/train.py (2)
src/axolotl/utils/schemas/enums.py (1)
  • RLType (24-32)
src/axolotl/loaders/model.py (1)
  • ModelLoader (63-805)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.1)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.0)
  • GitHub Check: PyTest from Source Dist (3.11, 2.6.0)
  • GitHub Check: PyTest (3.11, 2.7.1)
  • GitHub Check: PyTest (3.11, 2.6.0)
  • GitHub Check: PyTest (3.11, 2.7.0)
  • GitHub Check: pre-commit
  • GitHub Check: pre-commit
🔇 Additional comments (2)
src/axolotl/train.py (2)

118-120: LGTM: Memory optimization correctly implemented.

The conditional logic properly implements the memory optimization by skipping reference model creation when GRPO is used with beta=0. This aligns with the TRL implementation pattern and the retrieved learning that GRPO requires special handling.


122-122: LGTM: Correct parameter usage for conditional reference model loading.

The ModelLoader is now properly instantiated with the conditionally determined reference_model parameter, enabling the memory optimization when GRPO beta is 0.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch grpo-beta-zero-no-ref-model

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov

codecov Bot commented Jul 27, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/axolotl/train.py 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@winglian winglian requested a review from NanoCode012 July 27, 2025 15:31
@winglian winglian merged commit 28804b8 into main Jul 27, 2025
15 checks passed
@winglian winglian deleted the grpo-beta-zero-no-ref-model branch July 27, 2025 21:04
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