How to convert a model to NVFP4

last edited

Converting a model to NVFP4 means running post-training quantization with Model Optimizer or llm-compressor for LLMs, or a comfy-kitchen based converter for diffusion checkpoints. The result is a new file with 4-bit weights. Running it fast still needs Blackwell cards.

00.511.52346block of 16 valuesscale: 1 fp8 numbernearest of 8 levels, sign kept in 1 bit

Which tool converts a model to NVFP4?

The latest Model Optimizer release was v0.48.0, tagged in early November. The latest llm-compressor release was v0.15.0, tagged in late October. General background is on the quantization page.

toolmodelscalibrationoutput
hf_ptq.pyLLMs, VLMsdata-drivencheckpoint folder for vLLM or SGLang
quantize.py (diffusers)FLUX, LTX-Video, image and video models128-256 prompts--hf-ckpt-dir folder
oneshot()LLMs, VLMs20-256 samplescompressed-tensors folder
comfy-dit-quantizerComfyUI checkpointsoptional scale passone .safetensors file

How is an LLM converted to NVFP4?

20-256 samples set activation scaleslm_headsaveoneshot() with scheme nvfp4

In llm-compressor, a recipe of QuantizationModifier(targets="Linear", scheme="NVFP4", ignore=["lm_head"]) goes into oneshot(), and save_pretrained() writes the folder. The NVFP4 example calibrates on 20 samples.

In Model Optimizer, python hf_ptq.py --pyt_ckpt_path <model> --qformat nvfp4 --export_path <dir> does the same job. Its docs recommend nvfp4_mlp_only for better accuracy, since attention layers stay in higher precision.

How are diffusion models converted for ComfyUI?

blocks.0keep.mlpfp8q_projnvfp4k_projnvfp4input_scaleCOMFY_CALIB=1 passconfig rules, top-down

The ComfyUI loader reads one file, so converters rewrite chosen layers inside it. comfy-dit-quantizer reads a JSON file of per-layer rules and runs python quantize.py config.json model.safetensors output.safetensors. NVFP4 layers then need an input-scale pass: generate images with COMFY_CALIB=1, then run add_input_scale.py.

The Starnodes converter wraps this as a node and also converts on CPU. Lower-precision alternatives are compared in GGUF versus FP8 speed.

Sources