Skip to content

Export fine-tuned models to GGUF and deploy on Ollama

After training with Soup CLI, export your model to GGUF format and serve it locally with Ollama in three commands.

0. Build llama.cpp first, if you want a quantized GGUF

Soup auto-clones llama.cpp (pinned at tag b12423 since v0.78.0, b5270 before) into ~/.soup/llama.cpp on first use, but it does not build it. Converting to f16 or f32 works from the Python script alone. Every quantized type additionally needs the llama-quantize binary, so build it once:

bash
cd ~/.soup/llama.cpp
cmake -B build -DGGML_NATIVE=OFF -DLLAMA_CURL=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release --target llama-quantize -j 4

Soup finds the binary in both the single-config layout (build/bin/llama-quantize, from Make or Ninja) and the multi-config one (build/bin/Release/llama-quantize.exe, from MSVC or Xcode), or in an absolute PATH directory. Since v0.77.1 every program Soup runs from there is run by its absolute path, --llama-cpp . included; the current directory is not searched for it. To use a checkout you already have, pass --llama-cpp /path/to/llama.cpp or set LLAMA_CPP_PATH. An existing ~/.soup/llama.cpp is reused as it is: the pin is a tag, and moving it does not update a checkout that is already there. After upgrading from v0.77.2 or earlier, delete ~/.soup/llama.cpp to have the next export clone b12423, then build llama-quantize again. A GGUF written by the new converter can differ from one written with b5270 for the same model, so export again before you compare files.

On Windows the validated toolchain is Visual Studio 2022 Build Tools with the "Desktop development with C++" workload plus CMake 3.14 or newer, CPU-only. Linux and macOS need only a C++ toolchain and CMake. CUDA builds of llama.cpp are untested.

Warning:

Do not run pip install -r ~/.soup/llama.cpp/requirements.txt. It pins torch~=2.2.1 against the CPU wheel index, so it will downgrade a CUDA PyTorch and break training. Soup deliberately installs only the convert script's own extras (gguf, sentencepiece, protobuf), unpinned.

