llm-decode-kernels

End to end: Qwen2.5-1.5B-Instruct

All attention and MLP projections use round-to-nearest 4-bit weights (group 128) and our kernels. Embeddings, lm_head, attention (SDPA) and RoPE stay in fp16 on both sides. Both sides run the same small runner under CUDA graphs with a static KV cache, so the only difference is the kernels.

Decode speed

decode tokens/s

Model size (L4)

On the smaller model the fp16 lm_head is a bigger share of each token, so the same kernels help less, and round-to-nearest 4-bit costs more quality.

modelfp16 tok/sours tok/sspeedupfp16 ppl4-bit ppl
Qwen2.5-0.5B-Instruct128.4178.81.39x15.7919.09
Qwen2.5-1.5B-Instruct59.5118.21.99x10.6511.90

Where a decode token's time goes

The swapped layers are timed alone in their own CUDA graph; the rest is the full step minus that. The fp16 lm_head (151936 x 1536) alone reads 0.47 GB per token, so it becomes the next thing to fix.

breakdown

L4

backenddecode tok/sswapped layers ms/tokenprefill tok/s (T: tok/s)WikiText-2 ppllinear weights GB
fp1659.511.36128: 5743, 512: 11782, 2048: 1240910.6542.62
ours118.23.28128: 7683, 512: 11573, 2048: 1234611.9000.70
ours_cuda114.43.62128: 7650, 512: 11545, 2048: 1226211.9000.70
w4_ref---11.9010.70
ours_fp891.85.64128: 7877, 512: 12173, 2048: 1288910.7191.31

Runner check against Hugging Face: max abs logit difference 0.034 on the prompt; perplexity 10.654 vs HF 10.654. Greedy tokens are identical for the first 14 of 32 steps, then a near-tie flips and the texts drift apart (expected from fp16 rounding order).

Greedy outputs (L4)

Greedy decoding, cut at 64 new tokens. The 1.5B model gets dates wrong in both versions; 4-bit changes the wording, not the gist.

Explain in two sentences why LLM decoding is memory-bound.
fp16
LLM decoding is memory-bound because it requires processing large amounts of data, which is stored in memory, to generate the output. The more data that needs to be processed, the more memory is required, and the longer it takes to decode the output.
4-bit, our kernels
LLM decoding is memory-bound because it requires the model to maintain and utilize a large amount of information to generate text, making it computationally expensive and memory-intensive. This is because the model must store and recall a vast amount of data to produce the desired output, which limits its scalability and efficiency.
Write a haiku about a GPU that runs out of memory.
fp16
GPU cries in vain, Memory exhausted, no more, Silence fills the space.
4-bit, our kernels
GPU cries in vain, Memory's limit reached, Overflowing streams.
What is the capital of Australia, and why is it not Sydney?
fp16
The capital of Australia is Canberra. Sydney is the most populous city in Australia, but it is not the capital. Canberra was established in 1908 as the capital of the Australian Commonwealth, and it is located in the Australian Capital Territory.
4-bit, our kernels
The capital of Australia is Canberra. Canberra is not Sydney because: 1. Canberra was established in 1911 as the planned capital of the Australian Commonwealth, while Sydney was founded much earlier in 1813. 2. Canberra was designed to be a planned city, with a specific layout and purpose, whereas

H100

backenddecode tok/sswapped layers ms/tokenprefill tok/s (T: tok/s)WikiText-2 ppllinear weights GB
fp16283.12.32128: 21500, 512: 65072, 2048: 10824210.6542.62
ours397.91.31128: 16292, 512: 48927, 2048: 7970611.9000.70
ours_cuda338.61.74128: 16400, 512: 48708, 2048: 7996111.9000.70
w4_ref---11.9010.70

Runner check against Hugging Face: max abs logit difference 0.029 on the prompt; perplexity 10.654 vs HF 10.654. Greedy tokens are identical for the first 14 of 32 steps, then a near-tie flips and the texts drift apart (expected from fp16 rounding order).

Greedy outputs (H100)

Greedy decoding, cut at 64 new tokens. The 1.5B model gets dates wrong in both versions; 4-bit changes the wording, not the gist.

Explain in two sentences why LLM decoding is memory-bound.
fp16
LLM decoding is memory-bound because it requires processing large amounts of data, which is stored in memory, to generate the output. The more data that needs to be processed, the more memory is required, and the longer it takes to decode the output.
4-bit, our kernels
LLM decoding is memory-bound because it requires the model to maintain and utilize a large amount of information to generate text, making it computationally expensive and memory-intensive. This is because the model must store and recall a vast amount of data to produce the desired output, which limits its scalability and efficiency.
Write a haiku about a GPU that runs out of memory.
fp16
GPU cries in vain, Memory exhausted, no more, Silence fills the space.
4-bit, our kernels
GPU cries in vain, Memory's limit reached, Overflowing streams.
What is the capital of Australia, and why is it not Sydney?
fp16
The capital of Australia is Canberra. Sydney is the most populous city in Australia, but it is not the capital. Canberra was established in 1908 as the capital of the Australian Commonwealth, and it is located in the Australian Capital Territory.
4-bit, our kernels
The capital of Australia is Canberra. Canberra is not Sydney because: 1. Canberra was established in 1911 as the planned capital of the Australian Commonwealth, while Sydney was founded much earlier in 1813. 2. Canberra was designed to be a planned city, with a specific layout and purpose, whereas