nvfp4_qat_config ¶
NVFP4 quantization-aware (QAD) linear method, inference path.
Quantizes every targeted linear's weight to NVFP4 once at load time and runs each forward as a registered flashinfer-backed FP4 matmul. The original fp16/bf16 weight is popped immediately after quantization so the half-precision copy does not keep occupying GPU memory — that's what lets a Wan-2.1 pipeline stay fully resident on a single GPU without any CPU offloading.
The quantize / matmul custom ops are owned by :mod:fastvideo.layers.quantization.nvfp4_config and registered under the fastvideo_fp4:: namespace. We reuse them here for two reasons:
- Re-registering the same op name in a second module would raise.
- The registered ops have
register_fakeshape/dtype kernels, which is what makes the inference pipeline's per-blocktorch.compiletrace through without graph breaks. Calling raw flashinfer functions (the old behavior of this file, plus a@torch.compileonapply) graph-breaks at every quantize and every matmul.
For QAT training, see nvfp4_qat_train_config which keeps the weight trainable and fake-quantizes on the fly via a straight-through estimator.
Classes¶
fastvideo.layers.quantization.nvfp4_qat_config.NVFP4QATConfig ¶
Bases: QuantizationConfig
NVFP4 (Wan-style) linear quantization, inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_layers | tuple[str, ...] | None | Substrings matched against each linear layer's prefix. A layer is quantized if any substring is contained in its prefix. Defaults to the standard Wan attention + FFN projections (:data: | None |
Source code in fastvideo/layers/quantization/nvfp4_qat_config.py
fastvideo.layers.quantization.nvfp4_qat_config.NVFP4QATQuantizeMethod ¶
Bases: QuantizeMethodBase
Inference-only NVFP4 linear method with weight popping.
The dense weight parameter is materialized at load time only so that :func:convert_model_to_fp4 can read it once; the loader then removes it via mod._parameters.pop('weight'). From that point forward, apply reads only _fp4_weight / _fp4_weight_scale / _weight_global_sf.
Source code in fastvideo/layers/quantization/nvfp4_qat_config.py
Functions:¶
fastvideo.layers.quantization.nvfp4_qat_config.convert_model_to_fp4 ¶
Prequantize every FP4-tagged linear and drop its dense weight.
Walks the module tree, and for each layer whose quant_method is an :class:NVFP4QATQuantizeMethod, computes the NVFP4 packed weight / scale / global-scale buffers, then pops the original fp16/bf16 weight parameter so it no longer occupies GPU memory.