Fix gradient checkpointing warning filter implementation#97
Merged
shimmyshimmer merged 1 commit intoMar 25, 2025
Conversation
Contributor
Author
|
This is a bug , resulting in a runtime error and actually preventing most users from even loading models using FastLanguageModel.from_pretrained. Example: results in the runtime error: and prevents most people from progressing forward. Same thing happens with other models like Gemma3. SIde note: Oddly enough Transformers implementation of modeling_mistral3 isn't even importing the logging module at all to begin with.. This is not the reason for the runtime error though. The underlying code in compiler.py throwing the runtime error isn't even trivial. It is just trying to suppress a category of logs by filtering it out to un-clutter the console. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Logger Filter Implementation for Gradient Checkpointing Warnings
Description
This PR fixes a bug in the
unsloth_compile_transformersmethod incompiler.pythat causes an AttributeError when trying to suppress gradient checkpointing warnings. The current implementation incorrectly assumes that the model file has aloggerattribute, but logger instances are typically module-level variables, not attributes.Changes
Replaced the problematic
exec()call that was looking formodeling_file.loggerImplemented a proper logging filter that gets the correct logger instance via the transformers logging system
Ensures the filter works across different model architectures (Gemma, Mistral, etc.)
Bug Details
The current code attempts to suppress warnings with:
This fails with
Solution
The fix gets the appropriate logger directly from the transformers logging module and applies a filter to target only the specific gradient checkpointing warning message.
Testing
Verified the solution works with:
Gemma 3 models
Mistral 3 models
Related Issues
Fixes: