Skip to content

[Bug] Issues with loading and finetuning GLM 4.5 models #3284

Closed

Description

@Ammar-Alnagar
  1. Did you update? pip install --upgrade unsloth unsloth_zoo
    Yes

  2. Colab or Kaggle or local / cloud

Cloud / Local

  1. Number GPUs used, use nvidia-smi
    1

  2. Which notebook? Please link!
    Custom (basically modified this https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_(14B)-Reasoning-Conversational.ipynb)

  3. Which Unsloth version, TRL version, transformers version, PyTorch version?
    Transformers: 4.56.1
    TRL:0.22.2
    Torch 2.8

  4. Which trainer? SFTTrainer, GRPOTrainer etc
    SFTTrainer

model, tokenizer = FastLanguageModel.from_pretrained(
         model_name="unsloth/GLM-4.5-Air",
        max_seq_length=max_seq_length,
        load_in_4bit=load_in_4bit,
        dtype=dtype,
        # trust_remote_code=True,

    )

Log.txt

for extra context this is the log i get , i tried both unsloth and zai versions and updated unsloth and unsloth zoo
🦥 You can also ask via our Reddit page: https://www.reddit.com/r/unsloth/

Activity

  1. changed the title [-][Bug] Please fill in your issue title here.[/-] [+][Bug] Issues with loading and finetuning GLM 4.5 models[/+] on Sep 8, 2025
  2. rjarun8235 commented on Sep 8, 2025

    @rjarun8235

    HI @Ammar-Alnagar ,
    The model download fails even with direct download

    from transformers import AutoTokenizer, AutoModelForCausalLM
    
    tokenizer = AutoTokenizer.from_pretrained("unsloth/GLM-4.5-Air")
    model = AutoModelForCausalLM.from_pretrained("unsloth/GLM-4.5-Air")
    messages = [
        {"role": "user", "content": "Who are you?"},
    ]
    inputs = tokenizer.apply_chat_template(
    	messages,
    	add_generation_prompt=True,
    	tokenize=True,
    	return_dict=True,
    	return_tensors="pt",
    ).to(model.device)
    
    outputs = model.generate(**inputs, max_new_tokens=40)
    print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
    

    My guess, the config.json has "num_hidden_layers": 46, and the logs show error with ['model.layers.46.eh_proj.weight', 'model.layers.46.embed_tokens.weight' - this layer is 47th - hence the conflict in resolving I believe

  3. Ammar-Alnagar commented on Sep 9, 2025

    @Ammar-Alnagar
    Author

    I just checked the config.json :

    {
      "architectures": [
        "Glm4MoeForCausalLM"
      ],
      "attention_bias": true,
      "attention_dropout": 0.0,
      "pad_token_id": 151329,
      "eos_token_id": [
        151329,
        151336,
        151338
      ],
      "head_dim": 128,
      "hidden_act": "silu",
      "hidden_size": 4096,
      "partial_rotary_factor": 0.5,
      "initializer_range": 0.02,
      "intermediate_size": 10944,
      "max_position_embeddings": 131072,
      "model_type": "glm4_moe",
      "moe_intermediate_size": 1408,
      "norm_topk_prob": true,
      "num_attention_heads": 96,
      "n_group": 1,
      "topk_group": 1,
      "n_routed_experts": 128,
      "n_shared_experts": 1,
      "routed_scaling_factor": 1.0,
      "num_experts_per_tok": 8,
      "first_k_dense_replace": 1,
      "num_hidden_layers": 46,
      "num_key_value_heads": 8,
      "rms_norm_eps": 1e-05,
      "rope_scaling": null,
      "rope_theta": 1000000,
      "num_nextn_predict_layers": 1,
      "tie_word_embeddings": false,
      "torch_dtype": "bfloat16",
      "transformers_version": "4.54.0",
      "use_cache": true,
      "use_qk_norm": false,
      "vocab_size": 151552
    }
    

    I tried reinstalling and installing unsloth and unsloth zoo but still the same issue is happening for some reason.
    I am at a complete loss

  4. rjarun8235 commented on Sep 10, 2025

    @rjarun8235

    i just check the config.json :

    {
      "architectures": [
        "Glm4MoeForCausalLM"
      ],
      "attention_bias": true,
      "attention_dropout": 0.0,
      "pad_token_id": 151329,
      "eos_token_id": [
        151329,
        151336,
        151338
      ],
      "head_dim": 128,
      "hidden_act": "silu",
      "hidden_size": 4096,
      "partial_rotary_factor": 0.5,
      "initializer_range": 0.02,
      "intermediate_size": 10944,
      "max_position_embeddings": 131072,
      "model_type": "glm4_moe",
      "moe_intermediate_size": 1408,
      "norm_topk_prob": true,
      "num_attention_heads": 96,
      "n_group": 1,
      "topk_group": 1,
      "n_routed_experts": 128,
      "n_shared_experts": 1,
      "routed_scaling_factor": 1.0,
      "num_experts_per_tok": 8,
      "first_k_dense_replace": 1,
      "num_hidden_layers": 46,
      "num_key_value_heads": 8,
      "rms_norm_eps": 1e-05,
      "rope_scaling": null,
      "rope_theta": 1000000,
      "num_nextn_predict_layers": 1,
      "tie_word_embeddings": false,
      "torch_dtype": "bfloat16",
      "transformers_version": "4.54.0",
      "use_cache": true,
      "use_qk_norm": false,
      "vocab_size": 151552
    }
    

    i tried reinstalling and installing unsloth and unsloth zoo but still the same issue is happening for some reason. i am at a complete loss

    Since this model is throwing the same error with the transformers library too, it has to be fixed in the source @Ammar-Alnagar

  5. shimmyshimmer commented on Sep 18, 2025

    @shimmyshimmer
    Member

    i just check the config.json :

    {
      "architectures": [
        "Glm4MoeForCausalLM"
      ],
      "attention_bias": true,
      "attention_dropout": 0.0,
      "pad_token_id": 151329,
      "eos_token_id": [
        151329,
        151336,
        151338
      ],
      "head_dim": 128,
      "hidden_act": "silu",
      "hidden_size": 4096,
      "partial_rotary_factor": 0.5,
      "initializer_range": 0.02,
      "intermediate_size": 10944,
      "max_position_embeddings": 131072,
      "model_type": "glm4_moe",
      "moe_intermediate_size": 1408,
      "norm_topk_prob": true,
      "num_attention_heads": 96,
      "n_group": 1,
      "topk_group": 1,
      "n_routed_experts": 128,
      "n_shared_experts": 1,
      "routed_scaling_factor": 1.0,
      "num_experts_per_tok": 8,
      "first_k_dense_replace": 1,
      "num_hidden_layers": 46,
      "num_key_value_heads": 8,
      "rms_norm_eps": 1e-05,
      "rope_scaling": null,
      "rope_theta": 1000000,
      "num_nextn_predict_layers": 1,
      "tie_word_embeddings": false,
      "torch_dtype": "bfloat16",
      "transformers_version": "4.54.0",
      "use_cache": true,
      "use_qk_norm": false,
      "vocab_size": 151552
    }
    

    i tried reinstalling and installing unsloth and unsloth zoo but still the same issue is happening for some reason. i am at a complete loss

    Since this model is throwing the same error with the transformers library too, it has to be fixed in the source @Ammar-Alnagar

    Thank you for investigating. So transformers does not work with the model either? Then unfortunately it won't work in unsloth until it works in transformers :(

  6. Ammar-Alnagar commented on Sep 18, 2025

    @Ammar-Alnagar
    Author

    @shimmyshimmer I have noticed many differences between the config files for the unsloth version and the Z.AI version , could this be the reason ?

    I can run the model normally with VLLM .

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