Q4NX
A trellis codebook for GPUs with fast integer math: one multiply turns a state into four small integers, which INT8 tensor cores can use directly.
Why integers
The codebooks on the other pages decode to fp16 values, so the matmul has to run on fp16 tensor cores. Q4NX was built for GPUs whose integer units are faster than their fp16 units (it was developed on the NVIDIA CMP 170HX, where INT8 tensor cores run about 1.5 times faster than fp16). Its values are the integers −15 … 15, which an INT8 tensor core takes as is, and decoding needs no floating-point math at all.
Integers are a coarse grid: only 31 distinct values, against mcg's 10,746. Q4NX gets some of that back by emitting four weights per state with a longer state, so each step chooses among 24K successors (4096 at K = 3). The right panel plots the first two of each successor's four values.
How it decodes
| step | operation |
|---|---|
| 1 | a = (state · 0x83DCD12D) mod 2³², mul1's multiplier |
| 2 | for each byte c: v[c] = (a >> (8c + 4) & 15) + (a >> 8c & 15) − 15 |
| 3 | w = v / √42.5, applied after the matmul |
A sum of two uniform nibbles has a triangular distribution, which the histogram shows. On the GPU, Alex's
INT8 kernel computes the four nibble sums with one IMAD: hi + lo = byte − 15·hi.
Unlike the tail-biting codebooks, a Q4NX tile does not wrap: the bits before a tile's first step read as zeros.
Sources
- The format spec: AlexBrandes/exllamav3, doc/q4nx.md
- The port in GPTQModel (
gptqmodel/exllamav3/q4nx.py), which adds a 3.5-bit width - A release: codebrandes/GLM-5.3-Flash-Q4NX-2.6bpw
Things to try
- Set
K = 2.5: the state grows to 22 bits and each step chooses among 1024 successors. - Use only the low nibble of each byte and watch the histogram turn flat.