---
title: fp4linear
---

<div class="python-reference">
<a id="fastvideo.layers.fp4linear-functions"></a>
<a id="fastvideo.layers.fp4linear"></a>

<h2 id="fastvideo.layers.fp4linear.nvfp4_quantize_fenced"><code>fastvideo.layers.fp4linear.nvfp4_quantize_fenced</code></h2>
<pre class="doc-signature"><code>nvfp4_quantize_fenced(x: torch.Tensor, global_sf: torch.Tensor, sf_layout: int, do_shuffle: bool = False) -&gt; tuple&#91;torch.Tensor, torch.Tensor&#93;</code></pre>
<p>FlashInfer NVFP4 quantization with the DGX Spark (GB10) ordering fence.</p>
<p>Every FastVideo NVFP4 quantization goes through here, so the GB10
workaround covers inference and the QAT straight-through linear alike.</p>
<h2 id="fastvideo.layers.fp4linear.fp4_linear_forward"><code>fastvideo.layers.fp4linear.fp4_linear_forward</code></h2>
<pre class="doc-signature"><code>fp4_linear_forward(x: torch.Tensor) -&gt; tuple&#91;torch.Tensor, torch.Tensor | None&#93;</code></pre>

<details><summary>Source</summary><pre><code>def fp4_linear_forward(self, x: torch.Tensor) -&gt; tuple&#91;torch.Tensor, torch.Tensor | None&#93;:
    # pass config **positionally**; autograd.Function.apply ignores kwargs
    bias = self.bias if not self.skip_bias_add else None
    output = _LinearFWD4BWD16Fn.apply(x, self.weight, bias, &quot;cutlass&quot;, 16, True)
    output_bias = self.bias if self.skip_bias_add else None
    return output, output_bias</code></pre></details>
</div>
