Blog
Research
December 1, 2026

Optimizing Video Diffusion Models by Utilizing End-to-End NVFP4 Inference

Research engineerΒ at Synthesia

Create AI videos with 240+ avatars in 140+ languages

Key Takeaways

In this work, we present and end to end recipe for NVFP4 inference of video diffusion model, by using NVIDIA Model Optimizer to selectively quantise linear layers to NVFP4, and by augmenting the SageAttention3 algorithm with Hadamard rotation to outlier along the channel dimension to remove the background drift and temporal artefacts from the generated video. The FP4 attention kernel achieves a performance of 1.05 peta-ops, and the end to end speed up of the FP4 inference recipe is 1.36x faster than the FP8 linear layer and attention.

Video diffusion models generate data by learning how to undo noise given conditioning signals such as a prompt, audio and reference images that steer the video generation. They typically work by denoising one chunk at a time, which consists of multiple frames. The noise generated is first run through an encoder which compresses it into a latent space, passing that output to the denoising transformer, followed by a decoder.

Even with the compression, because of large sequence lengths, a significant amount of time is spent in self-attention and linear layers of the model. It is thus of interest to minimize the latency to reduce the serving cost and obtain a better user experience.

The NVFP4 data type

The NVFP4 datatype has only 4 bits: 1 for the sign, 2 for the exponent and 1 mantissa bit, and can only represent 15 values. To mitigate the issues with this low dynamic range, the input is quantized such that every 16 elements share one 8-bit scale of the format e4m3. An additional FP32 scale is shared across the entire tensor to extend the range of the e4m3 block scales. Together, these scales are chosen such that the largest value maps to the largest value e2m1 can represent, i.e. 6. This works well when the numbers are in a similar range, but can lead to loss of information when there’s a lot of variance in the magnitude within a block.

Combining Hadamard Rotation with SageAttention3

SageAttention3 (SA3) is a well known technique for using the NVFP4 datatype for video diffusion models. It quantises both matrix multiplications, QKα΅€ and PV, so Q, K, V and the softmax probabilities P are all stored in NVFP4. It limits the errors from outliers in two ways. First, NVFP4's small 1Γ—16 block quantisation granularity confines an outlier to the 16 values that share its scale. Second, it inherits mean smoothing from SageAttention 1 and 2. For tensors of shape [B, N, H, D] where the symbols have their usual meaning, it subtracts from K its mean over all L tokens, one value per channel and head. It subtracts from Q its mean over each block of consecutive tokens, of a certain block size b. The contribution of the subtracted Q mean is then added back to the attention scores; K smoothing needs no correction because softmax is invariant to a constant shift within each row.

However, even with the small granularity of 1x16 it is possible that this window covers where the values have high variance which can lead to information loss. For example, consider the following values in the window, with the converted NVFP4 values, we use just 8 values for this demonstration, where 8 values share one scale. In this example we have 4 keys and 1 query token.

With SageAttention3, key 2 would be quantised as follows:

However, this only works if the outlier is shared across the tokens. That however may not always be the case and the massive channel can change value and sign from token to token and mean smoothing no longer eliminates the same.

Consider an example with a head dimension of 16, where the keys 0,1, 2 and 3 are abbreviated as K0, K1, K2 and K3 respectively, and query is abbreviated as Q.

With this distribution, because of the negative sign, mean smoothing is not enough to absorb the outliers, and the quantisation key 2 becomes as follows:

As it can be seen, quite a few of the values have been flushed to zero, leading to information loss. Moreover, running attention with such quantisation errors can also lead to the attention weight landing on the wrong key, as it can be seen below:

We solve this problem by adding a head-wise (i.e. along the D dimension) Hadamard rotation, which spreads this energy across these 1x16 blocks, prior to the quantisation of the Q, K and V tensors, and keep each key’s content in the quantised block. A Hadamard matrix is a square matrix made up of Β±1 entries, who’s rows are mutually orthogonal.

‍

And hence we need not undo the rotation after the QKT before computing the softmax scores. The rotation of Q, K and V can be fused into the quantisation step, and the final rotation can be fused into the attention kernel, to keep the overhead at the minimum. The fusion of rotation into quantisation is not done as a part of this work.

It’s worth noting that Hadamard rotation does not substitute mean smoothing, but rather they act along different axes to enable FP4 quantisation of attention.

Mean smoothing subtracts each channel's average over the sequence. If an outlier is present in every token across the D dimension per head, that average is as large as the outlier itself, and subtracting it brings every token back to ordinary values before quantisation. If the outlier changes from token to token, for example in sign, its average is close to zero and smoothing removes nothing. The Hadamard rotation does not need the outlier to be shared: it works within each token, spreading the large value across all 128 channels so that no 1Γ—16 block is dominated by it.

Going back to the 16 channel example above, the quantisation of the second key would look as follows, where the input is rotated and then mean smoothed prior to quantisation

