make round-to-grid with refinement the default, add --learned for learned rounding
On Qwen2.5-0.5B, learned rounding matched round-to-grid in perplexity and KL (22.38 vs 22.37, 0.0920 vs 0.0919) at about six times the quantize time. --simple is still accepted as a no-op. Docs and man pages updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
164fa6b4a4
commit
1e50e4e045
16 files changed
+76
-39
No files matched your search
@@ -14,7 +14,7 @@ gguf_to_nvfp4_gguf \- quantize or repack an existing GGUF model to NVFP4 GGUF
|
||||
[\fB\-\-convert\-to\-quant\fR \fIPATH\fR]
|
||||
[\fB\-\-model\-name\fR \fINAME\fR]
|
||||
[\fB\-\-device\fR \fIDEVICE\fR]
|
||||
[\fB\-\-simple\fR]
|
||||
[\fB\-\-learned\fR]
|
||||
[\fB\-\-optimizer\fR \fIOPT\fR]
|
||||
[\fB\-\-num\-iter\fR \fIN\fR]
|
||||
[\fB\-\-lr\fR \fILR\fR]
|
||||
@@ -51,8 +51,8 @@ reads an existing GGUF model (such as an F16, BF16, or existing quantized checkp
|
||||
and converts it to NVIDIA FP4 (NVFP4) format, or repacks an existing NVFP4 GGUF file.
|
||||
.PP
|
||||
Vocabulary, tokenizer settings, architecture metadata, and tensor names are copied directly
|
||||
from the source GGUF header. When quantizing unquantized (float) tensors, learned rounding
|
||||
or simple grid rounding is applied using the same optimization flags as \fBhf_to_nvfp4_gguf\fR.
|
||||
from the source GGUF header. When quantizing unquantized (float) tensors, round-to-grid refinement (default)
|
||||
or learned rounding (\fB\-\-learned\fR) is applied using the same optimization flags as \fBhf_to_nvfp4_gguf\fR.
|
||||
.PP
|
||||
An accompanying Ollama \fBModelfile\fR is written alongside the output GGUF, configured with
|
||||
the source model's parameters and templates.
|
||||
@@ -91,8 +91,11 @@ Skip learned rounding. Writes a float GGUF, or copies/repacks an existing NVFP4
|
||||
Target data type when learned rounding is skipped. \fBnvfp4\fR copies an already NVFP4 GGUF without re-optimizing;
|
||||
\fBauto\fR leaves tensors as stored in the source file (default: \fBauto\fR).
|
||||
.TP
|
||||
.B \-\-learned
|
||||
Use \fBconvert_to_quant\fR's learned rounding instead of the default round-to-grid with block-scale and code refinement. On Qwen2.5-0.5B it matched the default in perplexity and KL and took about six times as long.
|
||||
.TP
|
||||
.B \-\-simple
|
||||
Round each value directly onto the E2M1 grid without learned rounding (fast, non-iterative).
|
||||
Round onto the E2M1 grid without learned rounding (default; accepted for compatibility).
|
||||
.TP
|
||||
.B \-\-quantize\-output
|
||||
Also quantize the output (\fIlm_head\fR) matrix. By default, output projection layers are left unquantized.
|
||||
@@ -188,10 +191,10 @@ gguf_to_nvfp4_gguf -o ./llama3-nvfp4 ./llama-3-8b-f16.gguf
|
||||
.fi
|
||||
.RE
|
||||
.TP
|
||||
.B Fast conversion with simple grid rounding:
|
||||
.B Default conversion (grid rounding with scale and code refinement):
|
||||
.RS
|
||||
.nf
|
||||
gguf_to_nvfp4_gguf --simple -o ./qwen-nvfp4 ./qwen2.5-7b-bf16.gguf
|
||||
gguf_to_nvfp4_gguf -o ./qwen-nvfp4 ./qwen2.5-7b-bf16.gguf
|
||||
.fi
|
||||
.RE
|
||||
.TP
|
||||
|
||||
@@ -23,7 +23,7 @@ gguf_to_nvfp4_hf \- convert and quantize GGUF models to NVFP4 Hugging Face forma
|
||||
[\fB\-\-llama\-cpp\fR \fIPATH\fR]
|
||||
[\fB\-\-convert\-to\-quant\fR \fIPATH\fR]
|
||||
[\fB\-\-device\fR \fIDEVICE\fR]
|
||||
[\fB\-\-simple\fR]
|
||||
[\fB\-\-learned\fR]
|
||||
[\fB\-\-optimizer\fR \fIOPT\fR]
|
||||
[\fB\-\-num\-iter\fR \fIN\fR]
|
||||
[\fB\-\-lr\fR \fILR\fR]
|
||||
@@ -57,7 +57,7 @@ GGUF tensor names are reverse-mapped to canonical Hugging Face conventions
|
||||
and RoPE permutations for Q and K are inverted.
|
||||
.PP
|
||||
If the source GGUF contains float or non-NVFP4 weights, 2D weight matrices are quantized
|
||||
using convert_to_quant's learned rounding (or simple round-to-grid with \fB\-\-simple\fR).
|
||||
using round-to-grid with block-scale and code refinement (or convert_to_quant's learned rounding with \fB\-\-learned\fR).
|
||||
If the source GGUF already contains NVFP4 super-blocks, they are unpacked and repacked
|
||||
into ModelOpt-compatible safetensors without loss of precision.
|
||||
.PP
|
||||
@@ -107,8 +107,11 @@ Data type for tensors when \fB\-\-no\-quant\fR is used (default: \fBauto\fR).
|
||||
.BI \-\-output\-dtype " " {bfloat16,float16}
|
||||
Data type used for unquantized 2D weights, layer norms, and embeddings (default: \fBbfloat16\fR).
|
||||
.TP
|
||||
.B \-\-learned
|
||||
Use \fBconvert_to_quant\fR's learned rounding instead of the default round-to-grid with block-scale and code refinement. On Qwen2.5-0.5B it matched the default in perplexity and KL and took about six times as long.
|
||||
.TP
|
||||
.B \-\-simple
|
||||
Round weights directly onto the E2M1 grid without iterative learned rounding.
|
||||
Round onto the E2M1 grid without learned rounding (default; accepted for compatibility).
|
||||
.SS Optimization & Learning Rate
|
||||
.TP
|
||||
.BI \-\-optimizer " " {auto,prodigy,adamw,radam,original}
|
||||
|
||||
@@ -14,7 +14,7 @@ hf_to_nvfp4_gguf \- quantize Hugging Face models to NVFP4 GGUF for llama.cpp and
|
||||
[\fB\-\-convert\-to\-quant\fR \fIPATH\fR]
|
||||
[\fB\-\-model\-name\fR \fINAME\fR]
|
||||
[\fB\-\-device\fR \fIDEVICE\fR]
|
||||
[\fB\-\-simple\fR]
|
||||
[\fB\-\-learned\fR]
|
||||
[\fB\-\-optimizer\fR \fIOPT\fR]
|
||||
[\fB\-\-num\-iter\fR \fIN\fR]
|
||||
[\fB\-\-lr\fR \fILR\fR]
|
||||
@@ -53,8 +53,8 @@ and \fBOllama\fR.
|
||||
.PP
|
||||
The model is loaded through \fBllama.cpp\fR's architecture conversion logic so that
|
||||
all vocabulary, tensor naming conventions, tokenization metadata, and architectural
|
||||
parameters match native GGUF standards. Weight matrices are quantized using learned
|
||||
rounding (via \fBconvert_to_quant\fR) or simple nearest-grid projection onto the E2M1
|
||||
parameters match native GGUF standards. Weight matrices are quantized using nearest-grid projection
|
||||
with block-scale and code refinement (default) or learned rounding (\fB\-\-learned\fR, via \fBconvert_to_quant\fR), onto the E2M1
|
||||
floating point grid with two-level scaling (per-block E4M3/E8M0 scales and per-tensor scales).
|
||||
.PP
|
||||
Along with the output GGUF, an Ollama \fBModelfile\fR is generated automatically,
|
||||
@@ -96,8 +96,11 @@ Skip learned rounding. Writes a float GGUF, or repacks an already NVFP4 checkpoi
|
||||
Data type for non-quantized weights when learned rounding is skipped. \fBnvfp4\fR repacks a
|
||||
checkpoint that already has packed 4-bit weights. \fBauto\fR preserves the source float types (default: \fBauto\fR).
|
||||
.TP
|
||||
.B \-\-learned
|
||||
Use \fBconvert_to_quant\fR's learned rounding instead of the default round-to-grid with block-scale and code refinement. On Qwen2.5-0.5B it matched the default in perplexity and KL and took about six times as long.
|
||||
.TP
|
||||
.B \-\-simple
|
||||
Round weights directly onto the E2M1 grid without iterative learned rounding (fast, non-iterative).
|
||||
Round onto the E2M1 grid without learned rounding (default; accepted for compatibility).
|
||||
.TP
|
||||
.B \-\-quantize\-output
|
||||
Also quantize the final output projection (\fIlm_head\fR) matrix. By default, output layers are
|
||||
@@ -191,17 +194,17 @@ Enable detailed verbose logging.
|
||||
Run internal verification of NVFP4 packing against llama.cpp's reference dequantizer and exit immediately.
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
.B Full learned-rounding conversion to GGUF:
|
||||
.B Learned-rounding conversion to GGUF (slow, no measured quality gain):
|
||||
.RS
|
||||
.nf
|
||||
hf_to_nvfp4_gguf -o ./llama3-8b-NVFP4 ./meta-llama-3-8b
|
||||
hf_to_nvfp4_gguf --learned -o ./llama3-8b-NVFP4 ./meta-llama-3-8b
|
||||
.fi
|
||||
.RE
|
||||
.TP
|
||||
.B Fast quantization with simple grid rounding:
|
||||
.B Default quantization (grid rounding with scale and code refinement):
|
||||
.RS
|
||||
.nf
|
||||
hf_to_nvfp4_gguf --simple -o ./qwen-nvfp4 ./Qwen2.5-7B-Instruct
|
||||
hf_to_nvfp4_gguf -o ./qwen-nvfp4 ./Qwen2.5-7B-Instruct
|
||||
.fi
|
||||
.RE
|
||||
.TP
|
||||
|
||||
@@ -22,7 +22,7 @@ hf_to_nvfp4_hf \- quantize Hugging Face models to NVFP4 Hugging Face format
|
||||
[\fB\-\-llama\-cpp\fR \fIPATH\fR]
|
||||
[\fB\-\-convert\-to\-quant\fR \fIPATH\fR]
|
||||
[\fB\-\-device\fR \fIDEVICE\fR]
|
||||
[\fB\-\-simple\fR]
|
||||
[\fB\-\-learned\fR]
|
||||
[\fB\-\-optimizer\fR \fIOPT\fR]
|
||||
[\fB\-\-num\-iter\fR \fIN\fR]
|
||||
[\fB\-\-lr\fR \fILR\fR]
|
||||
@@ -56,8 +56,8 @@ vocabulary, chat templates, and generation configs. For each quantized weight ma
|
||||
the script writes ModelOpt-compatible packed 4-bit weights alongside per-block E4M3 scale
|
||||
factors (\fI<name>.weight_scale\fR) and per-tensor scale factors (\fI<name>.weight_scale_2\fR).
|
||||
.PP
|
||||
Weights are quantized using learned rounding (via \fBconvert_to_quant\fR) or simple nearest-grid
|
||||
projection onto the E2M1 floating point grid with two-level scaling. Biases are adjusted
|
||||
Weights are quantized using nearest-grid projection with block-scale and code refinement (default)
|
||||
or learned rounding (\fB\-\-learned\fR, via \fBconvert_to_quant\fR), onto the E2M1 floating point grid with two-level scaling. Biases are adjusted
|
||||
using simulated calibration data unless disabled. Checkpoint-based resumption is supported
|
||||
per tensor so interrupted runs can resume without recomputing.
|
||||
.SH POSITIONAL ARGUMENTS
|
||||
@@ -97,8 +97,11 @@ Data type for non-quantized weights when learned rounding is skipped (default: \
|
||||
.BI \-\-output\-dtype " " {bfloat16,float16}
|
||||
Data type used for unquantized 2D weights, layer norms, and embeddings (default: \fBbfloat16\fR).
|
||||
.TP
|
||||
.B \-\-learned
|
||||
Use \fBconvert_to_quant\fR's learned rounding instead of the default round-to-grid with block-scale and code refinement. On Qwen2.5-0.5B it matched the default in perplexity and KL and took about six times as long.
|
||||
.TP
|
||||
.B \-\-simple
|
||||
Round weights directly onto the E2M1 grid without iterative learned rounding.
|
||||
Round onto the E2M1 grid without learned rounding (default; accepted for compatibility).
|
||||
.SS Optimization & Learning Rate
|
||||
.TP
|
||||
.BI \-\-optimizer " " {auto,prodigy,adamw,radam,original}
|
||||
@@ -220,7 +223,7 @@ Quantize with fast simple grid rounding without learned iterations:
|
||||
.PP
|
||||
.nf
|
||||
.RS
|
||||
hf_to_nvfp4_hf --simple -o ./my-model-nvfp4 ./my-model
|
||||
hf_to_nvfp4_hf -o ./my-model-nvfp4 ./my-model
|
||||
.RE
|
||||
.fi
|
||||
.SH SEE ALSO
|
||||
|
||||
@@ -10,7 +10,7 @@ hf_to_nvfp4_safetensors \- quantize a Hugging Face directory to a ComfyUI NVFP4
|
||||
[\fB\-\-heur\fR]
|
||||
[\fB\-\-exclude\-layers\fR \fIREGEX\fR]
|
||||
[\fB\-\-convert\-to\-quant\fR \fIPATH\fR]
|
||||
[\fB\-\-simple\fR]
|
||||
[\fB\-\-learned\fR]
|
||||
[\fB\-\-optimizer\fR \fIOPT\fR]
|
||||
[\fB\-\-num\-iter\fR \fIN\fR]
|
||||
[\fB\-\-lr\fR \fILR\fR]
|
||||
@@ -79,8 +79,11 @@ Skip layers that convert_to_quant's built-in size heuristic rejects.
|
||||
Regular expression matching layer or tensor names to leave unquantized in float format.
|
||||
.SS Quantization & Optimization
|
||||
.TP
|
||||
.B \-\-learned
|
||||
Use \fBconvert_to_quant\fR's learned rounding instead of the default round-to-grid with block-scale and code refinement. On Qwen2.5-0.5B it matched the default in perplexity and KL and took about six times as long.
|
||||
.TP
|
||||
.B \-\-simple
|
||||
Round onto the E2M1 grid directly without iterative learned rounding.
|
||||
Round onto the E2M1 grid without learned rounding (default; accepted for compatibility).
|
||||
.TP
|
||||
.BI \-\-optimizer " " {auto,prodigy,adamw,radam,original}
|
||||
Learned-rounding optimizer. \fBauto\fR uses Prodigy when installed, otherwise AdamW (default: \fBauto\fR).
|
||||
|
||||
@@ -114,7 +114,7 @@ Override maximum context length stored in the GGUF.
|
||||
.TP
|
||||
.I quant_opts
|
||||
All standard learned-rounding and execution options supported by \fBgguf_to_nvfp4_gguf\fR
|
||||
are supported: \fB\-\-simple\fR, \fB\-\-optimizer\fR, \fB\-\-lr\fR, \fB\-\-num\-iter\fR,
|
||||
are supported: \fB\-\-learned\fR, \fB\-\-optimizer\fR, \fB\-\-lr\fR, \fB\-\-num\-iter\fR,
|
||||
\fB\-\-scale\-optimization\fR, \fB\-\-device\fR, \fB\-\-checkpoint\-dir\fR, etc.
|
||||
.SS \-\-info
|
||||
.B ollama_nvfp4
|
||||
|
||||
@@ -19,7 +19,7 @@ safetensors_to_nvfp4_gguf \- quantize a safetensors file to an NVFP4 GGUF weight
|
||||
[\fB\-\-verbose\fR]
|
||||
[\fB\-\-self\-test\fR]
|
||||
[\fB\-\-device\fR \fIDEVICE\fR]
|
||||
[\fB\-\-simple\fR]
|
||||
[\fB\-\-learned\fR]
|
||||
[\fB\-\-optimizer\fR \fIOPT\fR]
|
||||
[\fB\-\-num\-iter\fR \fIN\fR]
|
||||
[\fB\-\-lr\fR \fILR\fR]
|
||||
@@ -93,8 +93,11 @@ Path to a vision projector GGUF to copy next to output. May be specified multipl
|
||||
Maximum context length to store in the GGUF metadata.
|
||||
.SS Quantization & Optimization
|
||||
.TP
|
||||
.B \-\-learned
|
||||
Use \fBconvert_to_quant\fR's learned rounding instead of the default round-to-grid with block-scale and code refinement. On Qwen2.5-0.5B it matched the default in perplexity and KL and took about six times as long.
|
||||
.TP
|
||||
.B \-\-simple
|
||||
Round each value directly onto the E2M1 grid without learned rounding.
|
||||
Round onto the E2M1 grid without learned rounding (default; accepted for compatibility).
|
||||
.TP
|
||||
.BI \-\-optimizer " " {auto,prodigy,adamw,radam,original}
|
||||
Learned-rounding optimizer (default: \fBauto\fR).
|
||||
@@ -199,10 +202,10 @@ safetensors_to_nvfp4_gguf --no-quant --outtype nvfp4 -o repacked.gguf comfy-nvfp
|
||||
.fi
|
||||
.RE
|
||||
.TP
|
||||
.B Quantize every eligible weight matrix with simple grid rounding:
|
||||
.B Quantize every eligible weight matrix (default grid rounding):
|
||||
.RS
|
||||
.nf
|
||||
safetensors_to_nvfp4_gguf --simple --all-weights -o fast-nvfp4.gguf model.safetensors
|
||||
safetensors_to_nvfp4_gguf --all-weights -o fast-nvfp4.gguf model.safetensors
|
||||
.fi
|
||||
.RE
|
||||
.SH EXIT STATUS
|
||||
|
||||
Reference in new issue
Block a user