Skip to content

[Bug] Fine-tuning unsloth/Qwen3-4B-Instruct-2507fails when loading with 8bit #3501

Closed

Description

@mapa17

Running a notebook in the official docker imgage with the sample code (based on the unsloth notebook Qwen3_(4B)-Instruct) below will fail on my system.

==((====))==  Unsloth 2025.9.11: Fast Qwen3 patching. Transformers: 4.56.2. vLLM: 0.10.2.
   \\   /|    NVIDIA GeForce RTX 3060. Num GPUs = 1. Max memory: 11.631 GB. Platform: Linux.
O^O/ \_/ \    Torch: 2.8.0+cu128. CUDA: 8.6. CUDA Toolkit: 12.8. Triton: 3.4.0
\        /    Bfloat16 = TRUE. FA [Xformers = 0.0.33+5146f2a.d20251002. FA2 = True]
 "-____-"     Free license: http://github.com/unslothai/unsloth
from unsloth import FastLanguageModel
from datasets import Dataset, load_dataset
from unsloth.chat_templates import get_chat_template
from unsloth.chat_templates import standardize_data_formats

import torch

fourbit_models = [
    "unsloth/Qwen3-4B-Instruct-2507-unsloth-bnb-4bit", # Qwen 14B 2x faster
    "unsloth/Qwen3-4B-Thinking-2507-unsloth-bnb-4bit",
    "unsloth/Qwen3-8B-unsloth-bnb-4bit",
    "unsloth/Qwen3-14B-unsloth-bnb-4bit",
    "unsloth/Qwen3-32B-unsloth-bnb-4bit",

    # 4bit dynamic quants for superior accuracy and low memory use
    "unsloth/gemma-3-12b-it-unsloth-bnb-4bit",
    "unsloth/Phi-4",
    "unsloth/Llama-3.1-8B",
    "unsloth/Llama-3.2-3B",
    "unsloth/orpheus-3b-0.1-ft-unsloth-bnb-4bit" # [NEW] We support TTS models!
] # More models at https://huggingface.co/unsloth

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/Qwen3-4B-Instruct-2507",
    max_seq_length = 4096, # Choose any for long context!
    load_in_4bit = False,  # 4 bit quantization to reduce memory
    load_in_8bit = True, # [NEW!] A bit more accurate, uses 2x memory
    load_in_16bit = False,
    full_finetuning = False, # [NEW!] We have full finetuning now!
    # token = "hf_...", # use one if using gated models
    cache_dir="./hf_cache"
)

model = FastLanguageModel.get_peft_model(
    model,
    r = 32, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj",],
    lora_alpha = 32,
    lora_dropout = 0, # Supports any, but = 0 is optimized
    bias = "none",    # Supports any, but = "none" is optimized
    # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
    use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
    random_state = 3407,
    use_rslora = False,  # We support rank stabilized LoRA
    loftq_config = None, # And LoftQ
)


tokenizer = get_chat_template(
    tokenizer,
    chat_template = "qwen3-instruct",
)

dataset = load_dataset("mlabonne/FineTome-100k", split = "train")


dataset = standardize_data_formats(dataset)

def formatting_prompts_func(examples):
   convos = examples["conversations"]
   texts = [tokenizer.apply_chat_template(convo, tokenize = False, add_generation_prompt = False) for convo in convos]
   return { "text" : texts, }

dataset = dataset.map(formatting_prompts_func, batched = True)
split_dataset = dataset.train_test_split(test_size = 0.01, shuffle = True, seed = 3407)

print(f"{split_dataset=}")

from trl import SFTTrainer, SFTConfig
trainer = SFTTrainer(
    model = model,
    tokenizer = tokenizer,
    train_dataset = split_dataset['train'],
    eval_dataset = split_dataset['test'], # Can set up evaluation!
    args = SFTConfig(
        dataset_text_field = "text",
        per_device_train_batch_size = 2,
        gradient_accumulation_steps = 8, # Use GA to mimic batch size!
        warmup_steps = 5,
        num_train_epochs = 1, # Set this for 1 full training run.
        #max_steps = 60,
        learning_rate = 2e-5, # Reduce to 2e-5 for long training runs
        logging_steps = 1,
        optim = "adamw_8bit",
        weight_decay = 0.01,
        lr_scheduler_type = "linear",
        seed = 3407,
        report_to = "none", # Use this for WandB etc
        fp16_full_eval = True,
        per_device_eval_batch_size = 2,
        eval_accumulation_steps = 8,
        eval_strategy = "steps",
        eval_steps = 20
    ),
)

trainer_stats = trainer.train()

Producing the error trace

