-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Nightly #3720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Nightly #3720
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e53e185
Update _utils.py
danielhanchen 150eadf
Merge branch 'main' into nightly
danielhanchen 25a6250
Merge branch 'main' into nightly
danielhanchen 6b908cf
Merge branch 'main' into nightly
danielhanchen f754bd2
Merge branch 'main' into nightly
danielhanchen 30ade52
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 94bbcaa
Merge branch 'main' into nightly
danielhanchen 30b78c5
Merge branch 'main' into nightly
danielhanchen f357fc5
Merge branch 'main' into nightly
danielhanchen cde2d42
[FIX] [Transformers] VLM input embeds fix for gradients (#3715)
Datta0 a63a337
Merge branch 'main' into nightly
danielhanchen 2c22ce6
Update rope_embedding.py
danielhanchen 449430d
Merge branch 'main' into nightly
danielhanchen b5f1a77
Fixes
danielhanchen c94f595
Update _utils.py
danielhanchen 01319d3
Update import_fixes.py
danielhanchen 696a540
Update rl_replacements.py
danielhanchen ac54d6e
fix_openenv_no_vllm
danielhanchen 9a98139
Fix
danielhanchen 680f19f
Update __init__.py
danielhanchen fb763f3
Update __init__.py
danielhanchen f4f2a7f
Update __init__.py
danielhanchen e17b62f
Update import_fixes.py
danielhanchen f34eb0a
Update import_fixes.py
danielhanchen 04ad21c
Update import_fixes.py
danielhanchen 32b52a0
logger
danielhanchen 0c9288f
Update __init__.py
danielhanchen b5b57b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] efb5801
Update __init__.py
danielhanchen 12ccc47
Merge branch 'nightly' of https://github.com/unslothai/unsloth into n…
danielhanchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,8 @@ | |
| from packaging.version import Version as TrueVersion | ||
| import re | ||
| import logging | ||
|
|
||
| UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1" | ||
| # Cannot import logger here since it'll import transformers | ||
| # from unsloth_zoo.log import logger | ||
|
|
||
|
|
||
| def Version(version): | ||
|
|
@@ -70,9 +70,10 @@ def GetMessages(self, *args, **kwargs): | |
| def GetPrototype(self, *args, **kwargs): | ||
| return | ||
|
|
||
| from unsloth_zoo.log import logger | ||
|
|
||
| if not hasattr(google.protobuf.message_factory, "MessageFactory"): | ||
| if UNSLOTH_ENABLE_LOGGING: | ||
| print("Unsloth: Patching protobuf.MessageFactory as it doesn't exist") | ||
| logger.info("Unsloth: Patching protobuf.MessageFactory as it doesn't exist") | ||
| google.protobuf.message_factory.MessageFactory = MessageFactory | ||
| elif ( | ||
| hasattr(google.protobuf.message_factory, "MessageFactory") | ||
|
|
@@ -82,8 +83,7 @@ def GetPrototype(self, *args, **kwargs): | |
| and not hasattr(google.protobuf.message_factory, "GetMessageClass") | ||
| ): | ||
| google.protobuf.message_factory.MessageFactory = MessageFactory | ||
| if UNSLOTH_ENABLE_LOGGING: | ||
| print("Unsloth: Patching protobuf.MessageFactory as it doesn't exist") | ||
| logger.info("Unsloth: Patching protobuf.MessageFactory as it doesn't exist") | ||
| elif ( | ||
| hasattr(google.protobuf.message_factory, "MessageFactory") | ||
| and not hasattr( | ||
|
|
@@ -97,8 +97,7 @@ def GetPrototype(self, descriptor): | |
| return GetMessageClass(descriptor) | ||
|
|
||
| google.protobuf.message_factory.MessageFactory.GetPrototype = GetPrototype | ||
| if UNSLOTH_ENABLE_LOGGING: | ||
| print("Unsloth: Patching protobuf.MessageFactory.GetPrototype") | ||
| logger.info("Unsloth: Patching protobuf.MessageFactory.GetPrototype") | ||
| pass | ||
| except: | ||
| pass | ||
|
|
@@ -110,6 +109,8 @@ def fix_xformers_performance_issue(): | |
| return | ||
| xformers_version = importlib_version("xformers") | ||
| if Version(xformers_version) < Version("0.0.29"): | ||
| from unsloth_zoo.log import logger | ||
|
|
||
| xformers_location = importlib.util.find_spec("xformers").origin | ||
| xformers_location = os.path.split(xformers_location)[0] | ||
| cutlass = Path(xformers_location) / "ops" / "fmha" / "cutlass.py" | ||
|
|
@@ -126,13 +127,11 @@ def fix_xformers_performance_issue(): | |
| f.seek(0) | ||
| f.write(text) | ||
| f.truncate() | ||
| if UNSLOTH_ENABLE_LOGGING: | ||
| print( | ||
| "Unsloth: Patching Xformers to fix some performance issues." | ||
| ) | ||
| logger.info( | ||
| "Unsloth: Patching Xformers to fix some performance issues." | ||
| ) | ||
| except Exception as e: | ||
| if UNSLOTH_ENABLE_LOGGING: | ||
| print(f"Unsloth: Failed patching Xformers with error = {str(e)}") | ||
| logger.info(f"Unsloth: Failed patching Xformers with error = {str(e)}") | ||
|
|
||
|
|
||
| # ValueError: 'aimv2' is already used by a Transformers config, pick another name. | ||
|
|
@@ -141,6 +140,8 @@ def fix_vllm_aimv2_issue(): | |
| return | ||
| vllm_version = importlib_version("vllm") | ||
| if Version(vllm_version) < Version("0.10.1"): | ||
| from unsloth_zoo.log import logger | ||
|
|
||
| vllm_version = importlib.util.find_spec("vllm").origin | ||
| vllm_version = os.path.split(vllm_version)[0] | ||
| ovis_config = Path(vllm_version) / "transformers_utils" / "configs" / "ovis.py" | ||
|
|
@@ -167,13 +168,11 @@ def fix_vllm_aimv2_issue(): | |
| f.seek(0) | ||
| f.write(text) | ||
| f.truncate() | ||
| if UNSLOTH_ENABLE_LOGGING: | ||
| print( | ||
| "Unsloth: Patching vLLM to fix `'aimv2' is already used by a Transformers config, pick another name.`" | ||
| ) | ||
| logger.info( | ||
| "Unsloth: Patching vLLM to fix `'aimv2' is already used by a Transformers config, pick another name.`" | ||
| ) | ||
| except Exception as e: | ||
| if UNSLOTH_ENABLE_LOGGING: | ||
| print(f"Unsloth: Failed patching vLLM with error = {str(e)}") | ||
| logger.info(f"Unsloth: Failed patching vLLM with error = {str(e)}") | ||
|
|
||
|
|
||
| def fix_vllm_guided_decoding_params(): | ||
|
|
@@ -274,8 +273,74 @@ def check_fbgemm_gpu_version(): | |
| raise ImportError( | ||
| f"Unsloth: fbgemm_gpu_genai=={fbgemm_gpu_version} detected. It might cause unexpected issues like segmentation faults. Please uninstall the current one by doing `pip uninstall fbgemm-gpu` && `pip install fbgemm-gpu` to install fbgemm-gpu 1.4.0 or newer!" | ||
| ) | ||
| elif UNSLOTH_ENABLE_LOGGING: | ||
| print(f"Unsloth: fbgemm_gpu_genai=={fbgemm_gpu_version} detected.") | ||
| from unsloth_zoo.log import logger | ||
|
|
||
| logger.info(f"Unsloth: fbgemm_gpu_genai=={fbgemm_gpu_version} detected.") | ||
|
|
||
|
|
||
| def patch_enable_input_require_grads(): | ||
| """ | ||
| Patch transformers PreTrainedModel.enable_input_require_grads to handle vision models | ||
| that raise NotImplementedError from get_input_embeddings(). | ||
|
|
||
| """ | ||
| import inspect | ||
| from transformers import PreTrainedModel | ||
|
|
||
| # Check if the original function iterates over self.modules() instead of just returning the enable_input_require_grads | ||
| # Ref: https://github.com/huggingface/transformers/pull/41993/files#diff-6b72b98c4c2dcfc6cc606843917733f5d858374fbc22a735ff483bbc0c1e63eaL1979-R1996 | ||
| try: | ||
| original_source = inspect.getsource(PreTrainedModel.enable_input_require_grads) | ||
| except: | ||
| return | ||
|
|
||
| # Only patch if the new pattern exists (iterating over self.modules()) | ||
| if "for module in self.modules()" not in original_source: | ||
| return | ||
|
|
||
| def _patched_enable_input_require_grads(self): | ||
| def make_inputs_require_grads(module, input, output): | ||
| output.requires_grad_(True) | ||
|
|
||
| hooks = [] | ||
| seen_modules = set() | ||
|
|
||
| for module in self.modules(): | ||
| if not ( | ||
| isinstance(module, PreTrainedModel) | ||
| and hasattr(module, "get_input_embeddings") | ||
| ): | ||
| continue | ||
|
|
||
| try: | ||
| input_embeddings = module.get_input_embeddings() | ||
| except NotImplementedError: | ||
| # Vision models may not implement get_input_embeddings - skip them | ||
| # For GLM V4.6 for example, this skips only `self.visual` | ||
| continue | ||
|
|
||
| if input_embeddings is None: | ||
| continue | ||
|
|
||
| embedding_id = id(input_embeddings) | ||
| if embedding_id in seen_modules: | ||
| continue | ||
|
|
||
| seen_modules.add(embedding_id) | ||
| hooks.append( | ||
| input_embeddings.register_forward_hook(make_inputs_require_grads) | ||
| ) | ||
|
|
||
| self._require_grads_hooks = hooks | ||
| if hooks: | ||
| self._require_grads_hook = hooks[0] | ||
|
|
||
| PreTrainedModel.enable_input_require_grads = _patched_enable_input_require_grads | ||
| from unsloth_zoo.log import logger | ||
|
|
||
| logger.info( | ||
| "Unsloth: Patched enable_input_require_grads for vision model compatibility" | ||
| ) | ||
|
|
||
|
|
||
| def torchvision_compatibility_check(): | ||
|
|
@@ -313,7 +378,49 @@ def torchvision_compatibility_check(): | |
| f"but found torchvision=={torchvision_version}. " | ||
| f"Please refer to https://pytorch.org/get-started/previous-versions/ for more information." | ||
| ) | ||
| elif UNSLOTH_ENABLE_LOGGING: | ||
| print( | ||
| f"Unsloth: torch=={torch_version} and torchvision=={torchvision_version} are compatible." | ||
| ) | ||
| from unsloth_zoo.log import logger | ||
|
|
||
| logger.info( | ||
| f"Unsloth: torch=={torch_version} and torchvision=={torchvision_version} are compatible." | ||
| ) | ||
|
|
||
|
|
||
| # Fix TRL OpenEnv 0.26 NameError: name 'SamplingParams' is not defined | ||
| def fix_openenv_no_vllm(): | ||
| if importlib.util.find_spec("trl") is None: | ||
| return | ||
| trl_location = importlib.util.find_spec("trl").origin | ||
| trl_location = os.path.split(trl_location)[0] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| openenv = Path(trl_location) / "experimental" / "openenv" / "utils.py" | ||
| if not openenv.exists(): | ||
| return | ||
| from unsloth_zoo.log import logger | ||
|
|
||
| try: | ||
| with open(openenv, "r+", encoding = "utf-8") as f: | ||
| text = f.read() | ||
| bad = ( | ||
| "if is_vllm_available():\n" | ||
| " from vllm import SamplingParams\n" | ||
| " from vllm.sampling_params import GuidedDecodingParams\n" | ||
| ) | ||
| if bad + "\n" + "\n" in text: | ||
| text = text.replace( | ||
| bad + "\n" + "\n", | ||
| bad | ||
| + ( | ||
| "else:\n" | ||
| " from typing import Any\n" | ||
| " SamplingParams = Any\n" | ||
| " GuidedDecodingParams = Any\n" | ||
| "\n" | ||
| ), | ||
| ) | ||
| f.seek(0) | ||
| f.write(text) | ||
| f.truncate() | ||
| logger.info( | ||
| "Unsloth: Patching TRL OpenEnv to fix SamplingParams not defined" | ||
| ) | ||
| except Exception as e: | ||
| logger.info(f"Unsloth: Failed patching TRL OpenEnv with error = {str(e)}") | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| __version__ = "2025.12.4" | ||
| __version__ = "2025.12.5" | ||
|
|
||
| __all__ = [ | ||
| "SUPPORTS_BFLOAT16", | ||
|
|
@@ -413,6 +413,16 @@ def filter(self, x): | |
| except: | ||
| pass | ||
|
|
||
| # Flax classes are deprecated and will be removed in Diffusers v1.0.0. | ||
| try: | ||
| from diffusers.utils import logger as diffusers_logger | ||
|
|
||
| diffusers_logger.addFilter(HideLoggingMessage("are deprecated")) | ||
| del diffusers_logger | ||
| except: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| pass | ||
|
|
||
|
|
||
| # Errors out on | ||
| # Some weights of Gemma3nForConditionalGeneration were not initialized from the model checkpoint | ||
| from transformers.modeling_utils import logger as transformers_logger | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a bare
except:is generally discouraged as it can catch unexpected exceptions likeSystemExitorKeyboardInterrupt, making it harder to debug and interrupt the program. It's better to catch specific exceptions, orExceptionat the very least.