# Hadamard FP8 quantization with head-weight scaling (`hadamard_fp8_quant_weight_scale`) | ServingStudio Kernel Library

Rotate each query head of a wider GEMM row by a Hadamard transform, quantize it to FP8 with one power-of-two scale, and scale the head weights by it, in one launch.

A DSA indexer rotates each query head by the normalized Walsh-Hadamard matrix and quantizes it to FP8 E4M3 before scoring cached keys, and scales each head's weight by that head's quant scale. When the query projection is one column span of a concatenated GEMM's output, this kind reads the span in place (row stride lead_cols + num_heads·head_dim). The rotated head is rounded to BF16 first; its absolute maximum, floored at 1e-4, sets a scale rounded up to a power of two (UE8M0); the head divided by it is clamped to ±448. The FP32 head weights (one per token and head) are multiplied by the scale and by head_dim^-0.5 · num_heads^-0.5. FP8 heads, FP32 scales and FP32 scaled weights are written in one launch.

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

## Formula

- `y = BF16(x · H_head_dim / √head_dim) per head`
- `scale = 2^⌈log2(max(|y|, 1e-4) / 448)⌉ per head`
- `q = clamp(y / scale, −448, 448) as FP8 E4M3`
- `w' = w · scale · head_dim^-0.5 · num_heads^-0.5`
- `GB/s = num_tokens · num_heads · (head_dim · (BF16 + FP8 bytes) + 3 · 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. One launch per call; three warm-up calls run first. Before timing, the outputs are checked byte for byte against the vLLM fork's fwht128_quant_fp8 on a contiguous copy of the span plus the weight scale, and the FP8 heads against a float64 dense-Hadamard reference.

## Caveats

- The triton backend has its head geometry compiled in (32 heads of 128) and refuses any other; lead_cols is free.
- The triton backend forms input offsets in int32, so num_tokens times the row width (lead_cols + num_heads·head_dim) must stay below 2^31: about 104,000 tokens at a 20,480-column row. Larger calls are refused.

## Arguments

| Argument | Type | Unit | Meaning |
| --- | --- | --- | --- |
| `num_tokens` | number | tokens | Input rows, one per token. |
| `num_heads` | number | heads | Indexer query heads per token. |
| `head_dim` | number | elements | Elements per head; also the Hadamard transform size. |
| `lead_cols` | number | elements | Columns of each input row before the query heads (the other projections' outputs of the concatenated GEMM); the row holds lead_cols + num_heads·head_dim columns. |
| `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

- `triton`: A repo-vendored Triton kernel, 32 heads per program: the vLLM fork's fwht128_quant_fp8 butterflies on strided loads, plus the weight scale. 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.

## Measured rows

68 rows in all.

| GPU | Backend | Precision | Rows |
| --- | --- | --- | --- |
| NVIDIA B200 | `triton` | `bf16` | 68 |

## 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`)

## API

- This kind: https://servingstudio.cs.washington.edu/api/public/v1/kernels/hadamard_fp8_quant_weight_scale
- Measured rows: https://servingstudio.cs.washington.edu/api/public/v1/kernels/hadamard_fp8_quant_weight_scale/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_weight_scale/configs

---

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