Skip to content

Conversation

@Datta0
Copy link
Collaborator

@Datta0 Datta0 commented Dec 9, 2025

This change from trl happened to break our code. The PR aims to fix it

image

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Datta0, 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 focuses on enhancing the integration and compatibility between Unsloth and the TRL (Transformer Reinforcement Learning) library. It refines the process of loading LoRA models by improving the regex used for injecting lora_request into llm.chat and llm.generate calls, making it more resilient to code formatting. Additionally, it addresses specific interactions with TRL's reload_weights and wake_up mechanisms, removing redundant or conflicting calls to ensure Unsloth's optimized LoRA handling and memory management operate without interference, particularly within the openenv experimental module.

Highlights

  • Improved LoRA Loading Regex: The regular expression used to inject lora_request into self.llm.generate and self.llm.chat calls has been made more robust. It now correctly handles multi-line function calls and variations in whitespace or trailing commas, ensuring load_lora is applied consistently.
  • TRL reload_weights Removal: Unnecessary collective_rpc("reload_weights") calls from TRL's _generate_single_turn function and trl.experimental.openenv.utils.generate_rollout_completions have been removed. This prevents conflicts with Unsloth's internal weight management, which handles LoRA loading differently.
  • TRL openenv wake_up Fix: The wake_up call within TRL's openenv module has been adjusted from wake_up(tags=["kv_cache"]) to wake_up(). This ensures all necessary components are woken up, preventing double wake_up issues and ensuring compatibility with Unsloth's memory allocator.
  • New Patching Mechanism for openenv: A new mechanism, RL_ADDITIONAL_FUNCTIONS, has been introduced to allow for more modular and flexible patching of functions within TRL's openenv module, improving maintainability and extensibility of Unsloth's integrations.
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 improves the patching mechanism for TRL by updating a regular expression to handle multi-line llm.chat and llm.generate calls. It also introduces new patching capabilities for openenv and adds patches to remove reload_weights calls, which are not needed for Unsloth's LoRA use case.

My review found a critical issue in the construction of the replacement string for the llm.chat/generate patching, which could lead to syntax errors and runtime failures. The rest of the changes look good and are consistent with the project's patching style.

@danielhanchen danielhanchen merged commit d85e359 into unslothai:main Dec 9, 2025
1 check passed
djsaunde pushed a commit to djsaunde/unsloth that referenced this pull request Dec 10, 2025
* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove reload_weights rpc call from grpo trainer

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Use regex instead of static string

* patch openenv reload_weights call

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Better handle sleep and wakeup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Reset indentation

* Handle multi line self.llm.chat better

* Use logger

* re-indent

* Stricter regex to replace wildcard

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>
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