Two checks before the toolchain work (v0.77.0). A model whose architecture the pinned converter cannot convert is refused before anything is cloned or installed, with Select a compatible checkout with --llama-cpp <dir>. (exit 1). (Since closed in v0.78.0: through v0.77.2 the b5270 pin could not convert Qwen3.5, and moving the pin was open upstream, #1911. Upstream says Qwen3.5 passes this check on a fresh b12423 checkout; this site did not run an export or a clone, so that is upstream's statement.) A checkout passed with --llama-cpp must advertise --no-mtp for a merged model that declares MTP layers but saved no MTP tensors, which Soup then converts with that flag; upstream says the b12423 pin does. soup export --format gguf also needs transformers (from pip install "soup-cli[train]"), because the converter imports it: without it the command exits 1 before cloning, with The pinned llama.cpp converter requires transformers, which is not installed in this environment. And in an environment that manages its own packages, --no-install-deps makes Soup check gguf, sentencepiece and protobuf and refuse, naming the missing ones, instead of running pip. It does not stop the clone, so pair it with --llama-cpp or LLAMA_CPP_PATH. --verbose streams the converter's and quantizer's output as it runs. Both flags are for --format gguf only; see Model Export.

1. Export to GGUF

bash
soup export --model ./runs/my-model \
            --format gguf \
            --quant q4_k_m \
            --output ./my-model.gguf

Quantization levels:

QuantSize (7B)QualityUse case
q4_k_m~4.1 GBGoodDefault — best size/quality balance
q5_k_m~4.8 GBBetterWhen you need higher accuracy
q8_0~7.5 GBNear-losslessBenchmarks, eval
q4_0~3.8 GBLowerThe smallest rung --quant accepts
f16 / f32~14 GB / ~28 GBUnquantizedA conversion with no quantization step

--quant accepts exactly these six values (q4_0, q4_k_m, q5_k_m, q8_0, f16, f32) and exits 1 on anything else, so the smaller llama.cpp rungs like q2_k and q3_k_m are not reachable through Soup.

2. Deploy to Ollama

Soup CLI ships with Ollama integration (v0.18.0+):

bash
soup deploy ollama \
    --model ./my-model.gguf \
    --name my-model \
    --template chatml

This creates an Ollama Modelfile, imports the GGUF, and registers your model. Since v0.77.1 Soup runs ollama by the absolute path it finds in an absolute PATH directory, like the llama.cpp programs, so the Ollama command line has to be installed there. Since v0.77.2 a name or a --system prompt is shown as typed in the plan panel (#2404, by @Nari-Ab): on v0.77.1 a prompt that contained a closing tag such as the Llama-2 and Mistral chat marker [/INST] stopped soup deploy ollama with a MarkupError and exit 1 before the plan appeared.

3. Chat

bash
ollama run my-model

Or via the API:

bash
curl http://localhost:11434/api/generate -d '{
  "model": "my-model",
  "prompt": "Hello!"
}'

One-liner: train → export → deploy

bash
soup train --config soup.yaml && \
soup export --model ./output --format gguf --quant q4_k_m --output ./my-model.gguf && \
soup deploy ollama --model ./my-model.gguf --name my-model --yes

soup train writes to the config's output: directory (./output unless you set it), and there is no latest subdirectory, so point --model at that directory. Without --output, soup export names the file <model-name>.<quant>.gguf and writes it next to the model directory (./output.q4_k_m.gguf), not inside it, so pass --output when a later command has to find the file. --yes skips the confirmation prompt of soup deploy ollama. In a script or CI job, pass --yes to soup train as well: since v0.77.0, with stdin piped or redirected and no --yes, it exits 3 instead of waiting for a confirmation nobody can give.

Running the llama.cpp programs with soup llama

soup llama <subcommand> [args...] starts one of five llama.cpp programs and forwards your arguments to it unchanged:

Soup commandProgram it starts
soup llama clillama-cli
soup llama mtmd-clillama-mtmd-cli
soup llama gguf-splitllama-gguf-split
soup llama serverllama-server
soup llama quantizellama-quantize
bash
soup llama quantize ./my-model.f16.gguf ./my-model.Q5_K_M.gguf Q5_K_M
soup llama server -m ./my-model.gguf --port 8080

The arguments are llama.cpp's own syntax, not Soup's, and they depend on the llama.cpp build you installed. A few things are Soup's:

  • The program must be in an absolute PATH directory. Since v0.77.1 it is looked up by name there and run by the absolute path found; the current directory and an empty or relative PATH entry (., bin) are not searched, so a binary that sits only in the folder you are in is not found (#2205). Setting LLAMA_CPP_HOME does not make Soup find it, and neither does the ~/.soup/llama.cpp/build/bin directory from step 0 above: soup export searches that directory itself, soup llama does not, so add it to PATH first.
  • When the program is missing the command prints llama-quantize not found on PATH; install llama.cpp or set LLAMA_CPP_HOME (with the name of the program you asked for) and exits 2.
  • --help after the subcommand shows Soup's help, not the program's. Run the program itself for its own options.
  • Arguments are limited: at most 64, each at most 1024 characters, with no NUL or line break in any of them. Otherwise it exits 2 before starting anything.
  • The program runs with a reduced environment. HF_TOKEN, OPENAI_API_KEY and every other variable outside a short allowlist are dropped (the list is in the CLI reference; since v0.77.1 it also keeps SYSTEMROOT, PATHEXT and NoDefaultCurrentDirectoryInExePath, and on Windows sets the last to 1, see Environment variables). Its output goes straight to your terminal and its exit code becomes the exit code of soup llama.

Other export formats

Soup CLI also supports:

  • ONNX — --format onnx for cross-platform inference, from a separate export-only environment with an optional --validate-onnx logits check (v0.78.0; see Model Export)
  • TensorRT-LLM — --format tensorrt for NVIDIA optimized serving
  • Hugging Face — not an export format. A merged checkpoint comes from soup merge --adapter <path> --output <dir>. The formats soup export accepts are gguf, gguf-ud, onnx, tensorrt, bitnet, tq1_0 and torchao; AWQ and GPTQ export were removed in v0.77.0, and they need v0.76.x and its [awq] or [gptq] extra, for example pip install "soup-cli[awq]<0.77"; upstream notes that both projects are archived and incompatible with [train] (see Model Export). Only the GGUF family (gguf, gguf-ud, bitnet, tq1_0) can be passed to --deploy ollama; the other formats are refused before the export starts, because Ollama cannot load them.

Soup is free and Apache-2.0. If it saved you a training run, starring the repo costs nothing and helps most. You can also fund the GPU time behind the work a 4 GB laptop cannot reach.