Skip to content
Merged

Nightly #3737

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e53e185
Update _utils.py
danielhanchen Dec 9, 2025
150eadf
Merge branch 'main' into nightly
danielhanchen Dec 9, 2025
25a6250
Merge branch 'main' into nightly
danielhanchen Dec 9, 2025
6b908cf
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
f754bd2
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
30ade52
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 10, 2025
94bbcaa
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
30b78c5
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
f357fc5
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
cde2d42
[FIX] [Transformers] VLM input embeds fix for gradients (#3715)
Datta0 Dec 12, 2025
a63a337
Merge branch 'main' into nightly
danielhanchen Dec 12, 2025
2c22ce6
Update rope_embedding.py
danielhanchen Dec 12, 2025
449430d
Merge branch 'main' into nightly
danielhanchen Dec 12, 2025
b5f1a77
Fixes
danielhanchen Dec 12, 2025
c94f595
Update _utils.py
danielhanchen Dec 12, 2025
01319d3
Update import_fixes.py
danielhanchen Dec 12, 2025
696a540
Update rl_replacements.py
danielhanchen Dec 12, 2025
ac54d6e
fix_openenv_no_vllm
danielhanchen Dec 12, 2025
9a98139
Fix
danielhanchen Dec 12, 2025
680f19f
Update __init__.py
danielhanchen Dec 12, 2025
fb763f3
Update __init__.py
danielhanchen Dec 12, 2025
f4f2a7f
Update __init__.py
danielhanchen Dec 12, 2025
e17b62f
Update import_fixes.py
danielhanchen Dec 12, 2025
f34eb0a
Update import_fixes.py
danielhanchen Dec 12, 2025
04ad21c
Update import_fixes.py
danielhanchen Dec 12, 2025
32b52a0
logger
danielhanchen Dec 12, 2025
0c9288f
Update __init__.py
danielhanchen Dec 12, 2025
b5b57b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2025
efb5801
Update __init__.py
danielhanchen Dec 12, 2025
12ccc47
Merge branch 'nightly' of https://github.com/unslothai/unsloth into n…
danielhanchen Dec 12, 2025
e3918e7
Merge branch 'main' into nightly
danielhanchen Dec 12, 2025
0cb9542
Merge branch 'main' into nightly
danielhanchen Dec 17, 2025
5540212
Update import_fixes.py
danielhanchen Dec 17, 2025
4c80b03
Update __init__.py
danielhanchen Dec 17, 2025
e57edc2
Update import_fixes.py
danielhanchen Dec 17, 2025
9bc1567
Update import_fixes.py
danielhanchen Dec 17, 2025
c22fbb7
Update import_fixes.py
danielhanchen Dec 17, 2025
d7482e8
Update import_fixes.py
danielhanchen Dec 17, 2025
ca77798
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 17, 2025
71c5938
Update import_fixes.py
danielhanchen Dec 17, 2025
2991a7d
Merge branch 'nightly' of https://github.com/unslothai/unsloth into n…
danielhanchen Dec 17, 2025
7c10195
Update unsloth/import_fixes.py
danielhanchen Dec 17, 2025
7f744d9
Merge branch 'main' into nightly
danielhanchen Dec 17, 2025
d96ac97
Merge branch 'main' into nightly
danielhanchen Dec 17, 2025
3738db7
Update save.py
danielhanchen Dec 17, 2025
fbaacce
[fbgemm] Silence tma fbgemm (#3735)
Datta0 Dec 17, 2025
6e5a561
Merge branch 'nightly' of https://github.com/unslothai/unsloth into n…
danielhanchen Dec 17, 2025
3e6cfb5
Update loader.py
danielhanchen Dec 17, 2025
30a454c
Update save.py
danielhanchen Dec 17, 2025
b58663a
Update save.py
danielhanchen Dec 17, 2025
7b61375
Update _utils.py
danielhanchen Dec 17, 2025
a2b5def
Update _utils.py
danielhanchen Dec 17, 2025
59a1fa5
Diffusers warnings
danielhanchen Dec 17, 2025
5e33a07
Update pyproject.toml
danielhanchen Dec 17, 2025
1f1bf49
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ huggingfacenotorch = [
]
huggingface = [
"unsloth[huggingfacenotorch]",
"unsloth_zoo>=2025.12.4",
"unsloth_zoo>=2025.12.5",
"torchvision",
"unsloth[triton]",
]
Expand Down Expand Up @@ -523,7 +523,7 @@ colab-ampere-torch220 = [
"flash-attn>=2.6.3 ; ('linux' in sys_platform)",
]
colab-new = [
"unsloth_zoo>=2025.12.4",
"unsloth_zoo>=2025.12.5",
"packaging",
"tyro",
"transformers>=4.51.3,!=4.52.0,!=4.52.1,!=4.52.2,!=4.52.3,!=4.53.0,!=4.54.0,!=4.55.0,!=4.55.1,!=4.57.0,<=4.57.3",
Expand Down
3 changes: 3 additions & 0 deletions unsloth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
fix_message_factory_issue,
check_fbgemm_gpu_version,
torchvision_compatibility_check,
fix_diffusers_warnings,
)

fix_message_factory_issue()
check_fbgemm_gpu_version()
torchvision_compatibility_check()
fix_diffusers_warnings()
del fix_message_factory_issue
del check_fbgemm_gpu_version
del torchvision_compatibility_check
del fix_diffusers_warnings

# This check is critical because Unsloth optimizes these libraries by modifying
# their code at import time. If they're imported first, the original (slower,
Expand Down
35 changes: 35 additions & 0 deletions unsloth/import_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ def filter(self, x):
return not (self.text in x.getMessage())


class HidePrintMessage:
__slots__ = ("_original_stream", "_hidden_texts")

def __init__(self, original_stream):
self._original_stream = original_stream
self._hidden_texts = []

def add_filter(self, text):
self._hidden_texts.append(text)

def write(self, message):
if not any(text in message for text in self._hidden_texts):
self._original_stream.write(message)

def flush(self):
self._original_stream.flush()

def __getattr__(self, name):
return getattr(self._original_stream, name)


if os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") != "1":
import sys

# Apply to stderr for FBGEMM
sys.stderr = HidePrintMessage(sys.stderr)
# https://github.com/pytorch/FBGEMM/blob/d99cd96490ec4aabac2ee95b1e76ea4dcfcfa628/fbgemm_gpu/experimental/gemm/triton_gemm/utils.py#L43-L52
sys.stderr.add_filter("TMA benchmarks will be running")


# Fix up AttributeError: 'MessageFactory' object has no attribute 'GetPrototype'
# MUST do this at the start primarily due to tensorflow causing issues
def fix_message_factory_issue():
Expand Down Expand Up @@ -506,3 +536,8 @@ def get_mapped_key(key: str, mapping_dict: dict[str, str]) -> str:
logger.info("Unsloth: Patching Executorch to fix get_mapped_key")
except Exception as e:
logger.info(f"Unsloth: Failed Executorch with error = {str(e)}")


def fix_diffusers_warnings():
# Silence Flax classes are deprecated and will be removed in Diffusers v1.0.0.
os.environ["DIFFUSERS_VERBOSITY"] = "error"
12 changes: 1 addition & 11 deletions unsloth/models/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "2025.12.5"
__version__ = "2025.12.6"

__all__ = [
"SUPPORTS_BFLOAT16",
Expand Down Expand Up @@ -413,16 +413,6 @@ 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:
pass


# Errors out on
# Some weights of Gemma3nForConditionalGeneration were not initialized from the model checkpoint
from transformers.modeling_utils import logger as transformers_logger
Expand Down
2 changes: 2 additions & 0 deletions unsloth/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ def from_pretrained(
"compatible with `full_finetuning=True`. If you wish to use QAT with LoRA, "
"please pass in `qat_scheme` in `FastLanguageModel.get_peft_model(...)` instead."
)
if qat_scheme == "phone-deployment":
qat_scheme = "int8-int4"
# Check if 4bit is allowed specifically for AMD
if not ALLOW_BITSANDBYTES and not use_exact_model_name:
if load_in_4bit or load_in_8bit or model_name.lower().endswith("-bnb-4bit"):
Expand Down
24 changes: 21 additions & 3 deletions unsloth/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,17 @@ def _unsloth_save_torchao_with_attached_config(
"""Save a QAT-trained model by converting fake-quantized weights to real quantized weights."""
# Convert QAT fake-quantized weights to real quantized weights
_convert_torchao_model(model)
# PEFT models also might come here, so parse it
if isinstance(model, PeftModelForCausalLM):
_unsloth_save_torchao_with_given_config(
model = model,
save_directory = save_directory,
tokenizer = tokenizer,
torchao_config = model.config.quantization_config,
push_to_hub = push_to_hub,
token = token,
)
return

# TorchAO does not support safe_serialization reliably
safe_serialization = False
Expand Down Expand Up @@ -2806,7 +2817,10 @@ def _unsloth_save_torchao_with_given_config(
)
from torchao import quantize_

quantization_config = TorchAoConfig(quant_type = torchao_config)
if isinstance(torchao_config, TorchAoConfig):
quantization_config = torchao_config
else:
quantization_config = TorchAoConfig(quant_type = torchao_config)

# Determine if this is a VLM
is_vlm = False
Expand Down Expand Up @@ -2897,7 +2911,7 @@ def unsloth_save_pretrained_torchao(
)

if torchao_config is not None:
# PTQ path: user provided a config, model must NOT have QAT config
# PTQ path: user provided a config, model must NOT have QAT config unless PEFT
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

The comment unless PEFT seems to contradict the assert statement that follows. The assertion assert not has_qat_config will fail for any model with a QAT config, including PEFT models, if torchao_config is provided. This is consistent with the error message, which advises against passing torchao_config for QAT models.

To avoid confusion, consider updating the comment to align with the code's behavior by removing the 'unless PEFT' clause.

Suggested change
# PTQ path: user provided a config, model must NOT have QAT config unless PEFT
# PTQ path: user provided a config, model must NOT have QAT config

assert not has_qat_config, (
"Unsloth: You passed `torchao_config` but this model was trained with `qat_scheme`. "
"For QAT models, do not pass `torchao_config` - the quantization config is already "
Expand Down Expand Up @@ -3010,7 +3024,11 @@ def patch_saving_functions(model, vision = False):

original_model = model
while True:
if original_model.push_to_hub.__name__ != "unsloth_push_to_hub":
# Check if push_to_hub exists before accessing its __name__
if (
hasattr(original_model, "push_to_hub")
and original_model.push_to_hub.__name__ != "unsloth_push_to_hub"
):
original_model.original_push_to_hub = original_model.push_to_hub
original_model.push_to_hub = types.MethodType(
unsloth_push_to_hub, original_model
Expand Down