The tokenizer has new PAD[/BOS/EOS](http://localhost:8888/BOS/EOS) tokens that differ from the model config and generation config. The model config and generation config were aligned accordingly, being updated with the tokenizer's values. Updated tokens: {'bos_token_id': None}.
==((====))==  Unsloth - 2x faster free finetuning | Num GPUs used = 1
   \\   [/](http://localhost:8888/)|    Num examples = 99,000 | Num Epochs = 1 | Total steps = 6,188
O^O[/](http://localhost:8888/) \_[/](http://localhost:8888/) \    Batch size per device = 2 | Gradient accumulation steps = 8
\        [/](http://localhost:8888/)    Data Parallel GPUs = 1 | Total batch size (2 x 8 x 1) = 16
 "-____-"     Trainable parameters = 66,060,288 of 4,088,528,384 (1.62% trained)
[/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:181](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=180): UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
[/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:181](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=180): UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
[/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:181](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=180): UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
[/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:181](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=180): UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
[/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:181](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=180): UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
[/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:181](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=180): UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
[/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:181](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=180): UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
  warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[4], line 29
      1 from trl import SFTTrainer, SFTConfig
      2 trainer = SFTTrainer(
      3     model = model,
      4     tokenizer = tokenizer,
   (...)     26     ),
     27 )
---> 29 trainer_stats = trainer.train()

File [/workspace/work/unsloth_compiled_cache/UnslothSFTTrainer.py:53](http://localhost:8888/lab/tree/work/work/unsloth_compiled_cache/UnslothSFTTrainer.py#line=52), in prepare_for_training_mode.<locals>.wrapper(self, *args, **kwargs)
     51 if hasattr(self, 'model') and hasattr(self.model, "for_training"):
     52     self.model.for_training()
---> 53 output = f(self, *args, **kwargs)
     54 # Return inference mode
     55 if hasattr(self, 'model') and hasattr(self.model, "for_inference"):

File [/opt/conda/lib/python3.11/site-packages/transformers/trainer.py:2328](http://localhost:8888/opt/conda/lib/python3.11/site-packages/transformers/trainer.py#line=2327), in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
   2326         hf_hub_utils.enable_progress_bars()
   2327 else:
-> 2328     return inner_training_loop(
   2329         args=args,
   2330         resume_from_checkpoint=resume_from_checkpoint,
   2331         trial=trial,
   2332         ignore_keys_for_eval=ignore_keys_for_eval,
   2333     )

File <string>:323, in _fast_inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)

File [/workspace/work/unsloth_compiled_cache/UnslothSFTTrainer.py:1040](http://localhost:8888/lab/tree/work/work/unsloth_compiled_cache/UnslothSFTTrainer.py#line=1039), in _UnslothSFTTrainer.training_step(self, *args, **kwargs)
   1038 def training_step(self, *args, **kwargs):
   1039     with self.maybe_activation_offload_context:
-> 1040         return super().training_step(*args, **kwargs)

File <string>:91, in _unsloth_training_step(***failed resolving arguments***)

File [/opt/conda/lib/python3.11/site-packages/accelerate/accelerator.py:2734](http://localhost:8888/opt/conda/lib/python3.11/site-packages/accelerate/accelerator.py#line=2733), in Accelerator.backward(self, loss, **kwargs)
   2732     self.lomo_backward(loss, learning_rate)
   2733 else:
-> 2734     loss.backward(**kwargs)

File [/opt/conda/lib/python3.11/site-packages/torch/_tensor.py:647](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_tensor.py#line=646), in Tensor.backward(self, gradient, retain_graph, create_graph, inputs)
    637 if has_torch_function_unary(self):
    638     return handle_torch_function(
    639         Tensor.backward,
    640         (self,),
   (...)    645         inputs=inputs,
    646     )
--> 647 torch.autograd.backward(
    648     self, gradient, retain_graph, create_graph, inputs=inputs
    649 )

File [/opt/conda/lib/python3.11/site-packages/torch/autograd/__init__.py:354](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/autograd/__init__.py#line=353), in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)
    349     retain_graph = create_graph
    351 # The reason we repeat the same comment below is that
    352 # some Python versions print out the first line of a multi-line function
    353 # calls in the traceback and some print out the last line
--> 354 _engine_run_backward(
    355     tensors,
    356     grad_tensors_,
    357     retain_graph,
    358     create_graph,
    359     inputs_tuple,
    360     allow_unreachable=True,
    361     accumulate_grad=True,
    362 )

File [/opt/conda/lib/python3.11/site-packages/torch/autograd/graph.py:829](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/autograd/graph.py#line=828), in _engine_run_backward(t_outputs, *args, **kwargs)
    827     unregister_hooks = _register_logging_hooks_on_whole_graph(t_outputs)
    828 try:
--> 829     return Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
    830         t_outputs, *args, **kwargs
    831     )  # Calls into the C++ engine to run the backward pass
    832 finally:
    833     if attach_logging_hooks:

File [/opt/conda/lib/python3.11/site-packages/torch/autograd/function.py:311](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/autograd/function.py#line=310), in BackwardCFunction.apply(self, *args)
    305     raise RuntimeError(
    306         "Implementing both 'backward' and 'vjp' for a custom "
    307         "Function is not allowed. You should only implement one "
    308         "of them."
    309     )
    310 user_fn = vjp_fn if vjp_fn is not Function.vjp else backward_fn
--> 311 return user_fn(self, *args)

File [/opt/conda/lib/python3.11/site-packages/unsloth_zoo/gradient_checkpointing.py:568](http://localhost:8888/opt/conda/lib/python3.11/site-packages/unsloth_zoo/gradient_checkpointing.py#line=567), in UnslothCheckpointFunction.backward(ctx, *args)
    565     pass
    567     with torch.enable_grad(), device_autocast_ctx, torch.amp.autocast("cpu", **ctx.cpu_autocast_kwargs):  # type: ignore[attr-defined]
--> 568         outputs = ctx.run_function(*detached_inputs)
    569     pass
    570 pass

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1773](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1772), in Module._wrapped_call_impl(self, *args, **kwargs)
   1771     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1772 else:
-> 1773     return self._call_impl(*args, **kwargs)

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1784](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1783), in Module._call_impl(self, *args, **kwargs)
   1779 # If we don't have any hooks, we want to skip the rest of the logic in
   1780 # this function, and just call forward.
   1781 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1782         or _global_backward_pre_hooks or _global_backward_hooks
   1783         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1784     return forward_call(*args, **kwargs)
   1786 result = None
   1787 called_always_called_hooks = set()

File [/opt/conda/lib/python3.11/site-packages/transformers/utils/deprecation.py:172](http://localhost:8888/opt/conda/lib/python3.11/site-packages/transformers/utils/deprecation.py#line=171), in deprecate_kwarg.<locals>.wrapper.<locals>.wrapped_func(*args, **kwargs)
    168 elif minimum_action in (Action.NOTIFY, Action.NOTIFY_ALWAYS) and not is_torchdynamo_compiling():
    169     # DeprecationWarning is ignored by default, so we use FutureWarning instead
    170     warnings.warn(message, FutureWarning, stacklevel=2)
--> 172 return func(*args, **kwargs)

File [/opt/conda/lib/python3.11/site-packages/transformers/models/qwen3/modeling_qwen3.py:275](http://localhost:8888/opt/conda/lib/python3.11/site-packages/transformers/models/qwen3/modeling_qwen3.py#line=274), in Qwen3DecoderLayer.forward(self, hidden_states, attention_mask, position_ids, past_key_values, use_cache, cache_position, position_embeddings, **kwargs)
    273 residual = hidden_states
    274 hidden_states = self.post_attention_layernorm(hidden_states)
--> 275 hidden_states = self.mlp(hidden_states)
    276 hidden_states = residual + hidden_states
    277 return hidden_states

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1773](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1772), in Module._wrapped_call_impl(self, *args, **kwargs)
   1771     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1772 else:
-> 1773     return self._call_impl(*args, **kwargs)

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1784](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1783), in Module._call_impl(self, *args, **kwargs)
   1779 # If we don't have any hooks, we want to skip the rest of the logic in
   1780 # this function, and just call forward.
   1781 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1782         or _global_backward_pre_hooks or _global_backward_hooks
   1783         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1784     return forward_call(*args, **kwargs)
   1786 result = None
   1787 called_always_called_hooks = set()

File [/workspace/work/unsloth_compiled_cache/unsloth_compiled_module_qwen3.py:210](http://localhost:8888/lab/tree/work/work/unsloth_compiled_cache/unsloth_compiled_module_qwen3.py#line=209), in Qwen3MLP.forward(self, x)
    209 def forward(self, x):
--> 210     return Qwen3MLP_forward(self, x)

File [/opt/conda/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py:736](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py#line=735), in _TorchDynamoContext.__call__.<locals>.compile_wrapper(*args, **kwargs)
    733 _maybe_set_eval_frame(_callback_from_stance(callback))
    735 try:
--> 736     return fn(*args, **kwargs)
    737 except Unsupported as e:
    738     if config.verbose:

File [/workspace/work/unsloth_compiled_cache/unsloth_compiled_module_qwen3.py:195](http://localhost:8888/lab/tree/work/work/unsloth_compiled_cache/unsloth_compiled_module_qwen3.py#line=194), in Qwen3MLP_forward(self, x)
    193 @torch.compile(fullgraph = False, dynamic = True, options = torch_compile_options)
    194 def Qwen3MLP_forward(self, x):
--> 195     down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
    196     return down_proj

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1773](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1772), in Module._wrapped_call_impl(self, *args, **kwargs)
   1771     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1772 else:
-> 1773     return self._call_impl(*args, **kwargs)

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1784](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1783), in Module._call_impl(self, *args, **kwargs)
   1779 # If we don't have any hooks, we want to skip the rest of the logic in
   1780 # this function, and just call forward.
   1781 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1782         or _global_backward_pre_hooks or _global_backward_hooks
   1783         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1784     return forward_call(*args, **kwargs)
   1786 result = None
   1787 called_always_called_hooks = set()

File [/workspace/work/unsloth_compiled_cache/Linear8bitLt_peft_forward.py:73](http://localhost:8888/lab/tree/work/work/unsloth_compiled_cache/Linear8bitLt_peft_forward.py#line=72), in unsloth_forward(self, x, *args, **kwargs)
     71     result = self.base_layer(x, *args, **kwargs)
     72 else:
---> 73     result = self.base_layer(x, *args, **kwargs)
     74     for active_adapter in self.active_adapters:
     75         if active_adapter not in self.lora_A.keys():

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1773](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1772), in Module._wrapped_call_impl(self, *args, **kwargs)
   1771     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1772 else:
-> 1773     return self._call_impl(*args, **kwargs)

File [/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py:1784](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/nn/modules/module.py#line=1783), in Module._call_impl(self, *args, **kwargs)
   1779 # If we don't have any hooks, we want to skip the rest of the logic in
   1780 # this function, and just call forward.
   1781 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1782         or _global_backward_pre_hooks or _global_backward_hooks
   1783         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1784     return forward_call(*args, **kwargs)
   1786 result = None
   1787 called_always_called_hooks = set()

File [/opt/conda/lib/python3.11/site-packages/bitsandbytes/nn/modules.py:1072](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/nn/modules.py#line=1071), in Linear8bitLt.forward(self, x)
   1069 if self.bias is not None and self.bias.dtype != x.dtype:
   1070     self.bias.data = self.bias.data.to(x.dtype)
-> 1072 out = bnb.matmul(x, self.weight, bias=self.bias, state=self.state)
   1074 if not self.state.has_fp16_weights and self.state.CB is not None:
   1075     self.weight.data = self.state.CB

File [/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:424](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=423), in matmul(A, B, out, state, threshold, bias)
    422     if A.device.type in ("cpu", "xpu"):
    423         return MatMul8bitFp.apply(A, B, out, bias, state)
--> 424 return MatMul8bitLt.apply(A, B, out, bias, state)

File [/opt/conda/lib/python3.11/site-packages/torch/autograd/function.py:576](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/autograd/function.py#line=575), in Function.apply(cls, *args, **kwargs)
    573 if not torch._C._are_functorch_transforms_active():
    574     # See NOTE: [functorch vjp and autograd interaction]
    575     args = _functorch.utils.unwrap_dead_wrappers(args)
--> 576     return super().apply(*args, **kwargs)  # type: ignore[misc]
    578 if not is_setup_ctx_defined:
    579     raise RuntimeError(
    580         "In order to use an autograd.Function with functorch transforms "
    581         "(vmap, grad, jvp, jacrev, ...), it must override the setup_context "
    582         "staticmethod. For more details, please see "
    583         "https://pytorch.org/docs/main/notes/extending.func.html"
    584     )

File [/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py:154](http://localhost:8888/opt/conda/lib/python3.11/site-packages/bitsandbytes/autograd/_functions.py#line=153), in MatMul8bitLt.forward(ctx, A, B, out, bias, state)
    153 class MatMul8bitLt(torch.autograd.Function):
--> 154     @staticmethod
    155     def forward(
    156         ctx: torch.autograd.function.FunctionCtx,
    157         A: torch.Tensor,
    158         B: torch.Tensor,
    159         out: Optional[torch.Tensor] = None,
    160         bias: Optional[torch.Tensor] = None,
    161         state: Optional[MatmulLtState] = None,
    162     ):
    163         state = state or MatmulLtState()
    165         # default of pytorch behavior if inputs are empty

File [/opt/conda/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py:929](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py#line=928), in DisableContext.__call__.<locals>._fn(*args, **kwargs)
    927 _maybe_set_eval_frame(_callback_from_stance(self.callback))
    928 try:
--> 929     return fn(*args, **kwargs)
    930 finally:
    931     set_eval_frame(None)

File [/opt/conda/lib/python3.11/site-packages/torch/_functorch/aot_autograd.py:1241](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_functorch/aot_autograd.py#line=1240), in aot_module_simplified.<locals>.forward(*runtime_args)
   1239 full_args.extend(params_flat)
   1240 full_args.extend(runtime_args)
-> 1241 return compiled_fn(full_args)

File [/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py:384](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py#line=383), in _create_runtime_wrapper.<locals>.runtime_wrapper(args)
    382         torch._C._set_grad_enabled(False)
    383     record_runtime_wrapper_prologue_exit(cm)
--> 384     all_outs = call_func_at_runtime_with_args(
    385         compiled_fn, args, disable_amp=disable_amp, steal_args=True
    386     )
    387 finally:
    388     if grad_enabled:

File [/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/utils.py:126](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/utils.py#line=125), in call_func_at_runtime_with_args(f, args, steal_args, disable_amp)
    124 with context():
    125     if getattr(f, "_boxed_call", False):
--> 126         out = normalize_as_list(f(args))
    127     else:
    128         # TODO: Please remove soon
    129         # https://github.com/pytorch/pytorch/pull/83137#issuecomment-1211320670
    130         warnings.warn(
    131             "Your compiler for AOTAutograd is returning a function that doesn't take boxed arguments. "
    132             "Please wrap it with functorch.compile.make_boxed_func or handle the boxed arguments yourself. "
    133             "See https://github.com/pytorch/pytorch/pull/83137#issuecomment-1211320670 for rationale."
    134         )

File [/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py:750](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py#line=749), in EffectTokensWrapper.post_compile.<locals>.inner_fn(args)
    747     args = [*([None] * num_tokens), *args]
    748     old_args.clear()
--> 750 outs = compiled_fn(args)
    752 # Inductor cache DummyModule can return None
    753 if outs is None:

File [/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py:556](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py#line=555), in FunctionalizedRngRuntimeWrapper.post_compile.<locals>.wrapper(runtime_args)
    549     out = self._functionalized_rng_runtime_epilogue(
    550         runtime_metadata,
    551         out,
    552         # TODO: this won't be right for the backward when we convert the call_compiled_backward to use the wrapper
    553         runtime_metadata.num_forward_returns,
    554     )
    555     return out
--> 556 return compiled_fn(runtime_args)

File [/opt/conda/lib/python3.11/site-packages/torch/_inductor/output_code.py:584](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_inductor/output_code.py#line=583), in CompiledFxGraph.__call__(self, inputs)
    582 assert self.current_callable is not None
    583 try:
--> 584     return self.current_callable(inputs)
    585 finally:
    586     get_runtime_metrics_context().finish()

File [/opt/conda/lib/python3.11/site-packages/torch/_inductor/utils.py:2716](http://localhost:8888/opt/conda/lib/python3.11/site-packages/torch/_inductor/utils.py#line=2715), in align_inputs_from_check_idxs.<locals>.run(new_inputs)
   2712 def run(new_inputs: list[InputType]) -> Any:
   2713     old_tensors, new_tensors = copy_misaligned_inputs(
   2714         new_inputs, inputs_to_check, mutated_input_idxs
   2715     )
-> 2716     out = model(new_inputs)
   2718     # If a mutated tensor was cloned to be aligned, we need to reflect back the mutation to the
   2719     # original tensor.
   2720     if len(old_tensors):

File [/tmp/torchinductor_unsloth/67/c67ekh5dv3tzbugvqdncd2xm7vt3km63f42igb2w4jybfr4uccul.py:123](http://localhost:8888/tmp/torchinductor_unsloth/67/c67ekh5dv3tzbugvqdncd2xm7vt3km63f42igb2w4jybfr4uccul.py#line=122), in call(args)
    121     assert_alignment(buf7, 16, 'torch.ops.bitsandbytes.int8_mixed_scaled_mm.default')
    122     buf8 = buf6[1]
--> 123     assert_size_stride(buf8, (u1, ), (1, ), 'torch.ops.bitsandbytes.int8_mixed_scaled_mm.default')
    124     assert_alignment(buf8, 16, 'torch.ops.bitsandbytes.int8_mixed_scaled_mm.default')
    125 if not (u1 >= 0):

AssertionError: wrong number of dimensions2 for op: torch.ops.bitsandbytes.int8_mixed_scaled_mm.default

🦥 You can also ask via our Reddit page: https://www.reddit.com/r/unsloth/

Activity

  1. David-AU-github commented on Oct 24, 2025

    @David-AU-github

    Same issue too ; Qwen 3 as well.

    Can load in 4 bit or 16 bit - no issues.
    Also updated unsloth too ; no change in issues.

    Attempted to set dtype to float16 during loading ; and float16 in "trainer" ; dies the same way:
    (these fix the "warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")")

    But not the :
    assert_size_stride(buf8, (u1, ), (1, ), 'torch.ops.bitsandbytes.int8_mixed_scaled_mm.default') ...

    Errors.

  2. M98M commented on Oct 29, 2025

    @M98M

    The notebook works in Colab T4.
    It does not work on local H100.
    It used to work in past versions few months ago. I'm not sure which package causes this problem. bnb/torch/unsloth...?
    now I get this:

    
    /home/venv/.venv/lib/python3.12/site-packages/bitsandbytes/autograd/_functions.py:181: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    ...
    
    AssertionError
    ....
    
    File /tmp/torchinductor_coder/bd/cbd72x5xafiswy2a55iwbdbgc7tbs55br6ma3wxsakhpzngq7ff7.py:123, in call(args)
        121     assert_alignment(buf7, 16, 'torch.ops.bitsandbytes.int8_mixed_scaled_mm.default')
        122     buf8 = buf6[1]
    --> [123](https://vscode-remote+ssh-002dremote-002b172-002e15-002e70-002e11.vscode-resource.vscode-cdn.net/tmp/torchinductor_coder/bd/cbd72x5xafiswy2a55iwbdbgc7tbs55br6ma3wxsakhpzngq7ff7.py:123)     assert_size_stride(buf8, (u1, ), (1, ), 'torch.ops.bitsandbytes.int8_mixed_scaled_mm.default')
        124     assert_alignment(buf8, 16, 'torch.ops.bitsandbytes.int8_mixed_scaled_mm.default')
        125 if not (u1 >= 0):
    
    AssertionError: wrong number of dimensions2 for op: torch.ops.bitsandbytes.int8_mixed_scaled_mm.default
    
    

    unsloth 2025.10.11
    unsloth-zoo 2025.10.12
    xformers 0.0.32.post2
    transformers 4.57.1
    trl 0.23.0
    triton 3.4.0
    torch 2.8.0
    torchao 0.14.1
    torchvision 0.23.0
    nvidia-cublas-cu12 12.8.4.1
    nvidia-cuda-cupti-cu12 12.8.90
    nvidia-cuda-nvrtc-cu12 12.8.93
    nvidia-cuda-runtime-cu12 12.8.90
    nvidia-cudnn-cu12 9.10.2.21
    nvidia-cufft-cu12 11.3.3.83
    nvidia-cufile-cu12 1.13.1.3
    nvidia-curand-cu12 10.3.9.90
    nvidia-cusolver-cu12 11.7.3.90
    nvidia-cusparse-cu12 12.5.8.93
    nvidia-cusparselt-cu12 0.7.1
    nvidia-nccl-cu12 2.27.3
    nvidia-nvjitlink-cu12 12.8.93
    nvidia-nvtx-cu12 12.8.90
    numpy 2.3.4
    peft 0.17.1
    bitsandbytes 0.48.1

  3. Hochikong commented on Nov 1, 2025

    @Hochikong

    I met the same problem when fintuning the Qwen3 4B 2507 with load_in_8bit=True, my python packages on A100 80G machine:

    (unslothvenv) ckho@pm:/mnt/sda/ckhowd/FT$ pip list
    Package                                  Version
    ---------------------------------------- --------------
    accelerate                               1.9.0
    aiohappyeyeballs                         2.6.1
    aiohttp                                  3.12.15
    aiosignal                                1.4.0
    annotated-types                          0.7.0
    anthropic                                0.64.0
    anyio                                    4.9.0
    argon2-cffi                              25.1.0
    argon2-cffi-bindings                     25.1.0
    arrow                                    1.3.0
    asttokens                                3.0.0
    async-lru                                2.0.5
    async-timeout                            4.0.3
    attrs                                    25.3.0
    babel                                    2.17.0
    backoff                                  2.2.1
    backports.asyncio.runner                 1.2.0
    beautifulsoup4                           4.13.4
    bitsandbytes                             0.46.1
    bleach                                   6.2.0
    boto3                                    1.40.22
    botocore                                 1.40.22
    cachetools                               5.5.2
    certifi                                  2025.8.3
    cffi                                     1.17.1
    charset-normalizer                       3.4.2
    click                                    8.2.1
    comm                                     0.2.3
    cryptography                             45.0.6
    cut-cross-entropy                        25.1.1
    dashscope                                1.24.2
    dataclasses-json                         0.6.7
    datasets                                 3.6.0
    debugpy                                  1.8.15
    decorator                                5.2.1
    deepeval                                 3.4.1
    defusedxml                               0.7.1
    diffusers                                0.34.0
    dill                                     0.3.8
    distro                                   1.9.0
    docstring_parser                         0.17.0
    exceptiongroup                           1.3.0
    execnet                                  2.1.1
    executing                                2.2.0
    fastjsonschema                           2.21.1
    filelock                                 3.18.0
    fqdn                                     1.5.1
    frozenlist                               1.7.0
    fsspec                                   2025.3.0
    gguf                                     0.17.1
    google-auth                              2.40.3
    google-genai                             1.32.0
    googleapis-common-protos                 1.70.0
    greenlet                                 3.2.4
    grpcio                                   1.74.0
    h11                                      0.16.0
    hf_transfer                              0.1.9
    hf-xet                                   1.1.5
    httpcore                                 1.0.9
    httpx                                    0.28.1
    httpx-sse                                0.4.1
    huggingface-hub                          0.34.3
    idna                                     3.10
    importlib_metadata                       8.7.0
    iniconfig                                2.1.0
    ipykernel                                6.30.0
    ipython                                  8.37.0
    isoduration                              20.11.0
    jedi                                     0.19.2
    Jinja2                                   3.1.6
    jiter                                    0.10.0
    jmespath                                 1.0.1
    joblib                                   1.5.2
    json5                                    0.12.0
    jsonpatch                                1.33
    jsonpointer                              3.0.0
    jsonschema                               4.25.0
    jsonschema-specifications                2025.4.1
    jupyter_client                           8.6.3
    jupyter_core                             5.8.1
    jupyter-events                           0.12.0
    jupyter-lsp                              2.2.6
    jupyter_server                           2.16.0
    jupyter_server_terminals                 0.5.3
    jupyterlab                               4.4.5
    jupyterlab_pygments                      0.3.0
    jupyterlab_server                        2.27.3
    langchain                                0.3.27
    langchain-community                      0.3.29
    langchain-core                           0.3.75
    langchain-text-splitters                 0.3.9
    langsmith                                0.4.20
    lark                                     1.2.2
    markdown-it-py                           3.0.0
    MarkupSafe                               3.0.2
    marshmallow                              3.26.1
    matplotlib-inline                        0.1.7
    mdurl                                    0.1.2
    mistral_common                           1.8.5
    mistune                                  3.1.3
    mpmath                                   1.3.0
    msgspec                                  0.19.0
    multidict                                6.6.3
    multiprocess                             0.70.16
    mypy_extensions                          1.1.0
    nbclient                                 0.10.2
    nbconvert                                7.16.6
    nbformat                                 5.10.4
    nest-asyncio                             1.6.0
    networkx                                 3.4.2
    notebook_shim                            0.2.4
    numpy                                    2.2.6
    nvidia-cublas-cu12                       12.6.4.1
    nvidia-cuda-cupti-cu12                   12.6.80
    nvidia-cuda-nvrtc-cu12                   12.6.77
    nvidia-cuda-runtime-cu12                 12.6.77
    nvidia-cudnn-cu12                        9.5.1.17
    nvidia-cufft-cu12                        11.3.0.4
    nvidia-cufile-cu12                       1.11.1.6
    nvidia-curand-cu12                       10.3.7.77
    nvidia-cusolver-cu12                     11.7.1.2
    nvidia-cusparse-cu12                     12.5.4.2
    nvidia-cusparselt-cu12                   0.6.3
    nvidia-ml-py                             12.575.51
    nvidia-nccl-cu12                         2.26.2
    nvidia-nvjitlink-cu12                    12.6.85
    nvidia-nvtx-cu12                         12.6.77
    ollama                                   0.5.3
    openai                                   1.102.0
    opentelemetry-api                        1.36.0
    opentelemetry-exporter-otlp-proto-common 1.36.0
    opentelemetry-exporter-otlp-proto-grpc   1.36.0
    opentelemetry-proto                      1.36.0
    opentelemetry-sdk                        1.36.0
    opentelemetry-semantic-conventions       0.57b0
    orjson                                   3.11.3
    overrides                                7.7.0
    packaging                                25.0
    pandas                                   2.3.1
    pandocfilters                            1.5.1
    parso                                    0.8.4
    peft                                     0.17.0
    pexpect                                  4.9.0
    pillow                                   11.3.0
    pip                                      22.0.2
    platformdirs                             4.3.8
    pluggy                                   1.6.0
    portalocker                              3.2.0
    posthog                                  6.7.0
    prettytable                              3.16.0
    prometheus_client                        0.22.1
    prompt_toolkit                           3.0.51
    propcache                                0.3.2
    protobuf                                 6.31.1
    psutil                                   7.0.0
    ptyprocess                               0.7.0
    pure_eval                                0.2.3
    pyarrow                                  21.0.0
    pyasn1                                   0.6.1
    pyasn1_modules                           0.4.2
    pycountry                                24.6.1
    pycparser                                2.22
    pydantic                                 2.11.7
    pydantic_core                            2.33.2
    pydantic-extra-types                     2.10.6
    pydantic-settings                        2.10.1
    pyecharts                                2.0.8
    pyfiglet                                 1.0.4
    Pygments                                 2.19.2
    pynvml                                   12.0.0
    pytest                                   8.4.1
    pytest-asyncio                           1.1.0
    pytest-repeat                            0.9.4
    pytest-rerunfailures                     12.0
    pytest-xdist                             3.8.0
    python-dateutil                          2.9.0.post0
    python-dotenv                            1.1.1
    python-json-logger                       3.3.0
    pytz                                     2025.2
    PyYAML                                   6.0.2
    pyzmq                                    27.0.1
    referencing                              0.36.2
    regex                                    2025.7.34
    requests                                 2.32.5
    requests-toolbelt                        1.0.0
    rfc3339-validator                        0.1.4
    rfc3986-validator                        0.1.1
    rfc3987-syntax                           1.1.0
    rich                                     13.9.4
    rpds-py                                  0.26.0
    rsa                                      4.9.1
    s3transfer                               0.13.1
    safetensors                              0.5.3
    scikit-learn                             1.7.1
    scipy                                    1.15.3
    Send2Trash                               1.8.3
    sentencepiece                            0.2.0
    sentry-sdk                               2.35.1
    setuptools                               59.6.0
    shellingham                              1.5.4
    shtab                                    1.7.2
    simplejson                               3.20.1
    six                                      1.17.0
    sniffio                                  1.3.1
    soupsieve                                2.7
    SQLAlchemy                               2.0.43
    stack-data                               0.6.3
    swankit                                  0.2.4
    swanlab                                  0.6.13
    sympy                                    1.14.0
    tabulate                                 0.9.0
    tenacity                                 9.1.2
    terminado                                0.18.1
    threadpoolctl                            3.6.0
    tiktoken                                 0.12.0
    tinycss2                                 1.4.0
    tokenizers                               0.21.4
    tomli                                    2.2.1
    torch                                    2.7.1
    torchao                                  0.12.0
    torchvision                              0.22.1
    tornado                                  6.5.1
    tqdm                                     4.67.1
    traitlets                                5.14.3
    transformers                             4.55.4
    triton                                   3.3.1
    trl                                      0.20.0
    typeguard                                4.4.4
    typer                                    0.16.1
    types-python-dateutil                    2.9.0.20250708
    typing_extensions                        4.14.1
    typing-inspect                           0.9.0
    typing-inspection                        0.4.1
    tyro                                     0.9.27
    tzdata                                   2025.2
    unsloth                                  2025.10.1
    unsloth_zoo                              2025.10.1
    uri-template                             1.3.0
    urllib3                                  2.5.0
    wcwidth                                  0.2.13
    webcolors                                24.11.1
    webencodings                             0.5.1
    websocket-client                         1.8.0
    websockets                               15.0.1
    wheel                                    0.45.1
    wrapt                                    1.17.3
    xformers                                 0.0.31.post1
    xxhash                                   3.5.0
    yarl                                     1.20.1
    zipp                                     3.23.0
    zstandard                                0.24.0
    

    Error Message:

    ==((====))==  Unsloth - 2x faster free finetuning | Num GPUs used = 1
       \\   /|    Num examples = 415 | Num Epochs = 16 | Total steps = 160
    O^O/ \_/ \    Batch size per device = 7 | Gradient accumulation steps = 6
    \        /    Data Parallel GPUs = 1 | Total batch size (7 x 6 x 1) = 42
     "-____-"     Trainable parameters = 66,060,288 of 4,088,528,384 (1.62% trained)
      0%|                                                                                                                                                                                              | 0/160 [00:00<?, ?it/s]
    /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:185: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:185: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:185: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:185: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:185: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:185: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:185: UserWarning: MatMul8bitLt: inputs will be cast from torch.bfloat16 to float16 during quantization
      warnings.warn(f"MatMul8bitLt: inputs will be cast from {A.dtype} to float16 during quantization")
    ---------------------------------------------------------------------------
    AssertionError                            Traceback (most recent call last)
    Cell In[5], line 12
          7 print(tokenizer.decode(trainer.train_dataset[100]["input_ids"]))
          8 print(tokenizer.decode(
          9     [tokenizer.pad_token_id if x == -100 else x for x in trainer.train_dataset[100]["labels"]]).replace(
         10     tokenizer.pad_token, " "))
    ---> 12 trainer_stats = trainer.train()
         13 swanlab.finish()
         15 index = 1
    
    File /mnt/sda/ckhowd/FT/unsloth_compiled_cache/UnslothSFTTrainer.py:53, in prepare_for_training_mode.<locals>.wrapper(self, *args, **kwargs)
         51 if hasattr(self, 'model') and hasattr(self.model, "for_training"):
         52     self.model.for_training()
    ---> 53 output = f(self, *args, **kwargs)
         54 # Return inference mode
         55 if hasattr(self, 'model') and hasattr(self.model, "for_inference"):
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/transformers/trainer.py:2238, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
       2236         hf_hub_utils.enable_progress_bars()
       2237 else:
    -> 2238     return inner_training_loop(
       2239         args=args,
       2240         resume_from_checkpoint=resume_from_checkpoint,
       2241         trial=trial,
       2242         ignore_keys_for_eval=ignore_keys_for_eval,
       2243     )
    
    File <string>:323, in _fast_inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
    
    File /mnt/sda/ckhowd/FT/unsloth_compiled_cache/UnslothSFTTrainer.py:1037, in _UnslothSFTTrainer.training_step(self, *args, **kwargs)
       1035 def training_step(self, *args, **kwargs):
       1036     with self.maybe_activation_offload_context:
    -> 1037         return super().training_step(*args, **kwargs)
    
    File <string>:83, in _unsloth_training_step(***failed resolving arguments***)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/accelerate/accelerator.py:2578, in Accelerator.backward(self, loss, **kwargs)
       2576     self.lomo_backward(loss, learning_rate)
       2577 else:
    -> 2578     loss.backward(**kwargs)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_tensor.py:648, in Tensor.backward(self, gradient, retain_graph, create_graph, inputs)
        638 if has_torch_function_unary(self):
        639     return handle_torch_function(
        640         Tensor.backward,
        641         (self,),
       (...)
        646         inputs=inputs,
        647     )
    --> 648 torch.autograd.backward(
        649     self, gradient, retain_graph, create_graph, inputs=inputs
        650 )
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/autograd/__init__.py:353, in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)
        348     retain_graph = create_graph
        350 # The reason we repeat the same comment below is that
        351 # some Python versions print out the first line of a multi-line function
        352 # calls in the traceback and some print out the last line
    --> 353 _engine_run_backward(
        354     tensors,
        355     grad_tensors_,
        356     retain_graph,
        357     create_graph,
        358     inputs,
        359     allow_unreachable=True,
        360     accumulate_grad=True,
        361 )
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/autograd/graph.py:824, in _engine_run_backward(t_outputs, *args, **kwargs)
        822     unregister_hooks = _register_logging_hooks_on_whole_graph(t_outputs)
        823 try:
    --> 824     return Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
        825         t_outputs, *args, **kwargs
        826     )  # Calls into the C++ engine to run the backward pass
        827 finally:
        828     if attach_logging_hooks:
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/autograd/function.py:307, in BackwardCFunction.apply(self, *args)
        301     raise RuntimeError(
        302         "Implementing both 'backward' and 'vjp' for a custom "
        303         "Function is not allowed. You should only implement one "
        304         "of them."
        305     )
        306 user_fn = vjp_fn if vjp_fn is not Function.vjp else backward_fn
    --> 307 return user_fn(self, *args)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/unsloth_zoo/gradient_checkpointing.py:568, in UnslothCheckpointFunction.backward(ctx, *args)
        565     pass
        567     with torch.enable_grad(), device_autocast_ctx, torch.amp.autocast("cpu", **ctx.cpu_autocast_kwargs):  # type: ignore[attr-defined]
    --> 568         outputs = ctx.run_function(*detached_inputs)
        569     pass
        570 pass
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1751, in Module._wrapped_call_impl(self, *args, **kwargs)
       1749     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
       1750 else:
    -> 1751     return self._call_impl(*args, **kwargs)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1762, in Module._call_impl(self, *args, **kwargs)
       1757 # If we don't have any hooks, we want to skip the rest of the logic in
       1758 # this function, and just call forward.
       1759 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
       1760         or _global_backward_pre_hooks or _global_backward_hooks
       1761         or _global_forward_hooks or _global_forward_pre_hooks):
    -> 1762     return forward_call(*args, **kwargs)
       1764 result = None
       1765 called_always_called_hooks = set()
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/transformers/models/qwen3/modeling_qwen3.py:272, in Qwen3DecoderLayer.forward(self, hidden_states, attention_mask, position_ids, past_key_value, use_cache, cache_position, position_embeddings, **kwargs)
        270 residual = hidden_states
        271 hidden_states = self.post_attention_layernorm(hidden_states)
    --> 272 hidden_states = self.mlp(hidden_states)
        273 hidden_states = residual + hidden_states
        274 return hidden_states
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1751, in Module._wrapped_call_impl(self, *args, **kwargs)
       1749     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
       1750 else:
    -> 1751     return self._call_impl(*args, **kwargs)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1762, in Module._call_impl(self, *args, **kwargs)
       1757 # If we don't have any hooks, we want to skip the rest of the logic in
       1758 # this function, and just call forward.
       1759 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
       1760         or _global_backward_pre_hooks or _global_backward_hooks
       1761         or _global_forward_hooks or _global_forward_pre_hooks):
    -> 1762     return forward_call(*args, **kwargs)
       1764 result = None
       1765 called_always_called_hooks = set()
    
    File /mnt/sda/ckhowd/FT/unsloth_compiled_cache/unsloth_compiled_module_qwen3.py:210, in Qwen3MLP.forward(self, x)
        209 def forward(self, x):
    --> 210     return Qwen3MLP_forward(self, x)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py:655, in _TorchDynamoContext.__call__.<locals>._fn(*args, **kwargs)
        652 _maybe_set_eval_frame(_callback_from_stance(callback))
        654 try:
    --> 655     return fn(*args, **kwargs)
        656 except Unsupported as e:
        657     if config.verbose:
    
    File /mnt/sda/ckhowd/FT/unsloth_compiled_cache/unsloth_compiled_module_qwen3.py:195, in Qwen3MLP_forward(self, x)
        193 @torch.compile(fullgraph = False, dynamic = True, options = torch_compile_options)
        194 def Qwen3MLP_forward(self, x):
    --> 195     down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
        196     return down_proj
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1751, in Module._wrapped_call_impl(self, *args, **kwargs)
       1749     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
       1750 else:
    -> 1751     return self._call_impl(*args, **kwargs)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1762, in Module._call_impl(self, *args, **kwargs)
       1757 # If we don't have any hooks, we want to skip the rest of the logic in
       1758 # this function, and just call forward.
       1759 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
       1760         or _global_backward_pre_hooks or _global_backward_hooks
       1761         or _global_forward_hooks or _global_forward_pre_hooks):
    -> 1762     return forward_call(*args, **kwargs)
       1764 result = None
       1765 called_always_called_hooks = set()
    
    File /mnt/sda/ckhowd/FT/unsloth_compiled_cache/Linear8bitLt_peft_forward.py:73, in unsloth_forward(self, x, *args, **kwargs)
         71     result = self.base_layer(x, *args, **kwargs)
         72 else:
    ---> 73     result = self.base_layer(x, *args, **kwargs)
         74     for active_adapter in self.active_adapters:
         75         if active_adapter not in self.lora_A.keys():
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1751, in Module._wrapped_call_impl(self, *args, **kwargs)
       1749     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
       1750 else:
    -> 1751     return self._call_impl(*args, **kwargs)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/nn/modules/module.py:1762, in Module._call_impl(self, *args, **kwargs)
       1757 # If we don't have any hooks, we want to skip the rest of the logic in
       1758 # this function, and just call forward.
       1759 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
       1760         or _global_backward_pre_hooks or _global_backward_hooks
       1761         or _global_forward_hooks or _global_forward_pre_hooks):
    -> 1762     return forward_call(*args, **kwargs)
       1764 result = None
       1765 called_always_called_hooks = set()
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/nn/modules.py:1004, in Linear8bitLt.forward(self, x)
       1001 if self.bias is not None and self.bias.dtype != x.dtype:
       1002     self.bias.data = self.bias.data.to(x.dtype)
    -> 1004 out = bnb.matmul(x, self.weight, bias=self.bias, state=self.state)
       1006 if not self.state.has_fp16_weights and self.state.CB is not None:
       1007     self.weight.data = self.state.CB
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:369, in matmul(A, B, out, state, threshold, bias)
        367 if threshold > 0.0:
        368     state.threshold = threshold
    --> 369 return MatMul8bitLt.apply(A, B, out, bias, state)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/autograd/function.py:575, in Function.apply(cls, *args, **kwargs)
        572 if not torch._C._are_functorch_transforms_active():
        573     # See NOTE: [functorch vjp and autograd interaction]
        574     args = _functorch.utils.unwrap_dead_wrappers(args)
    --> 575     return super().apply(*args, **kwargs)  # type: ignore[misc]
        577 if not is_setup_ctx_defined:
        578     raise RuntimeError(
        579         "In order to use an autograd.Function with functorch transforms "
        580         "(vmap, grad, jvp, jacrev, ...), it must override the setup_context "
        581         "staticmethod. For more details, please see "
        582         "https://pytorch.org/docs/main/notes/extending.func.html"
        583     )
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/bitsandbytes/autograd/_functions.py:158, in MatMul8bitLt.forward(ctx, A, B, out, bias, state)
        157 class MatMul8bitLt(torch.autograd.Function):
    --> 158     @staticmethod
        159     def forward(
        160         ctx: torch.autograd.function.FunctionCtx,
        161         A: torch.Tensor,
        162         B: torch.Tensor,
        163         out: Optional[torch.Tensor] = None,
        164         bias: Optional[torch.Tensor] = None,
        165         state: Optional[MatmulLtState] = None,
        166     ):
        167         state = state or MatmulLtState()
        169         # default of pytorch behavior if inputs are empty
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py:838, in DisableContext.__call__.<locals>._fn(*args, **kwargs)
        836 _maybe_set_eval_frame(_callback_from_stance(self.callback))
        837 try:
    --> 838     return fn(*args, **kwargs)
        839 finally:
        840     set_eval_frame(None)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py:1209, in aot_module_simplified.<locals>.forward(*runtime_args)
       1207 full_args.extend(params_flat)
       1208 full_args.extend(runtime_args)
    -> 1209 return compiled_fn(full_args)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py:328, in _create_runtime_wrapper.<locals>.runtime_wrapper(args)
        326     if grad_enabled:
        327         torch._C._set_grad_enabled(False)
    --> 328     all_outs = call_func_at_runtime_with_args(
        329         compiled_fn, args, disable_amp=disable_amp, steal_args=True
        330     )
        331 finally:
        332     if grad_enabled:
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_functorch/_aot_autograd/utils.py:126, in call_func_at_runtime_with_args(f, args, steal_args, disable_amp)
        124 with context():
        125     if hasattr(f, "_boxed_call"):
    --> 126         out = normalize_as_list(f(args))
        127     else:
        128         # TODO: Please remove soon
        129         # https://github.com/pytorch/pytorch/pull/83137#issuecomment-1211320670
        130         warnings.warn(
        131             "Your compiler for AOTAutograd is returning a function that doesn't take boxed arguments. "
        132             "Please wrap it with functorch.compile.make_boxed_func or handle the boxed arguments yourself. "
        133             "See https://github.com/pytorch/pytorch/pull/83137#issuecomment-1211320670 for rationale."
        134         )
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py:689, in EffectTokensWrapper.post_compile.<locals>.inner_fn(args)
        686     args = [*([None] * num_tokens), *args]
        687     old_args.clear()
    --> 689 outs = compiled_fn(args)
        691 # Inductor cache DummyModule can return None
        692 if outs is None:
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py:495, in FunctionalizedRngRuntimeWrapper.post_compile.<locals>.wrapper(runtime_args)
        488     out = self._functionalized_rng_runtime_epilogue(
        489         runtime_metadata,
        490         out,
        491         # TODO: this won't be right for the backward when we convert the call_compiled_backward to use the wrapper
        492         runtime_metadata.num_forward_returns,
        493     )
        494     return out
    --> 495 return compiled_fn(runtime_args)
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_inductor/output_code.py:460, in CompiledFxGraph.__call__(self, inputs)
        458 assert self.current_callable is not None
        459 try:
    --> 460     return self.current_callable(inputs)
        461 finally:
        462     get_runtime_metrics_context().finish()
    
    File /mnt/sda/ckhowd/unslothvenv/lib/python3.10/site-packages/torch/_inductor/utils.py:2404, in align_inputs_from_check_idxs.<locals>.run(new_inputs)
       2402 def run(new_inputs: list[InputType]) -> Any:
       2403     copy_misaligned_inputs(new_inputs, inputs_to_check)
    -> 2404     return model(new_inputs)
    
    File /tmp/torchinductor_ckho/6x/c6x6fatkegpfi4tjcbag6r6o23gfggatwuiqpjjoqxiatiufuci7.py:117, in call(args)
        115     assert_size_stride(buf7, (s0*s1, s3), (s3, 1))
        116     buf8 = buf6[1]
    --> 117     assert_size_stride(buf8, (u1, ), (1, ))
        118 if not u1 >= 0:
        119     raise RuntimeError('u1 >= 0')
    
    AssertionError: wrong number of dimensions
    
  4. aprilcoskun commented on Nov 6, 2025

    @aprilcoskun

    I have the same issue for Gemma 3 4b with load_in_8bit=True. Using Colab L4 gpu. Loading in 4bit works fine.

  5. Kepler-Br commented on Nov 9, 2025

    @Kepler-Br

    Same
    Using 2025.10.9-pt2.8.0-cu12.8-update-entrypoint docker image
    If I try to load in torch.float16 the warnings are gone, but trainer fails with AssertionError: wrong number of dimensions2 for op: torch.ops.bitsandbytes.int8_mixed_scaled_mm.default
    Tried Llama-3.2-1B-Instruct, gemma-3-1b-it, Qwen3-0.6B, and mistral

  6. aaljabari commented on Dec 6, 2025

    @aaljabari

    I have the same issue for Qwen3-14B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions