unsloth: [Bug] AttributeError: 'NoneType' object has no attribute 'absmax' when training llama-3.1-8b with GRPOTrainer

  1. Did you update? pip install --upgrade unsloth unsloth_zoo yes
  2. Colab or Kaggle or local / cloud cloud
  3. Number GPUs used, use nvidia-smi 1
  4. Which notebook? Please link! based on LLama 3.1 GRPO
  5. Which Unsloth version, TRL version, transformers version, PyTorch version? unsloth: 2025.7.1 unsloth_zoo: 2025.7.1 trl: 0.19.1 triton: 3.3.0 transformers: 4.53.1 torch: 2.7.0
  6. Which trainer? SFTTrainer, GRPOTrainer etc GRPOTrainer

I’m facing the error as in the title when trying to fine tune llama-3.1 with GRPO based on one of the notebooks. Trace:

[rank0]: Traceback (most recent call last):
[rank0]:   File "/workspace/data-science/ble.py", line 100, in <module>
[rank0]:     run()
[rank0]:   File "/workspace/data-science/ble.py", line 87, in run
[rank0]:     trainer.train(resume_from_checkpoint=False)
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/transformers/trainer.py", line 2206, in train
[rank0]:     return inner_training_loop(
[rank0]:            ^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "<string>", line 320, in _fast_inner_training_loop
[rank0]:   File "<string>", line 34, in _unsloth_training_step
[rank0]:   File "/workspace/data-science/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 2040, in compute_loss
[rank0]:     loss, completion_length, mean_kl = grpo_accumulated_loss(
[rank0]:                                        ^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 313, in grpo_accumulated_loss
[rank0]:     ref_hidden_states = trainer.model(
[rank0]:                         ^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/models/llama.py", line 1292, in PeftModel_fast_forward
[rank0]:     return self.base_model(
[rank0]:            ^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/peft/tuners/tuners_utils.py", line 216, in forward
[rank0]:     return self.model.forward(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/models/llama.py", line 1115, in _CausalLM_fast_forward
[rank0]:     outputs = self.model(
[rank0]:               ^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/models/llama.py", line 931, in LlamaModel_fast_forward
[rank0]:     layer_outputs = decoder_layer(
[rank0]:                     ^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/transformers/modeling_layers.py", line 82, in __call__
[rank0]:     return self._gradient_checkpointing_func(partial(super().__call__, **kwargs), *args)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/_compile.py", line 51, in inner
[rank0]:     return disable_fn(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/_dynamo/eval_frame.py", line 838, in _fn
[rank0]:     return fn(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/utils/checkpoint.py", line 488, in checkpoint
[rank0]:     return CheckpointFunction.apply(function, preserve, *args)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/autograd/function.py", line 575, in apply
[rank0]:     return super().apply(*args, **kwargs)  # type: ignore[misc]
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth_zoo/gradient_checkpointing.py", line 475, in forward
[rank0]:     outputs = run_function(*args)
[rank0]:               ^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/models/llama.py", line 604, in LlamaDecoderLayer_fast_forward
[rank0]:     hidden_states, self_attn_weights, present_key_value = self.self_attn(
[rank0]:                                                           ^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
[rank0]:     return self._call_impl(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
[rank0]:     return forward_call(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/models/llama.py", line 458, in LlamaAttention_fast_forward
[rank0]:     Q, K, V = self.apply_qkv(self, hidden_states)
[rank0]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/kernels/fast_lora.py", line 366, in apply_lora_qkv
[rank0]:     Q, K, V = LoRA_QKV.apply(X,
[rank0]:               ^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/autograd/function.py", line 575, in apply
[rank0]:     return super().apply(*args, **kwargs)  # type: ignore[misc]
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/amp/autocast_mode.py", line 510, in decorate_fwd
[rank0]:     return fwd(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/kernels/fast_lora.py", line 259, in forward
[rank0]:     Q = matmul_lora(X, QW, QW_quant, QA, QB, QS)
[rank0]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/kernels/utils.py", line 693, in matmul_lora
[rank0]:     W = fast_dequantize(W.t(), W_quant, use_global_buffer = True)
[rank0]:         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
[rank0]:     return func(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/workspace/data-science/env/lib/python3.12/site-packages/unsloth/kernels/utils.py", line 321, in fast_dequantize
[rank0]:     absmax2    = state2.absmax
[rank0]:                  ^^^^^^^^^^^^^
[rank0]: AttributeError: 'NoneType' object has no attribute 'absmax'

Full pip freeze output:

accelerate==1.8.1
aiohappyeyeballs==2.6.1
aiohttp==3.12.13
aiosignal==1.4.0
airportsdata==20250706
annotated-types==0.7.0
anyio==4.9.0
astor==0.8.1
attrs==25.3.0
bitsandbytes==0.46.1
blake3==1.0.5
cachetools==6.1.0
certifi==2025.7.9
charset-normalizer==3.4.2
click==8.2.1
cloudpickle==3.1.1
compressed-tensors==0.10.2
cupy-cuda12x==13.4.1
cut-cross-entropy==25.1.1
datasets==4.0.0
depyf==0.18.0
diffusers==0.34.0
dill==0.3.8
diskcache==5.6.3
distro==1.9.0
dnspython==2.7.0
docstring_parser==0.16
einops==0.8.1
email_validator==2.2.0
fastapi==0.116.0
fastapi-cli==0.0.8
fastapi-cloud-cli==0.1.2
fastrlock==0.8.3
filelock==3.18.0
frozenlist==1.7.0
fsspec==2025.3.0
gguf==0.17.1
h11==0.16.0
hf-xet==1.1.5
hf_transfer==0.1.9
httpcore==1.0.9
httptools==0.6.4
httpx==0.28.1
huggingface-hub==0.33.2
idna==3.10
importlib_metadata==8.7.0
interegular==0.3.3
Jinja2==3.1.6
jiter==0.10.0
jsonschema==4.24.0
jsonschema-specifications==2025.4.1
lark==1.2.2
llguidance==0.7.30
llvmlite==0.44.0
lm-format-enforcer==0.10.11
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mdurl==0.1.2
mistral_common==1.7.0
mpmath==1.3.0
msgpack==1.1.1
msgspec==0.19.0
multidict==6.6.3
multiprocess==0.70.16
nest-asyncio==1.6.0
networkx==3.5
ninja==1.11.1.4
numba==0.61.2
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-nccl-cu12==2.26.2
nvidia-nvjitlink-cu12==12.6.85
nvidia-nvtx-cu12==12.6.77
openai==1.90.0
opencv-python-headless==4.12.0.88
outlines==0.1.11
outlines_core==0.1.26
packaging==25.0
pandas==2.3.1
partial-json-parser==0.2.1.1.post6
peft==0.16.0
pillow==11.3.0
prometheus-fastapi-instrumentator==7.1.0
prometheus_client==0.22.1
propcache==0.3.2
protobuf==3.20.3
psutil==7.0.0
py-cpuinfo==9.0.0
pyarrow==20.0.0
pybase64==1.4.1
pycountry==24.6.1
pydantic==2.11.7
pydantic_core==2.33.2
Pygments==2.19.2
python-dateutil==2.9.0.post0
python-dotenv==1.1.1
python-json-logger==3.3.0
python-multipart==0.0.20
pytz==2025.2
PyYAML==6.0.2
pyzmq==27.0.0
ray==2.47.1
referencing==0.36.2
regex==2024.11.6
requests==2.32.4
rich==14.0.0
rich-toolkit==0.14.8
rignore==0.5.1
rpds-py==0.26.0
safetensors==0.5.3
scipy==1.16.0
sentencepiece==0.2.0
sentry-sdk==2.32.0
setuptools==79.0.1
shellingham==1.5.4
shtab==1.7.2
six==1.17.0
sniffio==1.3.1
starlette==0.46.2
sympy==1.14.0
tiktoken==0.9.0
tokenizers==0.21.2
torch==2.7.0
torchaudio==2.7.0
torchvision==0.22.0
tqdm==4.67.1
transformers==4.53.1
triton==3.3.0
trl==0.19.1
typeguard==4.4.4
typer==0.16.0
typing-inspection==0.4.1
typing_extensions==4.14.1
tyro==0.9.26
tzdata==2025.2
unsloth==2025.7.1
unsloth_zoo==2025.7.1
urllib3==2.5.0
uvicorn==0.35.0
uvloop==0.21.0
vllm==0.9.2
watchfiles==1.1.0
websockets==15.0.1
wheel==0.45.1
xformers==0.0.30
xgrammar==0.1.19
xxhash==3.5.0
yarl==1.20.1
zipp==3.23.0

nvcc --version - happened on multiple different ones 12.4, 12.6

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Fri_Feb_21_20:23:50_PST_2025
Cuda compilation tools, release 12.8, V12.8.93
Build cuda_12.8.r12.8/compiler.35583870_0
from unsloth import FastLanguageModel, is_bfloat16_supported
from datetime import datetime
import datasets
import random

max_seq_length = 9_000 # Can increase for longer reasoning traces
lora_rank = 64 # Larger rank = smarter, but slower

RANDOM_SEED = 1337

CURRENT_TIME = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")

def format_prompt(n):
    return {
        "prompt": [
            {"role": "system", "content": "Write N words on any topic."},
            {"role": "user", "content": f"N: {n}"}
        ]    
    }

dataset_formatted = datasets.Dataset.from_list([format_prompt(random.randint(100, 200)) for _ in range(1000)])

def run():
    model, tokenizer = FastLanguageModel.from_pretrained(
        model_name = "meta-llama/meta-Llama-3.1-8B-Instruct",
        max_seq_length = max_seq_length,
        load_in_4bit = True, # False for LoRA 16bit
        fast_inference = True, # Enable vLLM fast inference
        max_lora_rank = lora_rank,
        gpu_memory_utilization = 0.7, # Reduce if out of memory
    )

    model = FastLanguageModel.get_peft_model(
        model,
        r = lora_rank, # 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",
        ], # Remove QKVO if out of memory
        lora_alpha = lora_rank,
        use_gradient_checkpointing = "unsloth", # Enable long context finetuning
        random_state = 3407,
    )

    def foo_reward_func(prompts, completions, **kwargs) -> list[float]:
        return [1.0] * len(completions)


    from trl import GRPOConfig, GRPOTrainer
    training_args = GRPOConfig(
        use_vllm = True, # use vLLM for fast inference!
        learning_rate = 5e-6,
        adam_beta1 = 0.9,
        adam_beta2 = 0.99,
        weight_decay = 0.1,
        warmup_ratio = 0.1,
        lr_scheduler_type = "cosine",
        optim = "paged_adamw_8bit",
        logging_steps = 1,
        bf16 = is_bfloat16_supported(),
        fp16 = not is_bfloat16_supported(),
        per_device_train_batch_size = 6,
        gradient_accumulation_steps = 6, # Increase to 4 for smoother training
        num_generations = 6, # Decrease if out of memory
        max_prompt_length = 4024,
        max_completion_length = 4024,
        # num_train_epochs = 1, # Set to 1 for a full training run
        max_steps = 1000,
        save_steps = 100,
        max_grad_norm = 0.1,
        output_dir = f"outputs_foo_model",
        report_to="none",
        temperature = 0.8,
    )

    try:
        trainer = GRPOTrainer(
            model = model,
            processing_class = tokenizer,
            reward_funcs = [
                foo_reward_func,
            ],
            args = training_args,
            train_dataset = dataset_formatted,
        )
        trainer.train(resume_from_checkpoint=False)
    except KeyboardInterrupt:
        print("Exiting gracefully!")

    MODEL_OUTPUT_DIR = f"foo_model_16b_{CURRENT_TIME}"

    model.save_pretrained_merged(
        MODEL_OUTPUT_DIR,
        tokenizer,
        save_method="merged_16bit",
    )

if __name__ == "__main__":
    run()

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

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 1
  • Comments: 29

Most upvoted comments

@behroozazarkhalili @simonusher

was able to reproduce the same error you are getting. We’ll work on fixing it. Thank you for your patience

@rolandtannous I was able to reproduce the same issue even after upgrading to the latest version (same as @behroozazarkhalili).

Hey, it looks like it’s been fixed for me with the latest version. Thanks a lot for help

What I meant is that it shouldn’t install the dev version. If it did, then the dependency wasn’t pinned while I think that it should be . I’ll communicate this to the appropriate person.

Uhum. These are the versions that are working for me right now.

transformers: 4.51.3
unsloth: 2025.7.3
numpy: 1.26.4
bitsandbytes: 0.46.1
peft: 0.15.2
vllm: 0.9.2

@rolandtannous It is still present, even after updating to the merged version. It should be related to bitsandbytes quantization, as mentioned in #863.

Environment

  • Unsloth version: 2025.7.3
  • unsloth_zoo version: 2025.7.4
  • TRL version: 0.19.1
  • Transformers version: 4.53.1
  • PyTorch version: 2.7.1
  • bitsandbytes version: 0.46.1
  • peft: 0.16.0
  • Python version: 3.11
  • Operating System: Linux
  • GPU: CUDA-enabled
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 1
----> 1 trainer.train()

File ~/GRPO-Unsloth-Finetuning/GRPO-Qwen-Finetuning-Unsloth/grpo_qwen.py:399, in GRPOModelTrainer.train(self)
    385         trainer = GRPOTrainer(
    386                     model=self.model,
    387                     processing_class=self.tokenizer,
   (...)    396             train_dataset=dataset,
    397 )
    398         logger.info("Beginning GRPO training...")
--> 399         trainer.train()
    400         logger.info("Training completed!")

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/transformers/trainer.py:2206, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
   2204         hf_hub_utils.enable_progress_bars()
   2205 else:
-> 2206     return inner_training_loop(
   2207         args=args,
   2208         resume_from_checkpoint=resume_from_checkpoint,
   2209         trial=trial,
   2210         ignore_keys_for_eval=ignore_keys_for_eval,
   2211     )

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

File <string>:34, in _unsloth_training_step(self, model, inputs, num_items_in_batch)

File ~/GRPO-Unsloth-Finetuning/GRPO-Qwen-Finetuning-Unsloth/unsloth_compiled_cache/UnslothGRPOTrainer.py:2046, in _UnslothGRPOTrainer.compute_loss(self, model, inputs, return_outputs, num_items_in_batch)
   2044 else:
   2045     if hasattr(self.args, "loss_type"):
-> 2046         loss, completion_length, mean_kl = grpo_accumulated_loss(
   2047             trainer = self,
   2048             input_ids = _input_ids,
   2049             logits_to_keep = logits_to_keep,
   2050             completion_mask = completion_mask,
   2051             advantages = advantages,
   2052             old_hidden_states = old_hidden_states,
   2053             n_chunks = self.args.unsloth_num_chunks,
   2054             loss_type = self.args.loss_type,
   2055             epsilon_low = self.epsilon_low,
   2056             epsilon_high = self.epsilon_high,
   2057             max_completion_length = self.args.max_completion_length,
   2058             delta = self.args.delta,
   2059             temperature = self.args.temperature,
   2060             logit_softcapping = logit_softcapping,
   2061             logit_scale_multiply = logit_scale_multiply,
   2062             logit_scale_divide = logit_scale_divide,
   2063             attention_mask = attention_mask,
   2064         )
   2065     else:
   2066         # to ensure backwards compatibility with trl 0.15.2 and maybe even 0.17
   2067         loss, completion_length, mean_kl = grpo_accumulated_loss(
   2068             trainer = self,
   2069             input_ids = _input_ids,
   (...)   2079             attention_mask = attention_mask,
   2080         )

File ~/GRPO-Unsloth-Finetuning/GRPO-Qwen-Finetuning-Unsloth/unsloth_compiled_cache/UnslothGRPOTrainer.py:313, in grpo_accumulated_loss(trainer, input_ids, attention_mask, logits_to_keep, completion_mask, advantages, old_hidden_states, n_chunks, **kwargs)
    311 with torch.amp.autocast(device_type = trainer.model.device.type, dtype = trainer._autocast_dtype):
    312     with torch.inference_mode(), trainer.accelerator.unwrap_model(trainer.model, keep_fp32_wrapper = False).disable_adapter():
--> 313         ref_hidden_states = trainer.model(
    314             input_ids = input_ids,
    315             attention_mask = attention_mask,
    316             logits_to_keep = logits_to_keep + 1,
    317         ).logits
    318     pass
    319     new_hidden_states = trainer.model(
    320         input_ids = input_ids,
    321         attention_mask = attention_mask,
    322         logits_to_keep = logits_to_keep + 1,
    323     ).logits

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/models/llama.py:1316, in PeftModel_fast_forward(self, input_ids, causal_mask, attention_mask, inputs_embeds, labels, output_attentions, output_hidden_states, return_dict, task_ids, num_logits_to_keep, logits_to_keep, **kwargs)
   1305     return self.base_model(
   1306         input_ids = input_ids,
   1307         attention_mask = attention_mask,
   (...)   1313         **kwargs,
   1314     )
   1315 else:
-> 1316     return self.base_model(
   1317         input_ids = input_ids,
   1318         causal_mask = causal_mask,
   1319         attention_mask = attention_mask,
   1320         inputs_embeds = inputs_embeds,
   1321         labels = labels,
   1322         output_attentions = output_attentions,
   1323         output_hidden_states = output_hidden_states,
   1324         return_dict = return_dict,
   1325         num_logits_to_keep = num_logits_to_keep,
   1326         logits_to_keep = logits_to_keep,
   1327         **kwargs,
   1328     )

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/peft/tuners/tuners_utils.py:216, in BaseTuner.forward(self, *args, **kwargs)
    215 def forward(self, *args: Any, **kwargs: Any):
--> 216     return self.model.forward(*args, **kwargs)

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/models/llama.py:1140, in CausalLM_fast_forward.<locals>._CausalLM_fast_forward(self, input_ids, causal_mask, attention_mask, position_ids, past_key_values, inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, return_dict, num_logits_to_keep, logits_to_keep, *args, **kwargs)
   1138     # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
   1139     self.model._has_no_labels = labels is None
-> 1140     outputs = self.model(
   1141         input_ids = input_ids,
   1142         causal_mask = causal_mask,
   1143         attention_mask = attention_mask,
   1144         position_ids = position_ids,
   1145         past_key_values = past_key_values,
   1146         inputs_embeds = inputs_embeds,
   1147         use_cache = use_cache,
   1148         output_attentions = output_attentions,
   1149         output_hidden_states = output_hidden_states,
   1150         return_dict = return_dict,
   1151     )
   1152 pass
   1153 hidden_states = outputs[0]

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/models/llama.py:952, in LlamaModel_fast_forward(self, input_ids, causal_mask, attention_mask, position_ids, past_key_values, inputs_embeds, use_cache, output_attentions, output_hidden_states, return_dict, *args, **kwargs)
    949     hidden_states = layer_outputs[0]
    951 else:
--> 952     layer_outputs = decoder_layer(
    953         hidden_states,
    954         causal_mask=mask,
    955         attention_mask      = attention_mask,
    956         position_ids        = position_ids,
    957         past_key_value      = past_key_value,
    958         output_attentions   = output_attentions,
    959         use_cache           = use_cache,
    960         padding_mask        = padding_mask,
    961         position_embeddings = position_embeddings,
    962     )
    963     hidden_states = layer_outputs[0]
    964 pass

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/transformers/modeling_layers.py:82, in GradientCheckpointingLayer.__call__(self, *args, **kwargs)
     79         message = message.rstrip(",") + "."
     80         logger.warning(message)
---> 82     return self._gradient_checkpointing_func(partial(super().__call__, **kwargs), *args)
     83 return super().__call__(*args, **kwargs)

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/torch/_compile.py:51, in _disable_dynamo.<locals>.inner(*args, **kwargs)
     48     disable_fn = torch._dynamo.disable(fn, recursive)
     49     fn.__dynamo_disable = disable_fn  # type: ignore[attr-defined]
---> 51 return disable_fn(*args, **kwargs)

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/torch/utils/checkpoint.py:488, in checkpoint(function, use_reentrant, context_fn, determinism_check, debug, *args, **kwargs)
    483     if context_fn is not noop_context_fn or debug is not False:
    484         raise ValueError(
    485             "Passing `context_fn` or `debug` is only supported when "
    486             "use_reentrant=False."
    487         )
--> 488     return CheckpointFunction.apply(function, preserve, *args)
    489 else:
    490     gen = _checkpoint_without_reentrant_generator(
    491         function, preserve, context_fn, determinism_check, debug, *args, **kwargs
    492     )

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth_zoo/gradient_checkpointing.py:475, in UnslothCheckpointFunction.forward(ctx, run_function, preserve_rng_state, *args)
    472 if ctx._requires_gradient: ctx.save_for_backward(*tensor_inputs)
    474 with torch.no_grad():
--> 475     outputs = run_function(*args)
    477 if use_gpu_buffer: MAIN_STREAM.wait_stream(EXTRA_STREAM)
    478 return outputs

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/models/llama.py:625, in LlamaDecoderLayer_fast_forward(self, hidden_states, causal_mask, attention_mask, position_ids, past_key_value, output_attentions, use_cache, padding_mask, position_embeddings, *args, **kwargs)
    623 residual = hidden_states
    624 hidden_states = fast_rms_layernorm(self.input_layernorm, hidden_states)
--> 625 hidden_states, self_attn_weights, present_key_value = self.self_attn(
    626     hidden_states       = hidden_states,
    627     causal_mask         = causal_mask,
    628     attention_mask      = attention_mask,
    629     position_ids        = position_ids,
    630     past_key_value      = past_key_value,
    631     output_attentions   = output_attentions,
    632     use_cache           = use_cache,
    633     padding_mask        = padding_mask,
    634     position_embeddings = position_embeddings,
    635 )
    636 hidden_states = residual + hidden_states
    638 # Fully Connected

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/models/llama.py:568, in LlamaAttention_fast_forward(self, hidden_states, causal_mask, attention_mask, position_ids, past_key_value, output_attentions, use_cache, padding_mask, position_embeddings, *args, **kwargs)
    566 pass
    567 attn_output = A.reshape(bsz, q_len, n_heads*head_dim)
--> 568 attn_output = self.apply_o(self, attn_output)
    569 attn_weights = None
    570 return attn_output, attn_weights, past_key_value

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/kernels/fast_lora.py:457, in apply_lora_o(self, X)
    455 def apply_lora_o(self, X):
    456     OW, OW_quant, OA, OB, OS = get_lora_parameters(self.o_proj)
--> 457     O = LoRA_W.apply(X, OW, OW_quant, OA, OB, OS)
    458     return O

File ~/.conda/envs/behrooz/lib/python3.11/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 ~/.conda/envs/behrooz/lib/python3.11/site-packages/torch/amp/autocast_mode.py:510, in custom_fwd.<locals>.decorate_fwd(*args, **kwargs)
    508 if cast_inputs is None:
    509     args[0]._fwd_used_autocast = torch.is_autocast_enabled(device_type)
--> 510     return fwd(*args, **kwargs)
    511 else:
    512     autocast_context = torch.is_autocast_enabled(device_type)

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/kernels/fast_lora.py:408, in LoRA_W.forward(ctx, X, W, W_quant, A, B, S)
    403 @staticmethod
    404 @torch_amp_custom_fwd
    405 def forward(ctx, X : torch.Tensor,
    406             W, W_quant, A, B, S):
    407     dtype = X.dtype
--> 408     XW = matmul_lora(X, W, W_quant, A, B, S)
    409     ctx.custom_saved_tensors = (W, W_quant, S,)
    410     ctx.save_for_backward(A, B, X)

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/kernels/utils.py:694, in matmul_lora(X, W, W_quant, A, B, s, out)
    692 def matmul_lora(X, W, W_quant, A, B, s, out = None):
    693     dtype = X.dtype
--> 694     W = fast_dequantize(W.t(), W_quant, use_global_buffer = True)
    696     if X.dim() == 3:
    697         batch, seq_len, d = X.shape

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/torch/utils/_contextlib.py:116, in context_decorator.<locals>.decorate_context(*args, **kwargs)
    113 @functools.wraps(func)
    114 def decorate_context(*args, **kwargs):
    115     with ctx_factory():
--> 116         return func(*args, **kwargs)

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/unsloth/kernels/utils.py:322, in fast_dequantize(W, quant_state, out, use_global_buffer)
    320 offset     = quant_state.offset
    321 state2     = quant_state.state2
--> 322 absmax2    = state2.absmax
    323 code2      = state2.code
    324 blocksize2 = state2.blocksize

AttributeError: 'NoneType' object has no attribute 'absmax'

@behroozazarkhalili @darshanmakwana412 @simonusher

we just made a new release that should solve this problem for you. If you’re running the code on a local vm, make sure to upgrade your install of unsloth via

pip install --force-reinstall --upgrade unsloth-zoo
pip install --force-reinstall --upgrade unsloth

On the other hand, If you’re running the notebooks on colab no need to do introduce any changes to the install cells as the notebook will grab the newest version from pypi for you anyway.

Make sure to leave a comment if this doesn’t work out for you with the necessary details and code snippets that would allow us to reproduce the errors you’re observing and we’ll take it from there.