# Hadamard rotation and FP8 quantization (`hadamard_fp8_quant`) | ServingStudio Kernel Library

Rotate each row by a Hadamard transform, then quantize it to FP8 with one power-of-two scale.

Before a sparse-attention indexer scores cached keys, each query head is multiplied by the normalized Walsh-Hadamard matrix of its width and quantized to FP8 E4M3. The rotated row is rounded to BF16 first, as an unfused rotation would store it; its absolute maximum, floored at 1e-4, sets one scale per row rounded up to a power of two (UE8M0), and the row divided by that scale is clamped to ±448. The FP8 rows and the FP32 scales are written in one launch.

Category: Quantization. Interactive page: https://servingstudio.cs.washington.edu/kernels.html?kind=hadamard_fp8_quant. All kernel kinds: https://servingstudio.cs.washington.edu/kernels.md.

## Formula

- `y = BF16(x · H_head_dim / √head_dim)`
- `scale = 2^⌈log2(max(|y|, 1e-4) / 448)⌉ per row`
- `q = clamp(y / scale, −448, 448) as FP8 E4M3`
- `GB/s = num_rows · (head_dim · (BF16 bytes + FP8 bytes) + 4) / time`

## How it is measured

GPU kernel time from CUPTI activity records, averaged over repeated launches in one capture. The L2 cache is flushed before each launch, so the numbers are cold-cache times. The call is one Triton launch; output allocation is outside the counted kernel time.

## Caveats

- The vLLM-fork callable takes only head_dim = 128.
- GB/s counts logical input, FP8 output and scale bytes, not physical memory transactions.

## Arguments

| Argument | Type | Unit | Meaning |
| --- | --- | --- | --- |
| `num_rows` | number | rows | Rows rotated and quantized together (tokens times heads). |
| `head_dim` | number | elements | Elements in each row; also the Hadamard transform size. |
| `input_dtype` | dtype |  | Element type of the input rows. |

## Metrics

- Time (`time_ms`, ms)
- Throughput (`tflops`, TFLOPS)
- Memory bandwidth (`memory_bandwidth_gbps`, GB/s)
- Energy (`energy_j`, J)

## Backends

- `vllm_triton`: The vLLM fork's fwht128_quant_fp8 Triton call: a 128-point Hadamard butterfly and per-row UE8M0 FP8 quantization in one launch, 32 rows per program. dtypes `bf16`, compute capability 8.9 or newer, GPUs H100-SXM5-80GB, H100-PCIe-80GB, H200-SXM-141GB, B200-SXM-180GB, B300-SXM-288GB, GB200-Superchip, H800-SXM5-80GB, H20-SXM-96GB, L40, L40S, L4. Source: https://github.com/vllm-project/vllm/blob/main/vllm/models/glm5next/nvidia/ops/kpool_compress.py

## Measured rows

72 rows in all.

| GPU | Backend | Precision | Rows |
| --- | --- | --- | --- |
| NVIDIA B200 | `vllm_triton` | `bf16` | 72 |

## Used by these deployments

- [GLM-5.3-Flash NVFP4: ServingStudio design: DP attention, KDA TP groups, fused EP MoE, DFlash speculative decoding](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash-NVFP4/glm53_flash_nvfp4_dp_attn_kda_tp_fused_ep_moe_dflash2.md) (`GLM-5.3-Flash-NVFP4/glm53_flash_nvfp4_dp_attn_kda_tp_fused_ep_moe_dflash2`)
- [GLM-5.3-Flash NVFP4: vLLM, DP attention, EP MoE](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_dp_attn_ep_moe.md) (`GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_dp_attn_ep_moe`)
- [GLM-5.3-Flash NVFP4: vLLM, DP attention, EP MoE, DFlash speculative decoding](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_dp_attn_ep_moe_dflash2.md) (`GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_dp_attn_ep_moe_dflash2`)
- [GLM-5.3-Flash NVFP4: vLLM, TP attention, EP or TP MoE](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_kda_dsa_moe.md) (`GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_kda_dsa_moe`)
- [GLM-5.3-Flash NVFP4: vLLM, PP](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_pp_kda_dsa_moe.md) (`GLM-5.3-Flash-NVFP4/glm53_flash_vllm_nvfp4_pp_kda_dsa_moe`)
- [GLM-5.3-Flash: vLLM, DP attention, EP MoE](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash/glm53_flash_vllm_fp8_dp_attn_ep_moe.md) (`GLM-5.3-Flash/glm53_flash_vllm_fp8_dp_attn_ep_moe`)
- [GLM-5.3-Flash: vLLM, TP attention, EP or TP MoE](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash/glm53_flash_vllm_fp8_kda_dsa_moe.md) (`GLM-5.3-Flash/glm53_flash_vllm_fp8_kda_dsa_moe`)
- [GLM-5.3-Flash: vLLM, PP](https://servingstudio.cs.washington.edu/models/GLM-5.3-Flash/glm53_flash_vllm_fp8_pp_kda_dsa_moe.md) (`GLM-5.3-Flash/glm53_flash_vllm_fp8_pp_kda_dsa_moe`)

## API

- This kind: https://servingstudio.cs.washington.edu/api/public/v1/kernels/hadamard_fp8_quant
- Measured rows: https://servingstudio.cs.washington.edu/api/public/v1/kernels/hadamard_fp8_quant/rows (filter by any column, such as `?gpu=NVIDIA%20H200`; `format=csv` for CSV)
- Configs the public deployments ask of it: https://servingstudio.cs.washington.edu/api/public/v1/kernels/hadamard_fp8_quant/configs

---

This page as Markdown: https://servingstudio.cs.washington.edu/kernels/hadamard_fp8_quant.md. A guide to the whole site for AI agents: [llms.txt](https://servingstudio.cs.washington.edu/llms.txt).
