简体中文 | English
This directory provides a YAML-based selective GGUF quantization tool.
The environment name is model-quant:
conda env create -f tools/quant/environment.yamlThe config/ directory contains YAML examples for different models. Each YAML
file lists tensor families for a model, making it easy to configure mixed
quantization by tensor group.
Using SmolVLA as an example, a YAML plan contains multiple components. Each component corresponds to one GGUF file.
- First, edit the
inputandoutputfields in each component. They specify the source GGUF path and quantized GGUF output path. Directory variables are usually supplied in step 2, but file names should be fixed in the YAML. - Then, under
groups, edit thetypefor tensor families that should be quantized. In the example below, the action expert FFN gate tensor family is quantized toq8_0. The FFN gate family is defined by thepatternsfield: every block'sffn_gateweight tensor.
components:
...
action_expert:
input: "${SRC_GGUF_DIR}/action-expert-smolvla-f32.gguf"
output: "${QUANT_OUTPUT_DIR:-debug/artifacts/quant/smolvla_outputs}/action-expert-smolvla-quant.gguf"
groups:
ffn_gate:
quantizable: true
type: q8_0
shape: [2048, 720]
patterns:
- smolvla.expert.blk.*.ffn_gate.weight
...With this structure, you can freely choose which tensor families to quantize and which quantization type to use.
Notes:
- Some tensors should not be quantized, such as norm-related tensors. These
groups are marked with
quantizable: false, and theirtypeshould remainf32. - For the state projector, the quantization benefit is small and final accuracy is sensitive to its precision. We recommend keeping that component in f32.
The helper shell is tools/quant/shell/quant.sh. Before running it, configure
the key variables below, either by editing the shell or exporting environment
variables:
| Variable | Description |
|---|---|
ROBOT_CPP_ROOT |
Repository root. |
SRC_GGUF_DIR |
Source GGUF directory, referenced by ${SRC_GGUF_DIR} in YAML. |
QUANT_OUTPUT_DIR |
Quantized GGUF output directory, referenced by ${QUANT_OUTPUT_DIR} in YAML. |
MODEL_QUANT_PYTHON |
Python path from the quant conda environment; use which python after activating it. |
PLAN_PATH |
Quant plan YAML path. |
QUANT_BUILD_DIR* |
The script searches this directory for libggml-base / ggml-base.dll; if not found, it automatically builds ggml-base there. |
GGML_BASE_LIB* |
Existing libggml-base / ggml-base.dll path. If unset, the script tries to build and locate it automatically. |
*The quantization flow uses the ggml runtime library. The required
ggml-baselibrary name differs by platform:
- macOS:
libggml-base.dylib- Linux:
libggml-base.so- Windows:
ggml-base.dllorlibggml-base.dll
Then run:
bash tools/quant/shell/quant.shThis tool writes GGUF through the vendored llama.cpp/gguf-py. Standard
quantization types go directly through gguf-py:
f32f16bf16q4_0q4_1q5_0q5_1q8_0
K-quants use a locally built libggml-base and call llama.cpp/ggml's reference
quantizer:
q2_kq3_kq4_kq5_kq6_k