llama.cpp quantize
swaleio/llamacpp-quantize@b12723
llama.cpp quantize
Quantizes an existing GGUF file down to a smaller preset using llama.cpp's
llama-quantize, trading a little quality for a much smaller and faster model.
The image's ENTRYPOINT is llama.cpp's /app/tools.sh dispatcher, which runs
exactly one mode per invocation: the leading --quantize argument execs
llama-quantize with the remaining arguments. That one-mode-per-invocation
dispatch is why quantizing and converting are two separate tasks —
llamacpp-quantize and llamacpp-convert — rather than one; chain them, as in
the example below.
This task declares no outputs: it runs the vendor image unmodified, so there is
no wrapper to append to $WORKFLOW_TASK_OUTPUT — and none is needed, because
the consumer already knows where the result lands: it supplied output_gguf.
Pass the same path to the next task.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
input_gguf |
yes | — | Absolute path of the source .gguf file — typically the outfile of a llamacpp-convert task (e.g. ${{env.WORKFLOW_STORAGE}}/model-f16.gguf). |
output_gguf |
yes | — | Absolute path for the quantized .gguf file. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/model-q4_k_m.gguf) to share it with later tasks, or any other container-local path. |
preset |
yes | — | Quantization preset, e.g. Q4_K_M, Q5_K_M, Q8_0. |
All three inputs are required. input_gguf and output_gguf are the paths you
choose; preset has no default because llama-quantize has none either — it
refuses to guess a quantization type, and neither does this task. The preset is
the decision the task exists to make: every value is a different
quality-per-byte trade, none of them a neutral setting. Q4_K_M is the usual
choice, Q5_K_M trades size for quality, and Q8_0 is near-lossless but
largest.
Compute
CPU. llama-quantize is a multi-threaded CPU program — more cores make it
faster, and a GPU adds nothing. Budget disk rather than VRAM: the workspace
must hold the source and quantized files side by side (a Q4_K_M file is
roughly a third the size of its 16-bit source).
Example
Download a model from the Hugging Face Hub, convert it to a 16-bit GGUF with
llamacpp-convert, then quantize it to Q4_K_M. Each task lists its
predecessor in start_on so the steps run in order, and the files are
exchanged through the shared workspace paths the consumer chose.
name: llama.cpp quantize example
compute_type: cpu-4
entry_point: main
blocks:
main:
tasks:
weights:
name: Fetch weights
uses: swaleio/hf-download
args:
repo: Qwen/Qwen2.5-1.5B-Instruct
include: "*.safetensors,*.json,tokenizer.*"
dest: ${{env.WORKFLOW_STORAGE}}/qwen-hf
convert:
name: Convert to GGUF
uses: swaleio/llamacpp-convert
start_on:
- weights
args:
model_dir: ${{env.WORKFLOW_STORAGE}}/qwen-hf
outfile: ${{env.WORKFLOW_STORAGE}}/qwen-16bit.gguf
quantize:
name: Quantize
uses: swaleio/llamacpp-quantize
start_on:
- convert
args:
input_gguf: ${{env.WORKFLOW_STORAGE}}/qwen-16bit.gguf
output_gguf: ${{env.WORKFLOW_STORAGE}}/qwen-q4_k_m.gguf
preset: Q4_K_M
Downstream tasks read the quantized model at ${{env.WORKFLOW_STORAGE}}/qwen-q4_k_m.gguf
— the path the workflow supplied, so no output lookup is needed.
For the workflow syntax these examples use, see the workflow definition reference in the Swale documentation.
Licensed under the MIT License.