Optimizing Video Diffusion Models by Utilizing End-to-End NVFP4 Inference A new end-to-end NVFP4 inference recipe for video diffusion models, built with NVIDIA Model Optimizer to selectively quantize linear layers to NVFP4 and SageAttention3 augmented with Hadamard rotation, runs 1.36x faster than FP8 linear layers and attention, with the FP4 attention kernel reaching 1.05 peta-ops. The Hadamard rotation addresses outliers along the channel dimension that mean smoothing alone cannot absorb when a channel's value and sign change from token to token, removing background drift and temporal artifacts from generated video. Blog https://www.synthesia.io/blog Optimizing Video Diffusion Models by Utilizing End-to-End NVFP4 Inference 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 QK