---
title: fp8linear
---

<div class="python-reference">

<a id="fastvideo.layers.fp8linear"></a>
<p>FP8 quantization-aware training for linear layers.</p>
<p>Mirror of <code>fp4linear.py</code> but for FP8 (e4m3). The forward pass quantizes both
activations and weights to FP8 and runs <code>torch._scaled_mm</code>; the backward pass
is a bf16 straight-through estimator so the high-precision master weights stay
trainable. Falls back to a bf16 fake-quant forward wherever the device has no
e4m3fn <code>_scaled_mm</code> (pre-sm89 CUDA, pre-CDNA4 ROCm); the capability gate and
the FP8 constants are shared with <code>fp8_config</code> so the inference and QAT paths
cannot drift.</p>
<h2 id="fastvideo.layers.fp8linear.fp8_linear_forward"><code>fastvideo.layers.fp8linear.fp8_linear_forward</code></h2>
<pre class="doc-signature"><code>fp8_linear_forward(x: torch.Tensor) -&gt; torch.Tensor</code></pre>

<details><summary>Source</summary><pre><code>def fp8_linear_forward(self, x: torch.Tensor) -&gt; torch.Tensor:
    # pass config **positionally**; autograd.Function.apply ignores kwargs
    return _LinearFWD8BWD16Fn.apply(x, self.weight, self.bias, &quot;tensor&quot;), None</code></pre></details>
</div>
