Silence non-actionable TRL trainer import failures#3980
Conversation
_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.
Summary of ChangesHello @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, Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
_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>
Summary
_patch_trl_rl_trainers()inrl.pyenumerates all trainer modules fromdir(trl.trainer)and dynamically imports each one. Some modules likealignprop_trainer(in trl 0.22.2) fail because they depend on optional packages likediffusersthat may not be installed.return), but theprint()call on line 423 produces noise on everyfrom unsloth import FastLanguageModel:alignprop_traineris not needed for LLM fine-tuning.Changes
Change
print()tologger.info()so these messages only appear whenUNSLOTH_ENABLE_LOGGING=1. Theloggerimport already exists (from unsloth_zoo.log import loggeron line 26), and other similar messages in the same function already uselogger.info()(lines 442, 447, 458, 465).Test plan
from unsloth import FastLanguageModelno longer prints alignprop noise with trl 0.22.2UNSLOTH_ENABLE_LOGGING=1still shows the message for debugging