---
title: nvfp4_qat_train_config
---

<div class="python-reference">
<a id="fastvideo.layers.quantization.nvfp4_qat_train_config-classes"></a>
<a id="fastvideo.layers.quantization.nvfp4_qat_train_config-functions"></a>
<a id="fastvideo.layers.quantization.nvfp4_qat_train_config"></a>
<p>NVFP4 quantization-aware <em>training</em> linear method (straight-through estimator).</p>
<p>The inference <code>nvfp4_qat</code> config quantizes each weight to FP4 once at load time
(<code>convert_model_to_fp4</code>) and has no gradient path — it is inference only. For
QAT <em>finetuning</em> the weight must stay a trainable bf16/fp32 master that is
fake-quantized to FP4 on every forward, with a full-precision backward (a
straight-through estimator), so the model learns to absorb FP4 linear error.</p>
<p>That STE already exists in <code>fastvideo.layers.fp4linear._LinearFWD4BWD16Fn</code>
(FP4 forward, full-precision backward) but is otherwise unwired. This method
bridges it into the standard <code>quant_config</code> path. Wan-style prefixes retain
the broad attention/FFN projection profile used by <code>nvfp4_qat</code>; LTX-2
prefixes use the exact curated target set from its <code>NVFP4</code> deployment config.
No <code>convert_model_to_fp4</code> is needed: the weight is kept in full precision and
quantized on the fly each step.</p>
<h2 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig</code></h2>
<pre class="doc-signature"><code>QuantizationConfig()</code></pre>
<p>Base class for quantization configs.</p>

