Skip to content

bump trl to 0.29#8404

Open
hjh0119 wants to merge 1 commit intomodelscope:mainfrom
hjh0119:trl0.29
Open

bump trl to 0.29#8404
hjh0119 wants to merge 1 commit intomodelscope:mainfrom
hjh0119:trl0.29

Conversation

@hjh0119
Copy link
Collaborator

@hjh0119 hjh0119 commented Mar 23, 2026

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 primarily focuses on upgrading the trl library dependency to version 0.29. This upgrade necessitated a series of refactorings and compatibility adjustments within the DPO trainer and related components to ensure seamless integration and continued functionality with the newer trl version, while also preserving backward compatibility for certain configuration arguments.

Highlights

  • TRL Library Version Bump: The trl library dependency has been updated across documentation, installation guides, and the requirements/framework.txt file to allow versions up to <0.30, specifically accommodating trl 0.29.
  • DPO Trainer Compatibility Refactoring: Significant internal changes were made to swift/rlhf_trainers/dpo_trainer.py to maintain compatibility with the breaking changes introduced in trl 0.29. This involved reimplementing core DPO loss calculation logic, reference log probability computation, and other trainer methods.
  • Backward Compatibility for DPO Configuration: The DPOConfig in swift/rlhf_trainers/arguments.py was extended to include fields like rpo_alpha, ref_adapter_name, and reference_free, which were removed in trl 0.29, ensuring backward compatibility for existing configurations.
  • Activation Offloading Simplification: The explicit handling of activation_offloading context managers was removed from gkd_trainer.py and reward_trainer.py, and a default nullcontext was introduced in rlhf_mixin.py, streamlining the activation offloading mechanism in response to trl updates.

🧠 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.

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 updates the trl dependency to support version 0.29, which introduced several breaking changes. The changes correctly update documentation and the requirements file. The code is adapted for compatibility by re-implementing several methods from trl.DPOTrainer and handling removed arguments. This is a significant but necessary change to support the new trl version. I've found one potential issue in the re-implemented dpo_loss function that could lead to incorrect behavior.

Comment on lines +268 to +272
if self.label_smoothing == 0:
self.label_smoothing = 1e-3
losses = (self.beta * logits).sigmoid() * (F.logsigmoid(
self.beta * logits) - math.log(1 - self.label_smoothing)) + (-self.beta * logits).sigmoid() * (
F.logsigmoid(-self.beta * logits) - math.log(self.label_smoothing))
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Modifying the instance attribute self.label_smoothing within this function introduces a side effect. If this function is called multiple times with loss_type='exo_pair' and self.label_smoothing is initially 0, its value will be permanently changed to 1e-3. This could lead to incorrect behavior in subsequent loss calculations. It's better to use a local variable for this logic to avoid side effects.

Suggested change
if self.label_smoothing == 0:
self.label_smoothing = 1e-3
losses = (self.beta * logits).sigmoid() * (F.logsigmoid(
self.beta * logits) - math.log(1 - self.label_smoothing)) + (-self.beta * logits).sigmoid() * (
F.logsigmoid(-self.beta * logits) - math.log(self.label_smoothing))
label_smoothing = self.label_smoothing
if label_smoothing == 0:
label_smoothing = 1e-3
losses = (self.beta * logits).sigmoid() * (F.logsigmoid(
self.beta * logits) - math.log(1 - label_smoothing)) + (-self.beta * logits).sigmoid() * (
F.logsigmoid(-self.beta * logits) - math.log(label_smoothing))

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.

2 participants