Repository navigation
Closed
Labels
Description
- Did you update?
pip install --upgrade unsloth unsloth_zoo- Yes ColaborKaggleor local / cloud - local- Number GPUs used, use
nvidia-smi- 1 - Which notebook? Please link! - Some code borrowed from Gemma 3n notebook (the training seems to work there):
https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_(4B)-Vision.ipynb - Which Unsloth version, TRL version, transformers version, PyTorch version?
unsloth 2025.11.4
unsloth_zoo 2025.11.5
trl 0.23.0
transformers 4.56.2
torch 2.9.0
torchao 0.14.1
bitsandbytes 0.48.2 - Which trainer?
SFTTrainer,GRPOTraineretc - UnslothTrainer
import unsloth
from unsloth import FastLanguageModel, FastModel
from unsloth import UnslothTrainer, UnslothTrainingArguments
import torch
import transformers, datasets
import os
from dataloader import Data #local module
os.environ["UNSLOTH_DISABLE_AUTO_UPDATES"] = "0"
os.environ["UNSLOTH_ENABLE_FULL_FINETUNING"] = "0"
torch.set_default_dtype(torch.bfloat16)
torch.set_default_device("cuda:0")
torch._dynamo.config.recompile_limit = 64
#generator, loads paths to txt files
data = Data(dirlist = [
"/mnt/f/_DATASETS/_curated"
]
)
dataset = datasets.IterableDataset(data)
model, tokenizer = FastModel.from_pretrained(
model_name = "/mnt/f/_MODELS/[BF16]_gemma_3n_e4b_it_32k/",
dtype = None,
max_seq_length = 1024,
load_in_4bit = True,
full_finetuning = False
)
model = FastModel.get_peft_model(
model,
finetune_vision_layers = False,
finetune_language_layers = True,
finetune_attention_modules = True,
finetune_mlp_modules = True,
r = 8,
lora_alpha = 8,
lora_dropout = 0,
bias = "none",
random_state = 42,
use_gradient_checkpointing = True,
max_seq_length = 1024,
use_rslora = False
)
trainingArgs = UnslothTrainingArguments(
embedding_learning_rate = 0.0001,
learning_rate = 0.0002,
lr_scheduler_type = 'cosine',
warmup_ratio = 0.1,
dataloader_drop_last = True,
dataloader_pin_memory = False,
label_smoothing_factor = 0.05,
gradient_checkpointing = True,
per_device_train_batch_size = 1,
gradient_accumulation_steps = 1,
optim = "adamw_8bit",
weight_decay = 0.01,
output_dir = "outputs",
report_to = "none",
max_steps = len(data)
)
trainer = UnslothTrainer(
args = trainingArgs,
model = model,
tokenizer = tokenizer,
dataset_text_field = "text",
train_dataset = dataset,
eval_dataset = None,
max_seq_length = 1024,
dataset_num_proc = 0,
)
trainer_stats = trainer.train()Output:
🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!
==((====))== Unsloth 2025.11.4: Fast Gemma3N patching. Transformers: 4.56.2.
\\ /| NVIDIA GeForce RTX 4090. Num GPUs = 1. Max memory: 23.988 GB. Platform: Linux.
O^O/ \_/ \ Torch: 2.9.0+cu128. CUDA: 8.9. CUDA Toolkit: 12.8. Triton: 3.5.0
\ / Bfloat16 = TRUE. FA [Xformers = 0.0.33.post1. FA2 = True]
"-____-" Free license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████| 4/4 [01:24<00:00, 21.03s/it]
Unsloth: Making `model.base_model.model.model.language_model` require gradients
[2025-11-28 11:47:57,817] [INFO] [real_accelerator.py:219:get_accelerator] Setting ds_accelerator to cuda (auto detect)
==((====))== Unsloth - 2x faster free finetuning | Num GPUs used = 1
\\ /| Num examples = 44 | Num Epochs = 9,223,372,036,854,775,807 | Total steps = 44
O^O/ \_/ \ Batch size per device = 1 | Gradient accumulation steps = 1
\ / Data Parallel GPUs = 1 | Total batch size (1 x 1 x 1) = 1
"-____-" Trainable parameters = 19,210,240 of 7,869,188,432 (0.24% trained)
0%| | 0/44 [00:00<?, ?it/s]Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/bitsandbytes/nn/modules.py", line 355, in __torch_function__
@classmethod
File "/usr/local/lib/python3.10/dist-packages/bitsandbytes/nn/modules.py", line 355, in __torch_function__
@classmethod
File "/usr/local/lib/python3.10/dist-packages/bitsandbytes/nn/modules.py", line 355, in __torch_function__
@classmethod
[Previous line repeated 990 more times]
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/eval_frame.py", line 1044, in _fn
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/aot_autograd.py", line 1130, in forward
return compiled_fn(full_args)
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 353, in runtime_wrapper
all_outs = call_func_at_runtime_with_args(
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/utils.py", line 129, in call_func_at_runtime_with_args
out = normalize_as_list(f(args))
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 724, in inner_fn
outs = compiled_fn(args)
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 526, in wrapper
return compiled_fn(runtime_args)
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/utils.py", line 103, in g
return f(*args)
RecursionError: maximum recursion depth exceeded
Removing torch defaults from the beginning:
Traceback (most recent call last):
File "/mnt/f/apps/_llm2/workspace/test.py", line 76, in <module>
trainer_stats = trainer.train()
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/UnslothSFTTrainer.py", line 55, in wrapper
output = f(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/trainer.py", line 2328, in train
return inner_training_loop(
File "<string>", line 323, in _fast_inner_training_loop
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/UnslothSFTTrainer.py", line 1097, in training_step
return super().training_step(*args, **kwargs)
File "<string>", line 40, in _unsloth_training_step
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/UnslothSFTTrainer.py", line 1086, in compute_loss
outputs = super().compute_loss(
File "/usr/local/lib/python3.10/dist-packages/unsloth/models/_utils.py", line 1626, in _unsloth_pre_compute_loss
outputs = self._old_compute_loss(model, inputs, *args, **kwargs)
File "<string>", line 36, in compute_loss
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/operations.py", line 814, in forward
return model_forward(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/accelerate/utils/operations.py", line 802, in __call__
return convert_to_fp32(self.model_forward(*args, **kwargs))
File "/usr/local/lib/python3.10/dist-packages/torch/amp/autocast_mode.py", line 44, in decorate_autocast
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/peft/peft_model.py", line 1845, in forward
return self.base_model(
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/peft/tuners/tuners_utils.py", line 216, in forward
return self.model.forward(*args, **kwargs)
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/unsloth_compiled_module_gemma3n.py", line 1928, in forward
return Gemma3nForConditionalGeneration_forward(self, input_ids, pixel_values, input_features, attention_mask, input_features_mask, position_ids, past_key_values, token_type_ids, cache_position, inputs_embeds, labels, use_cache,
output_attentions, output_hidden_states, logits_to_keep, **lm_kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/external_utils.py", line 196, in nonrecursive_disable_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/utils/generic.py", line 940, in wrapper
output = func(self, *args, **kwargs)
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/unsloth_compiled_module_gemma3n.py", line 1745, in Gemma3nForConditionalGeneration_forward
outputs = self.model(
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/utils/generic.py", line 940, in wrapper
output = func(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/models/gemma3n/modeling_gemma3n.py", line 2127, in forward
outputs = self.language_model(
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/unsloth_compiled_module_gemma3n.py", line 1360, in forward
return Gemma3nTextModel_forward(self, input_ids, per_layer_inputs, attention_mask, position_ids, past_key_values, inputs_embeds, use_cache, output_attentions, output_hidden_states, cache_position, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/external_utils.py", line 196, in nonrecursive_disable_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/utils/generic.py", line 940, in wrapper
output = func(self, *args, **kwargs)
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/unsloth_compiled_module_gemma3n.py", line 1238, in Gemma3nTextModel_forward
layer_outputs = decoder_layer(
File "/usr/local/lib/python3.10/dist-packages/transformers/modeling_layers.py", line 93, in __call__
return self._gradient_checkpointing_func(partial(super().__call__, **kwargs), *args)
File "/usr/local/lib/python3.10/dist-packages/torch/_compile.py", line 53, in inner
return disable_fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/eval_frame.py", line 1044, in _fn
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/utils/checkpoint.py", line 496, in checkpoint
return CheckpointFunction.apply(function, preserve, *args)
File "/usr/local/lib/python3.10/dist-packages/torch/autograd/function.py", line 581, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
File "/usr/local/lib/python3.10/dist-packages/unsloth_zoo/gradient_checkpointing.py", line 484, in forward
outputs = run_function(*args)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1786, in _call_impl
return forward_call(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/utils/deprecation.py", line 172, in wrapped_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/models/gemma3n/modeling_gemma3n.py", line 1426, in forward
predictions = self.altup.predict(hidden_states)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/eval_frame.py", line 832, in compile_wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1874, in __call__
result = self._torchdynamo_orig_backend(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 688, in __call__
result = _compile(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1433, in _compile
guarded_code, tracer_output = compile_inner(code, one_graph, hooks)
File "/usr/local/lib/python3.10/dist-packages/torch/_utils_internal.py", line 92, in wrapper_function
return function(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1117, in compile_inner
return _compile_inner(code, one_graph, hooks)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1151, in _compile_inner
dynamo_output = compile_frame(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1032, in compile_frame
bytecode, tracer_output = transform_code_object(code, transform)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/bytecode_transformation.py", line 1592, in transform_code_object
tracer_output = transformations(instructions, code_options)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 1004, in transform
tracer_output = trace_frame(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 312, in _fn
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 815, in trace_frame
run_tracer()
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 797, in run_tracer
tracer.run()
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 1487, in run
while self.step():
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 1348, in step
self.dispatch_table[inst.opcode](self, inst)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 904, in wrapper
return inner_fn(self, inst)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 2320, in CALL_FUNCTION
self.call_function(fn, args, {})
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 1266, in call_function
self.push(fn.call_function(self, args, kwargs)) # type: ignore[arg-type]
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/misc.py", line 1115, in call_function
return self.obj.call_method(tx, self.name, args, kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/tensor.py", line 713, in call_method
return wrap_fx_proxy(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/builder.py", line 2645, in wrap_fx_proxy
return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/builder.py", line 2711, in wrap_fx_proxy_cls return _wrap_fx_proxy(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/builder.py", line 2809, in _wrap_fx_proxy
example_value = get_fake_value(proxy.node, tx, allow_non_graph_fake=True)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/utils.py", line 3478, in get_fake_value
raise TorchRuntimeError(str(e)).with_traceback(e.__traceback__) from None
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/utils.py", line 3376, in get_fake_value
ret_val = wrap_fake_exception(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/utils.py", line 2864, in wrap_fake_exception
return fn()
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/utils.py", line 3377, in <lambda>
lambda: run_node(tx.output, node, args, kwargs, nnmodule)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/utils.py", line 3587, in run_node
raise RuntimeError(make_error_message(e)).with_traceback(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/utils.py", line 3557, in run_node
return getattr(args[0], node.target)(*args[1:], **kwargs) # type: ignore[arg-type]
File "/usr/local/lib/python3.10/dist-packages/torch/utils/_stats.py", line 28, in wrapper
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_subclasses/fake_tensor.py", line 1376, in __torch_dispatch__
return self.dispatch(func, types, args, kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_subclasses/fake_tensor.py", line 2096, in dispatch
return self._cached_dispatch_impl(func, types, args, kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_subclasses/fake_tensor.py", line 1481, in _cached_dispatch_impl
return self._dispatch_impl(func, types, args, kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_subclasses/fake_tensor.py", line 2755, in _dispatch_impl
r = func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_ops.py", line 841, in __call__
return self._op(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_refs/__init__.py", line 576, in _fn
return fn(a, *args, out=a, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_prims_common/wrappers.py", line 348, in _fn
_safe_copy_out(
File "/usr/local/lib/python3.10/dist-packages/torch/_prims_common/wrappers.py", line 224, in _safe_copy_out
torch._check(
File "/usr/local/lib/python3.10/dist-packages/torch/__init__.py", line 1695, in _check
_check_with(RuntimeError, cond, message)
File "/usr/local/lib/python3.10/dist-packages/torch/__init__.py", line 1677, in _check_with
raise error_type(message_evaluated)
torch._dynamo.exc.TorchRuntimeError: Dynamo failed to run FX node with fake tensors: call_method clamp_(*(FakeTensor(..., device='cuda:0', size=(32, 1), dtype=torch.uint8), -zf37, zf37), **{}): got RuntimeError("Attempting to cast from torch.float32 to out tensor with dtype torch.uint8, but this can't be cast because it is not safe!")
from user code:
File "/mnt/f/apps/_llm2/workspace/unsloth_compiled_cache/unsloth_compiled_module_gemma3n.py", line 819, in predict
self.prediction_coefs.weight.data.clamp_(-self.config.altup_coef_clip, self.config.altup_coef_clip)
Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"
Similar behavior with
unsloth-zoo 2025.9.14
unsloth 2025.9.11
pytorch 2.9.1+cu12.8
bitsandbytes 0.47.0
In addition, full finetunning seems to work with:
os.environ["UNSLOTH_ENABLE_FULL_FINETUNING"] = "1"
tokenizer = transformers.AutoTokenizer.from_pretrained("../models/test/tokenizer/")
config = transformers.Gemma3nTextConfig(dtype=torch.bfloat16, use_cache=False, attn_implementation='sdpa', vocab_size=512, vocab_size_per_layer_input=512)
model = transformers.Gemma3nForCausalLM(config)
model._saved_temp_tokenizer = tokenizer
{'loss': 6.6753, 'grad_norm': 36700160.0, 'learning_rate': 0.0, 'epoch': 0.02}But lora training results in
os.environ["UNSLOTH_ENABLE_FULL_FINETUNING"] = "0"
model = FastLanguageModel.get_peft_model(
model=model,
r=8,
lora_alpha=8,
use_gradient_checkpointing=True,
random_state=42,
max_seq_length=1024,
use_rslora=False,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj",
"embed_tokens", "lm_head",
"correction_coefs", "prediction_coefs", "modality_router",
"linear_left", "linear_right", "per_layer_input_gate", "per_layer_projection",
"embed_tokens_per_layer", "per_layer_model_projection"],
)
NotImplementedError: Unsloth: gemma3n_text is not yet implemented!
Activity
mmathew23 commentedon Dec 5, 2025
@Tacx79 Could you try using SFTtrainer for this?
But then the other thing I would try is using
trl==0.22.2Tacx79 commentedon Dec 6, 2025
@mmathew23 both downgrading trl or/and using SFTtrainer result in the same recursion error
mmathew23 commentedon Dec 6, 2025
@Tacx79 Does the issue reproduce if you use a the gemma3n model from huggingface.co?
unsloth/gemma-3n-E2B-itAnd if you use a dataset from https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3N_(4B)-Conversational.ipynb ?
The notebooks running fine which does both, so now I'm trying to figure out if it's an environment issue, a dataset issue, or a loading model issue.
Tacx79 commentedon Dec 6, 2025
@mmathew23 yes, loading
unsloth/gemma-3n-E2B-itfrom hub and from local dir gives the same result, same as using dataset from the notebook.I found that changing
load_in_4bitto False fixes it and the lora training worksmmathew23 commentedon Dec 6, 2025
https://colab.research.google.com/drive/1ESiYli-nalHvVP0dBfikrP6siRtOVc8k?usp=sharing
@Tacx79
This colab uses the notebooks dataset, and the model from the hub. It seems to work. So if you're more or less following this exactly then there is some sort of issue with one of the package deps in your local environment.
Alternatively if you can edit the notebook and show how to reproduce the error there, please share.
Tacx79 commentedon Dec 6, 2025
@mmathew23 in my setup forcing datatype (float16 / bfloat16 / float32) and device results in
RecursionErrorwhen I load the model in 4 bits, the same as in the notebook. But when I comment out this chunkThe code runs in the notebook, but fails on my local setup with the output below. I also noticed that unsloth quietly switches to float32 and converts model to float16 in the notebook but it stays on bfloat16 on my end, even when I try to force other datatypes, or don't specify them
I'm happy with using full precision as workaround since it doesn't overflow my memory, but I can help with diagnosing it further if necessary. (Any way to disable bfloat and fa2 in unsloth?)
mmathew23 commentedon Dec 7, 2025
@Tacx79 Could you try setting up a new venv so flash attention is disabled? It should work without setting default dtypes and devices.
If linux based
Then
pip install unslothand rerun the script.Tacx79 commentedon Dec 8, 2025
@mmathew23 same behavior
mmathew23 commentedon Dec 8, 2025
@Tacx79 Thanks, if you could paste test.py wrapped in three backticks here I'll try to reproduce on my side.
Tacx79 commentedon Dec 8, 2025
@mmathew23 it's the same code from above
mmathew23 commentedon Dec 8, 2025
@Tacx79 Wait in this script what happens if you use
unsloth/gemma-3n-E2B-itinstead of from the mnt directory?Does it work? If so, then what happens if you first load from
unsloth/gemma-3n-E2B-itthen save it locally as/path/gemma-3n-E2B-itwithThen could you try the script again with the new model path?
Tacx79 commentedon Dec 8, 2025
@mmathew23 I deleted huggingface cache and tried
Then I tried again with the saved model
I also checked saving the model without training and merging
Then I tried inference only on the trained model, loaded in 4 bit again
and got the same error
but
I checked huggingface cache and noticed that
unsloth/gemma-3n-E2B-it | load_in_4bitdownloadsunsloth/gemma-3n-E2B-it-unsloth-bnb-4bit, then to save it with adapter it downloads actualunsloth/gemma-3n-E2B-it, could it be that load_in_4bit expects the model to be in 4 bit already?danielhanchen commentedon Sep 9, 2026
Fixed! bitsandbytes' Params4bit torch_function was recursing into itself under AOT autograd, we strip it at import now.
Please update Unsloth:
uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir(if it's not in the current release yet it'll be in the next one). Reopen if it still happens!