Repository navigation
Description
我在使用unsloth训练Qwen3-30B-A3B-bnb-4bit模型,前面都一切正常,最后导出gguf时出现下面错误,我也有先使用model.save_pretrained_merged("/root/autodl-tmp/merged_model_4bit", tokenizer, save_method = "merged_4bit_forced",)先保存,在用llama.cpp转换,但一样是这个错误。
Unsloth GGUF:hf-to-gguf:Loading model: Qwen3-30B-A3B-bnb-4bit
Unsloth GGUF:hf-to-gguf:Model architecture: Qwen3MoeForCausalLM
Unsloth GGUF:gguf.gguf_writer:gguf: This GGUF file is for Little Endian only
Unsloth GGUF:hf-to-gguf:Exporting model...
Unsloth GGUF:hf-to-gguf:gguf: loading model weight map from 'model.safetensors.index.json'
Unsloth GGUF:hf-to-gguf:gguf: loading model part 'model-00001-of-00004.safetensors'
Unsloth GGUF:hf-to-gguf:token_embd.weight, torch.bfloat16 --> Q8_0, shape = {2048, 151936}
Traceback (most recent call last):
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 6512, in
main()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 6506, in main
model_instance.write()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 677, in write
self.prepare_tensors()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 3178, in prepare_tensors
super().prepare_tensors()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 549, in prepare_tensors
for new_name, data_torch in (self.modify_tensors(data_torch, name, bid)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 3161, in modify_tensors
datas.append(self._experts[bid][ename])
~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'model.layers.0.mlp.experts.2.down_proj.weight'
Unsloth GGUF:hf-to-gguf:Loading model: Qwen3-30B-A3B-bnb-4bit
Unsloth GGUF:hf-to-gguf:Model architecture: Qwen3MoeForCausalLM
Unsloth GGUF:gguf.gguf_writer:gguf: This GGUF file is for Little Endian only
Unsloth GGUF:hf-to-gguf:Exporting model...
Unsloth GGUF:hf-to-gguf:gguf: loading model weight map from 'model.safetensors.index.json'
Unsloth GGUF:hf-to-gguf:gguf: loading model part 'model-00001-of-00004.safetensors'
Unsloth GGUF:hf-to-gguf:token_embd.weight, torch.bfloat16 --> Q8_0, shape = {2048, 151936}
Traceback (most recent call last):
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 6512, in
main()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 6506, in main
model_instance.write()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 677, in write
self.prepare_tensors()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 3178, in prepare_tensors
super().prepare_tensors()
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 549, in prepare_tensors
for new_name, data_torch in (self.modify_tensors(data_torch, name, bid)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/llama.cpp/unsloth_convert_hf_to_gguf.py", line 3161, in modify_tensors
datas.append(self._experts[bid][ename])
~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'model.layers.0.mlp.experts.2.down_proj.weight'
RuntimeError Traceback (most recent call last)
Cell In[20], line 1
----> 1 if True: model.save_pretrained_gguf("/root/autodl-tmp/Qwen3-30B-A3B-bnb-4bit", quantization_type="q8_0")
File ~/miniconda3/envs/llama-factory/lib/python3.10/site-packages/torch/utils/_contextlib.py:116, in context_decorator..decorate_context(*args, **kwargs)
113 @functools.wraps(func)
114 def decorate_context(*args, **kwargs):
115 with ctx_factory():
--> 116 return func(*args, **kwargs)
File ~/miniconda3/envs/llama-factory/lib/python3.10/site-packages/unsloth/save.py:2247, in save_to_gguf_generic(model, save_directory, quantization_type, repo_id, token)
2244 install_llama_cpp(just_clone_repo = True)
2245 pass
-> 2247 metadata = _convert_to_gguf(
2248 save_directory,
2249 print_output = True,
2250 quantization_type = quantization_type,
2251 )
2252 if repo_id is not None:
2253 prepare_saving(
2254 model,
2255 repo_id,
(...)
2259 token = token,
2260 )
File ~/miniconda3/envs/llama-factory/lib/python3.10/site-packages/unsloth_zoo/llama_cpp.py:692, in convert_to_gguf(input_folder, output_filename, quantization_type, max_shard_size, print_output, print_outputs)
689 pass
691 if metadata is None:
--> 692 raise RuntimeError(f"Unsloth: Failed to convert {conversion_filename} to GGUF.")
694 printed_metadata = "\n".join(metadata)
695 if print_output: print(f"Unsloth: Successfully saved GGUF to:\n{printed_metadata}")
RuntimeError: Unsloth: Failed to convert llama.cpp/unsloth_convert_hf_to_gguf.py to GGUF.
Activity
github-actions commentedon Jul 1, 2025
Is this issue still important to you? Apologies in advance we might have missed this issue as well. For faster response times, please post on our Reddit server - https://www.reddit.com/r/unsloth or our Discord - https://discord.com/invite/unsloth
rolandtannous commentedon Oct 15, 2025
@ZGuangJie
We just pushed a major fix for llamacpp integration.
1- Please make sure to update your local install of unsloth
If you're using a notebook on kaggle or colab, it should pull the latest version automatically.
2- You can now use
save_pretrained_ggufto quantize and save to GGUF format:For vision/multimodal models, use
tokenizer=processor3- You can pass it one or several quant methods (as a list):
or
We support all the quants mentioned in this page except the iq variants.
4- If the model is supported by Ollama, it will now also automatically create a
Modelfilefor you that you can use to create your model in ollama using:5- Use
push_to_hub_ggufif you want to convert to gguf and push to Huggingface Hub instead.6- Should work for all models supported by unsloth and ollama.
7- It now fully supports linux debian and RPM variants. We are still testing windows (if someone has a windows machine and is on our discord channel ping me to help debug)
Let me know if it works for you.
Thanks!
rolandtannous commentedon Oct 23, 2025
Will be closing this for now as the issue has been resolved. Please make sure to follow the instructions given in my last response.
Meanwhile , please feel free to respond if you're still having any issues.
Thank you