Skip to content

Makign qwen 2.5 7b compatible with old trl versions. #177

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
pluesclues:new_vlm_grpo_notebook_edits
Feb 5, 2026
Merged

Makign qwen 2.5 7b compatible with old trl versions. #177
danielhanchen merged 1 commit into
unslothai:mainfrom
pluesclues:new_vlm_grpo_notebook_edits

Conversation

@pluesclues

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @pluesclues, 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 enhances the Qwen2_5_7B_VL_GRPO notebook by adding backward compatibility for the trl library. It integrates version checks to conditionally apply chat templates and format prompts, ensuring that the notebook functions correctly regardless of whether an older (<0.24.0) or newer trl version is in use. This prevents potential breaking changes and improves the robustness of the notebook across different environments.

Highlights

  • TRL Version Compatibility: Introduced conditional logic to ensure the notebook is compatible with trl library versions older than 0.24.0.
  • Chat Template Application: Added a new code cell to explicitly apply the chat template to the training dataset's prompts if the trl version is below 0.24.0, as newer versions handle this automatically.
  • Dynamic Prompt Preparation: Modified the prompt preparation for model generation to dynamically apply the chat template based on the trl library version, ensuring correct formatting for both older and newer trl setups.

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

Changelog
  • nb/Qwen2_5_7B_VL_GRPO.ipynb
    • Added a new code cell that imports trl and packaging.version and conditionally applies tokenizer.apply_chat_template to the train_dataset's 'prompt' field if trl.__version__ is less than 0.24.0. This ensures prompts are correctly formatted for older trl versions.
    • Modified the prompt used for model.fast_generate by introducing a conditional assignment to example_prompt. If trl.__version__ is less than 0.24.0, the raw train_dataset prompt is used; otherwise, tokenizer.apply_chat_template is explicitly called on the prompt.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request yet.
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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 compatibility for older versions of the trl library by conditionally applying the chat template. The logic is sound and addresses the compatibility issue. I have one suggestion to improve maintainability by avoiding a duplicated version check. Additionally, there is a minor typo in the pull request title ('Makign').

Comment thread nb/Qwen2_5_7B_VL_GRPO.ipynb Outdated
" max_tokens = 1024,\n",
")\n",
"\n",
"if version.parse(trl.__version__) < version.parse(\"0.24.0\"):\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This version check is also performed in a previous cell (line 1091). To avoid code duplication and improve maintainability, it's a good practice to define a constant for this check once and reuse it. For example, you could define IS_OLD_TRL = version.parse(trl.__version__) < version.parse("0.24.0") in the cell at line 1091 and use if IS_OLD_TRL: in both places.

@danielhanchen

Copy link
Copy Markdown
Member

Thanks for this PR! The logic is correct. A few suggested improvements:

1. Use unsloth_zoo.utils.Version instead of packaging.version

This is cleaner and now supports passing package names directly:

# Before
import trl 
from packaging import version
if version.parse(trl.__version__) < version.parse("0.24.0"):

# After
from unsloth_zoo.utils import Version
if Version("trl") < Version("0.24.0"):

2. Missing version check in Cell 34 (second inference after training)

The second inference block after training is missing the version check. Currently it uses train_dataset[165]["prompt"] directly, which will fail for TRL >= 0.24.0 since the prompt is still in list format.

Should be:

if Version("trl") < Version("0.24.0"):
  example_prompt = train_dataset[165]["prompt"]
else:
  example_prompt = tokenizer.apply_chat_template(train_dataset[165]["prompt"], tokenize = False, add_generation_prompt = True)

outputs = model.fast_generate(
    {
        "prompt": example_prompt,
        "multi_modal_data": {"image": train_dataset[165]["image"]}
    },
    sampling_params,
    lora_request = model.load_lora("grpo_lora"))

Let me know if you want me to push these changes directly.

For TRL >= 0.24.0, the library handles apply_chat_template internally.
This adds version checks to prevent double-application of chat template.

Changes:
- Wrap train_dataset.map() with Version("trl") < Version("0.24.0") check
- Add isinstance(prompt, list) check for vLLM inference prompts
- Ensures compatibility with both old and new TRL versions

Affected notebooks:
- Qwen2_5_7B_VL_GRPO.ipynb (+ HuggingFace/Kaggle variants)
- Gemma3_(4B)-Vision-GRPO.ipynb (+ HuggingFace/Kaggle variants)
@danielhanchen danielhanchen force-pushed the new_vlm_grpo_notebook_edits branch from 68512f0 to f2c4611 Compare February 5, 2026 13:50
@danielhanchen danielhanchen merged commit c2dd975 into unslothai:main Feb 5, 2026
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