llama.cpp convert

swaleio/llamacpp-convert@b12855

llama.cpp convert

Converts a Hugging Face format model directory (config.json, tokenizer files, *.safetensors) into a single GGUF file that llama.cpp-based runtimes can load. The image's ENTRYPOINT is llama.cpp's /app/tools.sh dispatcher, which runs exactly one mode per invocation: the leading --convert argument execs convert_hf_to_gguf.py with the remaining arguments. That one-mode-per-invocation dispatch is why converting and quantizing are two separate tasks — llamacpp-convert and llamacpp-quantize — 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 outfile. Pass the same path to the next task.

Inputs

Input Required Default Description
model_dir yes — Absolute path of the Hugging Face format model directory to convert. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/model-hf) where an earlier task placed the model, or any other container-local path.
outfile yes — Absolute path for the converted .gguf file. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/model-f16.gguf) to share it with later tasks, or any other container-local path.
outtype no auto GGUF tensor type: f16, bf16, or q8_0. The default auto writes bf16 for a bf16 model and f16 otherwise, keeps the FP8 weights of an FP8 checkpoint scaled per tensor or per output channel, and fails on one with block scales: set bf16 for that.

model_dir and outfile are required — they are the paths you choose and the next task reads. outtype is optional and defaults to auto, which is what convert_hf_to_gguf.py itself does when the flag is omitted: it reads the checkpoint's own tensor dtype and writes bf16 for a bf16 model, f16 otherwise. Pass it explicitly to override that heuristic — f16 for a fixed full-precision baseline whatever the source is, bf16 to force bfloat16, or q8_0 to get an 8-bit file directly from conversion.

FP8 checkpoints depend on how their weights are scaled:

  • One scale per tensor or per output channel: auto keeps the weights in FP8 (F8_E4M3). A checkpoint scaled per tensor converts only with auto. Older llama.cpp builds cannot load the result, or the files quantized from it, correctly.
  • Block scales, as in Qwen's -FP8 models: auto fails with an "unsupported block/group scale" error. Set outtype to bf16, which writes the weights as bfloat16. The --fp8-as-q8 the error suggests is not one of this task's inputs.

Compute

CPU. Conversion is CPU- and RAM-bound — no CUDA is involved, so a GPU compute type adds nothing. Budget disk rather than VRAM: the workspace must hold the source directory and the converted file side by side (a 16-bit GGUF is roughly 2 bytes per parameter).

Example

Download a model from the Hugging Face Hub, convert it to a 16-bit GGUF, then quantize it with llamacpp-quantize. The convert step leaves outtype unset, so the converted file keeps the checkpoint's own dtype. 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 convert 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.