Skip to content

[Bug] AttributeError: 'Mistral3ForConditionalGeneration' object has no attribute 'model' #2415

Closed

Description

@ispb88

Trained a lora on with unsloth on https://huggingface.co/unsloth/Mistral-Small-3.1-24B-Base-2503-unsloth-bnb-4bit

Trying to merge it and I get this:

🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
Unsloth: Failed to patch SmolVLMForConditionalGeneration forward function.
WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:
    PyTorch 2.5.1 with CUDA 1201 (you have 2.7.0+cu126)
    Python  3.11.10 (you have 3.11.11)
  Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers)
  Memory-efficient attention, SwiGLU, sparse and more won't be available.
  Set XFORMERS_MORE_DETAILS=1 for more details
🦥 Unsloth Zoo will now patch everything to make training faster!
==((====))==  Unsloth 2025.4.1: Fast Mistral patching. Transformers: 4.51.3.
   \\   /|    NVIDIA A100-SXM4-80GB. Num GPUs = 1. Max memory: 79.254 GB. Platform: Linux.
O^O/ \_/ \    Torch: 2.7.0+cu126. CUDA: 8.0. CUDA Toolkit: 12.6. Triton: 3.3.0
\        /    Bfloat16 = TRUE. FA [Xformers = None. FA2 = False]
 "-____-"     Free license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!
Unsloth: Mistral does not support SDPA - switching to eager!
Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:02<00:00,  1.49it/s]
Traceback (most recent call last):
  File "/workspace/merge.py", line 8, in <module>
    model.save_pretrained_merged("/workspace/merged/" + c, tokenizer, save_method = "merged_16bit")
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/unsloth/save.py", line 2369, in unsloth_generic_save_pretrained_merged
    unsloth_generic_save(**arguments)
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/unsloth/save.py", line 2315, in unsloth_generic_save
    merge_and_overwrite_lora(
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/unsloth_zoo/saving_utils.py", line 584, in merge_and_overwrite_lora
    ) = prepare_saving(
        ^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/unsloth_zoo/saving_utils.py", line 437, in prepare_saving
    lora_weights, state_dict = create_lora_statistics(
                               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/unsloth_zoo/saving_utils.py", line 249, in create_lora_statistics
    inner_model = model.base_model.model if hasattr(model, "base_model") else model
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/unsloth_env/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1940, in __getattr__
    raise AttributeError(
AttributeError: 'Mistral3ForConditionalGeneration' object has no attribute 'model'

My merging code:


for c in ["113", "226", "339", "452", "565", "678"]:
    model, tokenizer = FastLanguageModel.from_pretrained(
        model_name = "/workspace/outputs/checkpoint-" + c,
        load_in_4bit = True,
    )
    model.save_pretrained_merged("/workspace/merged/" + c, tokenizer, save_method = "merged_16bit")

When I try to save as GGUF, I have this issue: #2209

Activity

  1. ispb88 commented on Apr 26, 2025

    @ispb88
    Author

    Using FastModel instead of FastLanguageModel seems to fix, closing. Linked GGUF issue persists however.

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