And the attention weights look as follows:

As it can be seen, the attention weight lands on the correct key with this method.

Results

Looking at an attention output from the first layer, from the first denoising step from a real world use case, compared against BF16 attention, the Peak signal-to-noise ratio (PSNR) numbers are as follows, where the Hadamard rotation shows a 2.5 increase in the PSNR.

Taking an example from a real world use case, the below diagram shows that Hadamard rotation reduces the drift in the static background and temporal flicker in videos as well. The first row shows a still from the video for context, and the image below, is a heatmap of the pixel level changes, which is obtained by averaging the absolute pixel difference across time.

As one expects, there is a lot of motion around the face and the body of the avatar, and the Hadamard rotation prevents drift from the static background, which is very evident in the base SA3 case evidenced by the vertical banding in the background.

Hadamard rotation also prevents a temporal flicker in the high frequency regions, as evidenced by the GIF below. It can be seen in the GIF, there is a tear in the high frequency regions of the Avatar. Here FP4(base) refers to using just the SageAttention3 algorithm.

FP4 Attention Kernel

We target the NVIDIA RTX PROβ„’ 6000 Blackwell Server Edition which has a compute capability of 12.0. We adapt the standard producer consumer model introduced by flash attention 3, where we have 2 warp-groups acting as the consumer. Each warp-group handles an output tile of 64 along the query / output length dimension.

The first 3 warps of the producer warp-group are responsible for bringing in the query and the KV Tiles of shape 128 along the KV length dimension. We use a 3 stage circular buffer of the KV tiles in shared memory, and a separate output staging buffer. The 3rd warp of the producer warp-group is the one responsible for storing the data back to global memory.

This ensures that the consumer warp-groups can immediately move onto the computation of the next tile, overlapping with the stores of the current one, after writing their output in shared memory. And as the layout allows for it, the result of the attention tile OΒ can be un-rotated directly in registers by multiplying it with the HD as described above. The HD is materialised into registers on the fly, rather than statically allocating registers or carving out shared memory space for the same.

We feed both these matrices OΒ and HD into the TF32 tensor core operation, and convert the result into BF16 before staging it in shared memory. The diagram below succinctly captures this pipeline.

We reach up to 1.05 Peta-OPs in attention performance on an RTX PRO 6000 Blackwell including the fused Hadamard un-rotation, with end-to-end (including quantisation and rotation), reaching around 910 TOPS, as summarised in the table below, for a head dimension of 128, and number of heads as 40.

Guided Quantisation of Linear Layers using NVIDIA Model Optimizer

Second to the self attention cost, Q, K and V projections and the feed forward neural networks occupy the most amount of time. It is thus also of interest to quantise this to NVFP4 (FP4 in short). However, not every layer can be quantised, different linear layers have different sensitivities, and treating every one the same can lead to catastrophic loss in quality, rendering the model unusable.

To quantify the error contribution of each layer, we use the NVIDIA Model-Optimizer tool (https:// github.com/NVIDIA/Model-Optimizer), which analyses the sensitivity of each layer in the model, and guides which can be quantised to NVFP4.

Based on the sensitivity score threshold, we quantised 55% of the linear layers into FP4, which represented 80% of the total linear layer FLOPs; the remaining linear layers are kept in FP8 precision. Also not all self-attention steps were run in NVFP4. We selected the ones which could be run in NVFP4 precision by only quantising one at a time, and measuring the impact on the error because of the same.

From the diagram below, the initial and the latter parts of the model seem to be more sensitive to quantisation.

With this setup alongside NVFP4 attention, it de-noises 1.36x faster than FP8 inference mode and 2.39x faster than BF16 inference, while maintaining quality, which is summarised in the table below.

In the below diagram, one can notice the reduced background drift by selectively choosing the FP4 linear layers,

Conclusion

In this work, we present and end to end recipe for NVFP4 inference of video diffusion model, by using NVIDIA Model Optimizer to selectively quantise linear layers to NVFP4, and by augmenting the SageAttention3 algorithm with Hadamard rotation to outlier along the channel dimension to remove the background drift and temporal artefacts from the generated video. The FP4 attention kernel achieves a performance of 1.05 peta-ops, and the end to end speed up of the FP4 inference recipe is 1.36x faster than the FP8 linear layer and attention.

As a further extension of this work, this can be coupled with the work done in Four Over Six (Cook et al., 2025). Four Over Six reduces NVFP4’s rounding error on values near the block maximum by choosing, per block, between scaling the maximum to either 6 or 4. The Hadamard rotation prevents small values next to an outlier from being erased, bringing the block to having values of similar magnitude, which is what Four Over Six targets. Integrating this is left to future work.

This article has been co-authored by research engineers James Briggs and Atharva Dubey.

Atharva Dubey

Atharva Dubey is a research engineer at Synthesia

Go to author's profile

You might also like

View all posts
No items found.
Video template title
Video template
Create video from template