Skip to content

Error saving GGUF of Gemma27B (but not Gemma4B) on DGX Spark #3581

Closed
unslothai/unsloth-zoo
#1236

Description

@weoieoeo

After successful vision finetuning of vision model Gemma27B (4bit) I run into this error. The process utilizes only approximately 65 GB of the available 128 GB of unified RAM. This error does not occur when I finetune the smaller Gemma4B (4bit) with the same vision dataset.

I am grateful for any advice

{'loss': 0.0248, 'grad_norm': 0.3881801664829254, 'learning_rate': 8.695652173913045e-09, 'epoch': 20.0}
{'train_runtime': 196532.9404, 'train_samples_per_second': 0.192, 'train_steps_per_second': 0.006, 'train_loss': 0.07668430322393154, 'epoch': 20.0}
100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 1200/1200 [54:35:32<00:00, 163.78s/it]
Unsloth: ##### The current model auto adds a BOS token.
Unsloth: ##### Your chat template has a BOS token. We shall remove it temporarily.
Unsloth: Merging model weights to 16-bit format...
Detected local model directory: /workspace/AIEngine/medgemma-27b-it
Copied tokenizer.model from local model directory
Found HuggingFace hub cache directory: /root/.cache/huggingface/hub
Unsloth: Preparing safetensor model files: 0%| | 0/12 [00:00<?, ?it/s]Copied model-00003-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 8%|█████▍ | 1/12 [00:02<00:22, 2.02s/it]Copied model-00006-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 17%|██████████▊ | 2/12 [00:04<00:25, 2.52s/it]Copied model-00012-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 25%|████████████████▎ | 3/12 [00:05<00:13, 1.45s/it]Copied model-00009-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 33%|█████████████████████▋ | 4/12 [00:06<00:12, 1.62s/it]Copied model-00002-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 42%|███████████████████████████ | 5/12 [00:08<00:12, 1.76s/it]Copied model-00007-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 50%|████████████████████████████████▌ | 6/12 [00:10<00:10, 1.82s/it]Copied model-00010-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 58%|█████████████████████████████████████▉ | 7/12 [00:13<00:09, 1.96s/it]Copied model-00008-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 67%|███████████████████████████████████████████▎ | 8/12 [00:15<00:08, 2.00s/it]Copied model-00004-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 75%|████████████████████████████████████████████████▊ | 9/12 [00:17<00:06, 2.00s/it]Copied model-00001-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 83%|█████████████████████████████████████████████████████▎ | 10/12 [00:21<00:05, 2.60s/it]Copied model-00011-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 92%|██████████████████████████████████████████████████████████▋ | 11/12 [00:23<00:02, 2.45s/it]Copied model-00005-of-00012.safetensors from local model directory
Unsloth: Preparing safetensor model files: 100%|████████████████████████████████████████████████████████████████| 12/12 [00:25<00:00, 2.10s/it]
Unsloth: Merging weights into 16bit: 100%|██████████████████████████████████████████████████████████████████████| 12/12 [07:34<00:00, 37.89s/it]
Unsloth: Merge process complete. Saved to /home/ollam3/unsloth_finetune
Unsloth: Converting to GGUF format...
==((====))== Unsloth: Conversion from HF to GGUF information
\ /| [0] Installing llama.cpp might take 3 minutes.
O^O/ _/ \ [1] Converting HF to GGUF bf16 might take 3 minutes.
\ / [2] Converting GGUF bf16 to ['q4_k_m'] might take 10 minutes each.
"-____-" In total, you will have to wait at least 16 minutes.

