Skip to content

Silence non-actionable TRL trainer import failures#3980

Merged
danielhanchen merged 1 commit into
mainfrom
fix-trl-import-noise
Feb 5, 2026
Merged

Silence non-actionable TRL trainer import failures#3980
danielhanchen merged 1 commit into
mainfrom
fix-trl-import-noise

Conversation

@danielhanchen
Copy link
Copy Markdown
Member

Summary

  • _patch_trl_rl_trainers() in rl.py enumerates all trainer modules from dir(trl.trainer) and dynamically imports each one. Some modules like alignprop_trainer (in trl 0.22.2) fail because they depend on optional packages like diffusers that may not be installed.
  • The failure is caught and handled gracefully (return), but the print() call on line 423 produces noise on every from unsloth import FastLanguageModel:
    Unsloth: Could not import trl.trainer.alignprop_trainer: Failed to import
    trl.trainer.alignprop_trainer because of the following error: cannot import
    name 'DDPOStableDiffusionPipeline' from 'trl.models'
    
  • This message is not actionable by the user -- alignprop_trainer is not needed for LLM fine-tuning.

Changes

Change print() to logger.info() so these messages only appear when UNSLOTH_ENABLE_LOGGING=1. The logger import already exists (from unsloth_zoo.log import logger on line 26), and other similar messages in the same function already use logger.info() (lines 442, 447, 458, 465).

Test plan

  • Verify from unsloth import FastLanguageModel no longer prints alignprop noise with trl 0.22.2
  • Verify setting UNSLOTH_ENABLE_LOGGING=1 still shows the message for debugging

_patch_trl_rl_trainers enumerates all trainer modules from dir(trl.trainer)
and attempts to import each one. Modules like alignprop_trainer fail because
they depend on optional packages (diffusers) that may not be installed. The
failure is harmless but the print() call produces noise on every import.

Change print() to logger.info() so these messages only appear when
UNSLOTH_ENABLE_LOGGING=1.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @danielhanchen, 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 improves the user experience by reducing unnecessary console output. Previously, unsloth would print error messages when dynamically importing trl trainer modules that depend on optional packages not installed in the user's environment. The change redirects these messages to the logger.info() level, making them visible only when logging is enabled, thus decluttering the console for typical usage.

Highlights

  • Silence Non-Actionable TRL Trainer Import Failures: The print() statement that previously produced console noise for trl trainer modules failing to import due to missing optional dependencies has been replaced with logger.info(). This change ensures that these non-actionable messages are suppressed by default, appearing only when detailed logging is explicitly enabled.

🧠 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
  • unsloth/models/rl.py
    • Changed print(f"Unsloth: Could not import trl.trainer.{trainer_file}: {error}") to logger.info(f"Unsloth: Could not import trl.trainer.{trainer_file}: {error}") within the _patch_trl_rl_trainers function to use the logging system instead of direct console output for import failures.
Activity
  • No specific review comments or activities have 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.

Copy link
Copy Markdown
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 correctly addresses the issue of noisy, non-actionable error messages during TRL trainer imports by replacing a print() statement with logger.info(). This is a good improvement as it aligns with standard library logging practices, reducing console noise for users by default while preserving the ability to see these messages for debugging when logging is enabled. The change is consistent with other logging calls within the same function and is correctly implemented. I approve of this change.

@danielhanchen danielhanchen merged commit c6d6ff0 into main Feb 5, 2026
4 checks passed
@danielhanchen danielhanchen deleted the fix-trl-import-noise branch February 5, 2026 13:32
abiswas-realadvice pushed a commit to abiswas-realadvice/unsloth that referenced this pull request May 14, 2026
_patch_trl_rl_trainers enumerates all trainer modules from dir(trl.trainer)
and attempts to import each one. Modules like alignprop_trainer fail because
they depend on optional packages (diffusers) that may not be installed. The
failure is harmless but the print() call produces noise on every import.

Change print() to logger.info() so these messages only appear when
UNSLOTH_ENABLE_LOGGING=1.

Co-authored-by: Daniel Han <danielhanchen@users.noreply.github.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.

1 participant