<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_name"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_name</code></h3>
<pre class="doc-signature"><code>get_name() -&gt; QuantizationMethods</code></pre>
<p>Name of the quantization method.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_supported_act_dtypes"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_supported_act_dtypes</code></h3>
<pre class="doc-signature"><code>get_supported_act_dtypes() -&gt; list&#91;torch.dtype&#93;</code></pre>
<p>List of supported activation dtypes.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_min_capability"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_min_capability</code></h3>
<pre class="doc-signature"><code>get_min_capability() -&gt; int</code></pre>
<p>Minimum GPU capability to support the quantization method.</p>
<p>E.g., 70 for Volta, 75 for Turing, 80 for Ampere.
This requirement is due to the custom CUDA kernels used by the
quantization method.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_config_filenames"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_config_filenames</code></h3>
<pre class="doc-signature"><code>get_config_filenames() -&gt; list&#91;str&#93;</code></pre>
<p>List of filenames to search for in the model directory.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.from_config"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.from_config</code></h3>
<pre class="doc-signature"><code>from_config(config: dict&#91;str, Any&#93;) -&gt; QuantizationConfig</code></pre>
<p>Create a config class from the model's quantization config.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.override_quantization_method"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.override_quantization_method</code></h3>
<pre class="doc-signature"><code>override_quantization_method(hf_quant_cfg, user_quant) -&gt; QuantizationMethods | None</code></pre>
<p>Detects if this quantization method can support a given checkpoint
format by overriding the user specified quantization method -- 
this method should only be overwritten by subclasses in exceptional 
circumstances</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_from_keys"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_from_keys</code></h3>
<pre class="doc-signature"><code>get_from_keys(config: dict&#91;str, Any&#93;, keys: list&#91;str&#93;) -&gt; Any</code></pre>
<p>Get a value from the model's quantization config.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_from_keys_or"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_from_keys_or</code></h3>
<pre class="doc-signature"><code>get_from_keys_or(config: dict&#91;str, Any&#93;, keys: list&#91;str&#93;, default: Any) -&gt; Any</code></pre>
<p>Get a optional value from the model's quantization config.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_quant_method"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_quant_method</code></h3>
<pre class="doc-signature"><code>get_quant_method(layer: torch.nn.Module, prefix: str) -&gt; QuantizeMethodBase | None</code></pre>
<p>Get the quantize method to use for the quantized layer.</p>
<h4>Parameters</h4>
<dl>
<dt><code>layer: torch.nn.Module</code></dt><dd><p>The layer for the quant method.</p></dd>
<dt><code>prefix: str</code></dt><dd><p>The full name of the layer in the state dict</p></dd>
</dl>
<p>Returns:
    The quantize method. None if the given layer doesn't support quant
    method.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.validate_runtime"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.validate_runtime</code></h3>
<pre class="doc-signature"><code>validate_runtime(device: torch.device) -&gt; None</code></pre>
<p>Fail fast on a device the scheme cannot execute on.</p>
<p>Called once by loaders that select a serialized checkpoint scheme,
before any weight is read. The default accepts every device; schemes
with kernel or capability requirements override it.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_cache_scale"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizationConfig.get_cache_scale</code></h3>
<pre class="doc-signature"><code>get_cache_scale(name: str) -&gt; str | None</code></pre>

<h2 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase</code></h2>
<pre class="doc-signature"><code>QuantizeMethodBase()</code></pre>
<p>Base class for different quantized methods.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.create_weights"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.create_weights</code></h3>
<pre class="doc-signature"><code>create_weights(layer: torch.nn.Module, *weight_args, **extra_weight_attrs)</code></pre>
<p>Create weights for a layer.</p>
<p>The weights will be set as attributes of the layer.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.apply"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.apply</code></h3>
<pre class="doc-signature"><code>apply(layer: torch.nn.Module, *args, **kwargs) -&gt; torch.Tensor</code></pre>
<p>Apply the weights in layer to the input tensor.</p>
<p>Expects create_weights to have been called before on the layer.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.embedding"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.embedding</code></h3>
<pre class="doc-signature"><code>embedding(layer: torch.nn.Module, *args, **kwargs) -&gt; torch.Tensor</code></pre>
<p>Gather embeddings in the layer based on indices in the input tensor.</p>
<p>Expects create_weights to have been called before on the layer.</p>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.process_weights_after_loading"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.QuantizeMethodBase.process_weights_after_loading</code></h3>
<pre class="doc-signature"><code>process_weights_after_loading(layer: nn.Module) -&gt; None</code></pre>
<p>Process the weight after loading.</p>
<p>This can be used for example, to transpose weights for computation.</p>
<h2 id="fastvideo.layers.quantization.nvfp4_qat_train_config.is_ltx2_nvfp4_linear_prefix"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.is_ltx2_nvfp4_linear_prefix</code></h2>
<pre class="doc-signature"><code>is_ltx2_nvfp4_linear_prefix(prefix: str) -&gt; bool</code></pre>
<p>Return whether <em>prefix</em> belongs to the LTX-2 NVFP4 deployment set.</p>
<h2 id="fastvideo.layers.quantization.nvfp4_qat_train_config.set_weight_attrs"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.set_weight_attrs</code></h2>
<pre class="doc-signature"><code>set_weight_attrs(weight: torch.Tensor, weight_attrs: dict&#91;str, Any&#93; | None)</code></pre>
<p>Set attributes on a weight tensor.</p>
<p>This method is used to set attributes on a weight tensor. This method
will not overwrite existing attributes.</p>
<h3>Parameters</h3>
<dl>
<dt><code>weight: torch.Tensor</code></dt><dd><p>The weight tensor.</p></dd>
<dt><code>weight_attrs: dict[str, Any] | None</code></dt><dd><p>A dictionary of attributes to set on the weight tensor.</p></dd>
</dl>
<h2 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainQuantizeMethod"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainQuantizeMethod</code></h2>
<pre class="doc-signature"><code>NVFP4QATTrainQuantizeMethod()</code></pre>

<details><summary>Source</summary><pre><code>class NVFP4QATTrainQuantizeMethod(QuantizeMethodBase):

    def create_weights(self, layer: torch.nn.Module, input_size_per_partition: int, output_partition_sizes: list&#91;int&#93;,
                       input_size: int, output_size: int, params_dtype: torch.dtype, **extra_weight_attrs):
        # Trainable master weight, fake-quantized to FP4 on each forward.
        weight = Parameter(torch.empty(
            sum(output_partition_sizes),
            input_size_per_partition,
            dtype=params_dtype,
        ),
                           requires_grad=True)
        set_weight_attrs(weight, &#123;&quot;input_dim&quot;: 1, &quot;output_dim&quot;: 0&#125;)
        layer.register_parameter(&quot;weight&quot;, weight)
        set_weight_attrs(weight, extra_weight_attrs)

    def apply(self, layer: torch.nn.Module, x: torch.Tensor, bias: torch.Tensor | None = None) -&gt; torch.Tensor:
        # FP4 forward + full-precision backward (STE).
        from fastvideo.layers.fp4linear import _LinearFWD4BWD16Fn
        return _LinearFWD4BWD16Fn.apply(x, layer.weight, bias, &quot;cutlass&quot;, 16, True)</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainQuantizeMethod.create_weights"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainQuantizeMethod.create_weights</code></h3>
<pre class="doc-signature"><code>create_weights(layer: torch.nn.Module, input_size_per_partition: int, output_partition_sizes: list&#91;int&#93;, input_size: int, output_size: int, params_dtype: torch.dtype, **extra_weight_attrs)</code></pre>

<details><summary>Source</summary><pre><code>def create_weights(self, layer: torch.nn.Module, input_size_per_partition: int, output_partition_sizes: list&#91;int&#93;,
                   input_size: int, output_size: int, params_dtype: torch.dtype, **extra_weight_attrs):
    # Trainable master weight, fake-quantized to FP4 on each forward.
    weight = Parameter(torch.empty(
        sum(output_partition_sizes),
        input_size_per_partition,
        dtype=params_dtype,
    ),
                       requires_grad=True)
    set_weight_attrs(weight, &#123;&quot;input_dim&quot;: 1, &quot;output_dim&quot;: 0&#125;)
    layer.register_parameter(&quot;weight&quot;, weight)
    set_weight_attrs(weight, extra_weight_attrs)</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainQuantizeMethod.apply"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainQuantizeMethod.apply</code></h3>
<pre class="doc-signature"><code>apply(layer: torch.nn.Module, x: torch.Tensor, bias: torch.Tensor | None = None) -&gt; torch.Tensor</code></pre>

<details><summary>Source</summary><pre><code>def apply(self, layer: torch.nn.Module, x: torch.Tensor, bias: torch.Tensor | None = None) -&gt; torch.Tensor:
    # FP4 forward + full-precision backward (STE).
    from fastvideo.layers.fp4linear import _LinearFWD4BWD16Fn
    return _LinearFWD4BWD16Fn.apply(x, layer.weight, bias, &quot;cutlass&quot;, 16, True)</code></pre></details>
<h2 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig</code></h2>
<pre class="doc-signature"><code>NVFP4QATTrainConfig()</code></pre>


<details><summary>Source</summary><pre><code>class NVFP4QATTrainConfig(QuantizationConfig):

    def __init__(self) -&gt; None:
        super().__init__()

    def get_name(self):
        return &quot;nvfp4_qat_train&quot;

    def get_supported_act_dtypes(self):
        return &#91;torch.bfloat16, torch.float16&#93;

    @classmethod
    def get_min_capability(cls):
        return 100

    @staticmethod
    def get_config_filenames():
        return &#91;&#93;

    @classmethod
    def from_config(cls, config: dict&#91;str, Any&#93;) -&gt; &quot;NVFP4QATTrainConfig&quot;:
        return cls()

    def get_quant_method(self, layer: torch.nn.Module, prefix: str):
        from fastvideo.layers.linear import LinearBase
        if not isinstance(layer, LinearBase):
            return None
        matches = (is_ltx2_nvfp4_linear_prefix(prefix) if prefix.startswith(&quot;ltx2.&quot;) else any(
            layer_name in prefix for layer_name in DEFAULT_FP4_LAYERS))
        if matches:
            return NVFP4QATTrainQuantizeMethod()
        return None</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_name"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_name</code></h3>
<pre class="doc-signature"><code>get_name()</code></pre>

<details><summary>Source</summary><pre><code>def get_name(self):
    return &quot;nvfp4_qat_train&quot;</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_supported_act_dtypes"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_supported_act_dtypes</code></h3>
<pre class="doc-signature"><code>get_supported_act_dtypes()</code></pre>

<details><summary>Source</summary><pre><code>def get_supported_act_dtypes(self):
    return &#91;torch.bfloat16, torch.float16&#93;</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_min_capability"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_min_capability</code></h3>
<pre class="doc-signature"><code>get_min_capability()</code></pre>

<details><summary>Source</summary><pre><code>@classmethod
def get_min_capability(cls):
    return 100</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_config_filenames"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_config_filenames</code></h3>
<pre class="doc-signature"><code>get_config_filenames()</code></pre>

<details><summary>Source</summary><pre><code>@staticmethod
def get_config_filenames():
    return &#91;&#93;</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.from_config"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.from_config</code></h3>
<pre class="doc-signature"><code>from_config(config: dict&#91;str, Any&#93;) -&gt; NVFP4QATTrainConfig</code></pre>

<details><summary>Source</summary><pre><code>@classmethod
def from_config(cls, config: dict&#91;str, Any&#93;) -&gt; &quot;NVFP4QATTrainConfig&quot;:
    return cls()</code></pre></details>
<h3 id="fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_quant_method"><code>fastvideo.layers.quantization.nvfp4_qat_train_config.NVFP4QATTrainConfig.get_quant_method</code></h3>
<pre class="doc-signature"><code>get_quant_method(layer: torch.nn.Module, prefix: str)</code></pre>

<details><summary>Source</summary><pre><code>def get_quant_method(self, layer: torch.nn.Module, prefix: str):
    from fastvideo.layers.linear import LinearBase
    if not isinstance(layer, LinearBase):
        return None
    matches = (is_ltx2_nvfp4_linear_prefix(prefix) if prefix.startswith(&quot;ltx2.&quot;) else any(
        layer_name in prefix for layer_name in DEFAULT_FP4_LAYERS))
    if matches:
        return NVFP4QATTrainQuantizeMethod()
    return None</code></pre></details>
</div>