Unsloth: llama.cpp found in the system. Skipping installation.
Unsloth: Preparing converter script...
Unsloth: [1] Converting model into bf16 GGUF format.
This might take 3 minutes...
Traceback (most recent call last):
File "/usr/local/lib/python3.12/dist-packages/unsloth_zoo/llama_cpp.py", line 991, in convert_to_gguf
subprocess.run(command, shell=True, check=True, capture_output=True)
File "/usr/lib/python3.12/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'python llama.cpp/unsloth_convert_hf_to_gguf.py --outfile medgemma-27b-it.BF16.gguf --outtype bf16 --split-max-size 50G unsloth_finetune' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.12/dist-packages/unsloth/save.py", line 1835, in unsloth_save_pretrained_gguf
all_file_locations, want_full_precision, is_vlm_update = save_to_gguf(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/unsloth/save.py", line 1099, in save_to_gguf
initial_files, is_vlm_update = convert_to_gguf(
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/unsloth_zoo/llama_cpp.py", line 995, in convert_to_gguf
raise RuntimeError(f"Unsloth: Failed to convert {description} to GGUF: {e}")
RuntimeError: Unsloth: Failed to convert text model to GGUF: Command 'python llama.cpp/unsloth_convert_hf_to_gguf.py --outfile medgemma-27b-it.BF16.gguf --outtype bf16 --split-max-size 50G unsloth_finetune' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ollam3/finetunevisionGemma3_Herz.py", line 217, in
model.save_pretrained_gguf("unsloth_finetune", tokenizer, quantization_method = "q4_k_m")
File "/usr/local/lib/python3.12/dist-packages/unsloth/save.py", line 1855, in unsloth_save_pretrained_gguf
raise RuntimeError(f"Unsloth: GGUF conversion failed: {e}")
RuntimeError: Unsloth: GGUF conversion failed: Unsloth: Failed to convert text model to GGUF: Command 'python llama.cpp/unsloth_convert_hf_to_gguf.py --outfile medgemma-27b-it.BF16.gguf --outtype bf16 --split-max-size 50G unsloth_finetune' returned non-zero exit status 1.

Activity

  1. mmathew23 commented on Nov 11, 2025

    @mmathew23
    Contributor

    @weoieoeo It's failing on the command python llama.cpp/unsloth_convert_hf_to_gguf.py --outfile medgemma-27b-it.BF16.gguf --outtype bf16 --split-max-size 50G unsloth_finetune. Can you try running that in the working directory of the train run and see what the error is?

  2. weoieoeo commented on Nov 12, 2025

    @weoieoeo
    Author

    I am not sure if I understand correctly. This is my local setup:

    root@a3e66db5040b:/home/ollam3# ls -list
    total 40
    53098059 4 drwxr-xr-x 26 root root 4096 Nov 11 15:58 llama.cpp
    61866156 4 drwxr-xr-x 2 root root 4096 Nov 11 15:51 unsloth_finetune
    61866144 4 drwxr-xr-x 2 root root 4096 Nov 11 15:51 MedGemma3-27b-4bit_Herz_11_11_2025
    61865989 4 drwxr-xr-x 4 root root 4096 Nov 11 15:38 unsloth_compiled_cache
    53098028 4 drwxr-xr-x 3 root root 4096 Nov 11 15:36 medgemma-27b-it
    53084194 8 -rw-r--r-- 1 root root 7785 Nov 11 15:34 finetunevisionGemma3_Herz.py
    53216791 4 drwxr-xr-x 3 root root 4096 Nov 11 12:17 medgemma-4b-it-unsloth-bnb-4bit
    53104292 4 drwxr-xr-x 7 root root 4096 Nov 11 11:54 outputs
    53084204 4 drwxr-xr-x 2 root root 4096 Nov 7 09:17 Final_visual_Dataset

    instead of this

    root@a3e66db5040b:/home/ollam3#python llama.cpp/unsloth_convert_hf_to_gguf.py --outfile medgemma-27b-it.BF16.gguf --outtype bf16 --split-max-size 50G unsloth_finetune

    you want this?

    root@a3e66db5040b:/home/ollam3# cp llama.cpp/unsloth_convert_hf_to_gguf.py ./

    root@a3e66db5040b:/home/ollam3# python unsloth_convert_hf_to_gguf.py --outfile medgemma-27b-it.BF16.gguf --outtype bf16 --split-max-size 50G unsloth_finetune
    Traceback (most recent call last):
    File "/home/ollam3/unsloth_convert_hf_to_gguf.py", line 312, in
    from gguf.vocab import MistralTokenizerType, MistralVocab
    ImportError: cannot import name 'MistralTokenizerType' from 'gguf.vocab' (/usr/local/lib/python3.12/dist-packages/gguf/vocab.py)

    or do you want this?

    root@a3e66db5040b:/home/ollam3# python llama.cpp/unsloth_convert_hf_to_gguf.py --outfile medgemma-27b-it.BF16.gguf --outtype bf16 --split-max-size 50G unsloth_finetune
    INFO:hf-to-gguf:Loading model: unsloth_finetune
    INFO:hf-to-gguf:Model architecture: Gemma3ForConditionalGeneration
    INFO:hf-to-gguf:gguf: loading model weight map from 'model.safetensors.index.json'
    INFO:hf-to-gguf:gguf: indexing model part 'model-00001-of-00012.safetensors'
    Traceback (most recent call last):
    File "/home/ollam3/llama.cpp/unsloth_convert_hf_to_gguf.py", line 10639, in
    main()
    File "/home/ollam3/llama.cpp/unsloth_convert_hf_to_gguf.py", line 10616, in main
    model_instance = model_class(dir_model, output_type, fname_out,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/ollam3/llama.cpp/unsloth_convert_hf_to_gguf.py", line 1017, in init
    super().init(*args, **kwargs)
    File "/home/ollam3/llama.cpp/unsloth_convert_hf_to_gguf.py", line 420, in init
    self.model_tensors = self.index_tensors(remote_hf_model_id=remote_hf_model_id)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/ollam3/llama.cpp/unsloth_convert_hf_to_gguf.py", line 502, in index_tensors
    ctx = cast(ContextManager[Any], gguf.utility.SafetensorsLocal(self.dir_model / part_name))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AttributeError: module 'gguf.utility' has no attribute 'SafetensorsLocal'

  3. mmathew23 commented on Nov 12, 2025

    @mmathew23
    Contributor

    Hi @weoieoeo, most likely you have an older version of gguf installed. Could you try to remove the local llama.cpp folder, remove ggug pip uninstall -y gguf, and rerun the script for gemma 27b? it should install setup llama.cpp locally again.

  4. added
    fixed - pending confirmation
    on Nov 12, 2025
  5. weoieoeo commented on Nov 13, 2025

    @weoieoeo
    Author

    Hi mmathew23! I have gguf 0.17.1 installed, which seems to be the most recent version. However I followed your advice and uninstalled gguf and removed the llama.cpp folder. Unfortunately, or as expected, the local rebuild of llama.cpp does not work. Which might be related to the fact, that I am working in a docker container on the DGX Spark.

    Detected local model directory: /home/ollam3/medgemma-27b-it
    Copied tokenizer.model from local model directory
    Found HuggingFace hub cache directory: /root/.cache/huggingface/hub
    Unsloth: Preparing safetensor model files: 100%|█████████████████████████████████| 12/12 [00:00<00:00, 90851.35it/s]
    Unsloth: Merging weights into 16bit: 100%|██████████████████████████████████████████| 12/12 [09:00<00:00, 45.05s/it]
    Unsloth: Merge process complete. Saved to /home/ollam3/unsloth_finetune
    Unsloth: Converting to GGUF format...
    ==((====))== Unsloth: Conversion from HF to GGUF information
    \ /| [0] Installing llama.cpp might take 3 minutes.
    O^O/ _/ \ [1] Converting HF to GGUF bf16 might take 3 minutes.
    \ / [2] Converting GGUF bf16 to ['q4_k_m'] might take 10 minutes each.
    "-____-" In total, you will have to wait at least 16 minutes.

    Unsloth: Installing llama.cpp. This might take 3 minutes...
    Unsloth: Updating system package directories
    Unsloth: All required system packages already installed!
    Unsloth: Install llama.cpp and building - please wait 1 to 3 minutes
    Unsloth: Cloning llama.cpp repository
    Unsloth: Install GGUF and other packages
    Traceback (most recent call last):
    File "/usr/local/lib/python3.12/dist-packages/unsloth/save.py", line 1074, in save_to_gguf
    quantizer_location, converter_location = check_llama_cpp()
    ^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/dist-packages/unsloth_zoo/llama_cpp.py", line 316, in check_llama_cpp
    raise RuntimeError(f"llama.cpp folder '{llama_cpp_folder}' does not exist")
    RuntimeError: llama.cpp folder 'llama.cpp' does not exist

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/usr/local/lib/python3.12/dist-packages/unsloth/save.py", line 1835, in unsloth_save_pretrained_gguf
    all_file_locations, want_full_precision, is_vlm_update = save_to_gguf(
    ^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/dist-packages/unsloth/save.py", line 1085, in save_to_gguf
    quantizer_location, converter_location = install_llama_cpp(
    ^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/dist-packages/unsloth_zoo/llama_cpp.py", line 415, in install_llama_cpp
    try_execute(f"{pip} install gguf protobuf sentencepiece mistral_common", **kwargs)
    File "/usr/local/lib/python3.12/dist-packages/unsloth_zoo/llama_cpp.py", line 275, in try_execute
    raise RuntimeError(error_msg)
    RuntimeError: [FAIL] Command uv pip install gguf protobuf sentencepiece mistral_common failed with exit code 2
    stdout: error: No virtual environment found; run uv venv to create an environment, or pass --system to install into a non-virtual environment

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/ollam3/finetunevisionGemma3_Herz.py", line 217, in
    model.save_pretrained_gguf("unsloth_finetune", tokenizer, quantization_method = "q4_k_m")
    File "/usr/local/lib/python3.12/dist-packages/unsloth/save.py", line 1855, in unsloth_save_pretrained_gguf
    raise RuntimeError(f"Unsloth: GGUF conversion failed: {e}")
    RuntimeError: Unsloth: GGUF conversion failed: [FAIL] Command uv pip install gguf protobuf sentencepiece mistral_common failed with exit code 2
    stdout: error: No virtual environment found; run uv venv to create an environment, or pass --system to install into a non-virtual environment

    I previously reported this problem but didn't look into it further, as it was solved by manually building llama.cpp inside the Docker image and copying the resulting files into the correct working directory inside the Docker image

    (https://github.com/unslothai/unsloth/issues/3561)

  6. removed
    fixed - pending confirmation
    on Nov 13, 2025
  7. mmathew23 commented on Nov 17, 2025

    @mmathew23
    Contributor

    Looping in @rolandtannous. Any thoughts here?

  8. fish4terrisa-MSDSM commented on Feb 20, 2026

    @fish4terrisa-MSDSM

    Use the gguf-py shipped with llama.cpp
    llama.cpp/gguf-py
    simply run pip install -e . in the directory
    The python-gguf package in AUR is broken(or at least conflicting with llama.cpp)
    I might add another package(maybe python-llama.cpp-gguf is a good name) to AUR and provide python-gguf later

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions