On a single RTX PRO 6000 Blackwell Server Edition (96 GB), our optimized Qwen3.8-27B NVFP4 setup reaches its first token on a cold 128K-token prompt in 11.4 seconds, compared with 18.4 seconds for the strongest public setup we could find and tune. That reduces time to first token (TTFT) by 38%, or 42% against stock vLLM 0.31.
We wanted to see how far we could reduce the time spent processing long prompts, so we spent about 12 hours with our agent swarm working on prefill. The gains grew with context length, from 4% at 16K to 38% at 128K against tuned vLLM, with most of the improvement coming from changes to attention, kernel fusion and chunk size. The fastest setup uses FP8 attention for later prompt positions; keeping BF16 attention throughout still brings TTFT down to 14.7 seconds without that additional precision change.
11.4 seconds at 128K, cold, one request. The strongest public setup we could find and tune took 18.4 seconds. Our recipe uses FP8 attention for the later positions of the prompt. With exact attention (BF16 at every position), it takes 14.7 seconds in the best run (14.8 s on average across three runs). We reached this in about 12 hours with our agent swarm.
Time to first token on a cold 128K-token prompt
Seconds, best run of each
- MagniFP8 attention past position 8,19211.4 s
- Magni, exact attentionBF16 attention at every position14.7 s
- vLLM 0.33, tunedthe strongest public setup we could find and tune18.4 s
- SGLang19.5 s
- vLLM 0.31, stock19.6 s
Benchmark setup
We measured cold-prompt TTFT with one request at a time and temperature 0. The prompt lengths are 4,125, 16,413, 32,797, 65,565 and 130,729 tokens, labeled 4K through 128K below; the prefill tables report the best run for each setup.
We didn’t benchmark concurrent serving or prefix-cache reuse.
Our runs used DFlash2 speculative decoding, where a smaller model guesses several tokens and the main model checks them in one step, keeping only what it would have written itself (apart from floating-point rounding). This mostly speeds up decode, and although we tried adding it to the strongest public baseline too, it made TTFT worse: 18.78 s at 128K instead of 18.353 s. We kept the baseline’s faster configuration for the comparison.
We compared against three public setups of vLLM and SGLang:
- vLLM 0.33, tuned: the strongest public setup we could find and tune. The FLASH_ATTN backend, up to 32,768 tokens per step, a BF16 KV cache and the public NVFP4 checkpoint.
- vLLM 0.31, stock: FlashInfer attention, a BF16 KV cache and 8,192-token chunks.
- SGLang: FlashInfer attention, a BF16 KV cache and 16,384-token chunks.
Restarting the server with identical settings moved timings by up to about 1.5%, so comparisons across server boots need some care, particularly where the measured differences are small.
Where the TTFT advantage grows
Here’s what ended up in the final recipe: FP8 attention for positions above 8,192 and cuDNN BF16 attention below, all linear projections in FP4, seven fused kernels, 6,912-token chunks and an FP8 KV cache. “Exact attention” uses the same setup but runs cuDNN BF16 attention everywhere. The 32K, 64K and 128K numbers came from one clean boot, three runs each. The 4K and 16K numbers came from an earlier boot of the same recipe (three to six runs).
| Prompt | Magni | Magni, exact attention | vLLM 0.33, tuned | vLLM 0.31, stock | SGLang |
|---|---|---|---|---|---|
| 4K | 0.252 | — | 0.273 | 0.291 | 0.305 |
| 16K | 1.092 | — | 1.140 | 1.273 | 1.285 |
| 32K | 2.030 | 2.201 | 2.634 | 2.839 | 2.837 |
| 64K | 4.605 | 5.405 | 6.555 | 7.019 | 7.078 |
| 128K | 11.404 | 14.740 | 18.353 | 19.563 | 19.527 |
The largest reduction comes at 128K, where TTFT falls from 18.353 s with tuned vLLM to 11.404 s with our recipe. That’s about seven seconds less waiting before the response begins, a 38% reduction or a 1.61× speedup. Against stock vLLM’s 19.563 s, the same result is a 42% reduction or a 1.72× speedup.
| Prompt | Speedup over vLLM 0.31, stock | Speedup over vLLM 0.33, tuned | Less waiting than vLLM 0.33, tuned |
|---|---|---|---|
| 4K | 1.15× | 1.08× | 8% |
| 16K | 1.17× | 1.04× | 4% |
| 32K | 1.40× | 1.30× | 23% |
| 64K | 1.52× | 1.42× | 30% |
| 128K | 1.72× | 1.61× | 38% |
The advantage is narrower at 4K and 16K, where we measured 8% and 4% less waiting than tuned vLLM. Those runs came from a different boot than the baseline, and the roughly 1.5% variation between identical server starts could account for some of the difference.
From 32K onward, the reduction grows from 23% to 30% and then 38%. For applications passing large documents or code context to a model, this is where the optimization has the clearest measured benefit. The BF16-attention variant also improves 128K TTFT by 1.25× against tuned vLLM, so the advantage doesn’t depend entirely on switching to FP8 attention.
Why long prompts take longer
Prefill processes the input in batches of tokens, while decode generates the answer one token at a time, or several at once with speculative decoding. A 128K-token prompt corresponds to roughly 100,000 English words. At that length, processing the input dominates TTFT in our single-request setup.
Two types of computation account for much of the work. The linear projections run as matrix multiplications (GEMMs), applying the model’s weights to each token, so their cost grows roughly in proportion to prompt length. Attention lets tokens draw on information from earlier positions, and its cost depends on the type of layer.
Of Qwen3.8-27B’s 64 layers, 48 use Gated DeltaNet, whose work also scales roughly with prompt length. The remaining 16 use full attention, comparing each token with every preceding token. Doubling the input therefore roughly quadruples the work in those full-attention layers, which helps explain why the gains grow with context length.
Each token looks back at every token before it
Comparisons in one attention head, at each prompt length in this post
4,125tokens
8.5 millioncomparisons
16,413tokens4.0× the 4K prompt
135 millioncomparisons15.8× the 4K prompt
32,797tokens8.0× the 4K prompt
538 millioncomparisons63.2× the 4K prompt
65,565tokens15.9× the 4K prompt
2.1 billioncomparisons253× the 4K prompt
130,729tokens31.7× the 4K prompt
8.5 billioncomparisons1,004× the 4K prompt
At 128K, full attention accounted for enough of the runtime to make it a major optimization target. Its performance depends on both the GPU kernel and how the serving engine feeds it work. We tested attention implementations from Triton, FlashInfer, FlashAttention-2 and NVIDIA’s cuDNN, while varying the number of tokens processed per chunk.
Precision was another variable. The model’s weights are stored in NVFP4, NVIDIA’s 4-bit format with a scale for each small block of values, while attention and its stored keys and values, the KV cache, can use different formats. BF16 uses 16 bits per value and FP8 uses eight, so FP8 reduces storage and can improve compute throughput. Whether that translates into lower latency depends on the kernel, and reducing precision also needs a quality check.
From 47.7 seconds to 11.4 seconds
Our first attempt, using Triton attention, an FP8 KV cache and 1,024-token chunks, took 47.7 seconds at 128K, more than twice the time of stock vLLM. Profiling showed us where that time was going and led to the changes below, all measured with speculation on. Some steps came from different server boots, so the smaller differences need care.
Time to first token at 128K, step by step
Seconds
- vLLM 0.33, tuned: 18.4 s
- Start: Triton attention, FP8 KV cache, chunk 1,02447.7 s
- 1. FlashInfer attention, chunk 8,19224.2 s
- 2. A BF16 KV cache20.0 s
- 3. All linear projections in FP418.8 s
- 4. Hybrid attention, fused kernels, chunk 6,912, FP8 KV cachecuDNN BF16 attention below position 8,192, FP8 above it11.4 s
- FlashInfer attention and larger chunks: 47.7 s to 24.2 s. Profiling led us to replace Triton attention with FlashInfer and increase the chunk size from 1,024 to 8,192 tokens, nearly halving 128K TTFT. Other runs of this configuration landed between 24 and 27 seconds.
- A BF16 KV cache: 24.2 s to 20.0 s. With FlashInfer, switching the KV cache from FP8 to BF16 saved 4.2 seconds at 128K. Using twice the storage was actually faster for this kernel.
- All linear projections in FP4: 20.0 s to 18.8 s. Running every linear projection in FP4 brought us down to 18.8 seconds, right around tuned vLLM’s 18.353 seconds.
- Hybrid attention, fused kernels and a smaller chunk: 18.8 s to 11.4 s. This is where the largest remaining gain came from. We kept exact BF16 attention through cuDNN for positions below 8,192 and used FP8 above that. Later tokens have much more context to look back at, so most of the full-attention work happens in those later positions. We also added seven fused kernels, combining several GPU operations into one pass so we spend less time launching separate programs and moving intermediate results around. We changed the chunk size to 6,912 and brought back the FP8 KV cache required by our FP8 attention path. Together, this took us from 18.8 to 11.4 seconds. The quality checks below show what we know about that tradeoff.
The final recipe
| Part | Setting |
|---|---|
| Weights | NVFP4 |
| Linear projections | FP4 |
| Attention, prompt positions below 8,192 | BF16, cuDNN |
| Attention, prompt positions above 8,192 | FP8 |
| KV cache | FP8 |
| Chunk | 6,912 tokens |
| Fused kernels | seven |
| Speculative decoding | DFlash2 |
What the quality tests tell us
The performance result has two parts: gains from changes to the serving implementation, and an additional gain from FP8 attention. We evaluated several changes separately, so each quality result needs to be read alongside the configuration it tested. Together, these checks don’t establish quality equivalence for the complete final recipe.
We first compared Triton and FlashInfer attention with an FP8 KV cache and temperature 0, isolating the attention switch in step 1.
HumanEval+ has 164 Python problems with extended tests, MBPP has 500 programming problems, and GSM8K has 1,319 maths word problems. FlashInfer solved 147 vs 145, 367 vs 362, and 1,252 vs 1,250 respectively.
Short-context quality, temperature 0
Problems solved, percent
- Triton, FP8 KV cache
- FlashInfer, FP8 KV cache
- HumanEval+164 problems
- MBPP500 problems
- GSM8K1,319 problems
We didn’t detect a quality loss from switching to FlashInfer: the scores were close enough that repeat runs of the same configuration varied by about as many problems as the gap between the two kernels. These short-context tests only cover that first attention change, though, and we don’t have a separate quality run for all-FP4 projections. The seven fused kernels passed their own check, producing token-for-token identical outputs at temperature 0 with or without the fusions.
We also ran RULER, a benchmark that checks whether a model can retrieve and keep track of information buried in long prompts. These scores are from FlashInfer with an FP8 KV cache, not the final recipe or cuDNN attention.
| Prompt | Score | Cases |
|---|---|---|
| 4K | 94.0% | 52 |
| 8K | 93.3% | 52 |
| 16K | 92.9% | 52 |
| 32K | 92.7% | 52 |
| 64K | 94.6% | 26 |
| 128K | 98.1% | 26 |
| 256K | 12 of 12 | 12 |
FP8 attention accounts for the remaining reduction from 14.7 to 11.4 seconds, so we tested it against BF16 attention on the same server boot, pairing identical prompts across several long-context tasks as well as RULER. The chart shows FP8 minus exact-attention scores, with uncertainty intervals.
FP8 attention minus exact attention, long-context panel
Score difference in points, zero is no change
- 32K440 cases−0.7−2.6 to +1.2
- 64K260 cases−2.3−5.9 to +1.4
- 128K44 cases, a small sample+0.1−10.6 to +10.8
- AgentLongBench, 128K80 cases+2.5−6.3 to +11.3
At 32K, the measured difference was −0.7 points, with an interval that includes zero. At 64K, FP8 scored 2.3 points lower, with an interval from −5.9 to +1.4; that sample therefore can’t rule out a loss of several points, even though it doesn’t establish one either. The 128K samples are too small for a strong conclusion, and we don’t have FP8-attention quality measurements at 16K or 256K.
We did one more check with 40 variable-tracking cases at 64K, repeated over three server boots. The final recipe’s scores minus stock were −0.035, +0.030 and +0.080 (out of 1). We didn’t see an FP8-specific regression, although a 40-case test only resolves differences of about ±0.2, so this is a fairly coarse check.
For workloads where that uncertainty is unacceptable, the BF16-attention variant reaches 14.7 seconds at 128K, or 1.25× the speed of tuned vLLM, without the additional precision change in attention. This still leaves the other untested parts of the recipe needing broader quality validation.
HumanEval doesn’t reach the positions where FP8 attention kicks in, so it can’t validate that change.
Decode performance and workload dependence
Replacing Triton attention with FlashInfer also improved long-context decode: at 128K, throughput rose from 25 to 127 tokens per second with an FP8 KV cache, more than a fivefold increase. One speculative draft-and-check round took about 20 ms at 3.5K and 24.6 ms at 130K, a relatively small increase despite the much longer context.
| Prompt | Triton, FP8 KV cache | FlashInfer, FP8 KV cache | Change |
|---|---|---|---|
| 4K | 165 | 162 | −2% |
| 16K | 100 | 163 | +63% |
| 32K | 75 | 160 | +113% |
| 64K | 44 | 150 | +241% |
| 128K | 25 | 127 | +408% |
The same change was less effective on short prompts. On a mixed panel of 34 short prompts, FlashInfer was 3.9% slower, at 344.0 tokens per second against Triton’s 357.9, and we haven’t isolated the cause. Speculative decode performance also depends on how often the target model accepts the drafter’s candidates, which varies by workload, so these results shouldn’t be treated as general throughput figures.
The remaining headroom
We originally wanted a 4× speedup over tuned vLLM, so we estimated how far faster GPU code alone could take us. We removed all attention time from the estimate and left only the matrix multiplications (GEMMs), running at their measured NVFP4 peak on this GPU. Even with attention costing nothing, that estimate is slower than the 4× target at every prompt length up to 128K.
| Prompt | vLLM 0.33, tuned | 4× target | Floor, no attention | Magni |
|---|---|---|---|---|
| 4K | 0.273 | 0.068 | 0.176 | 0.252 |
| 16K | 1.140 | 0.285 | 0.705 | 1.092 |
| 32K | 2.634 | 0.658 | 1.410 | 2.030 |
| 64K | 6.555 | 1.639 | 2.820 | 4.605 |
| 128K | 18.353 | 4.588 | 5.624 | 11.404 |
Where 11.4 s sits at 128K
Seconds
- 4× tuned vLLM: 4.6 s
- vLLM 0.33, tuned18.4 s
- Magni11.4 s
- Floor, no attentionthe GEMMs alone at their measured NVFP4 peak5.6 s
At 128K, tuned vLLM takes 3.3× as long as that floor and we take 2.0×, which means we’ve closed about 55% of the gap between the baseline and this estimate. Real attention will always take some time, so the achievable limit is higher and we’ve covered a larger share of the gap we could realistically close.
256K is interesting, though. There, the 11.261-second floor is below the 14.794-second 4× target, so the same argument doesn’t rule out a 4× result. We don’t have a clean 256K measurement of the final recipe yet.
What didn’t work
Along the way, we ran into a few bugs and tried several changes that never made it into the final setup.
Fusions that were not running
One of the first fused kernels we added wasn’t even running. We’d hooked it into a path the serving engine never used. vLLM’s default settings sent prefill through a different fused path. A smoke test caught it before benchmarking, and we fixed the hook. We also tried a norm+quant fusion (normalization and quantization together), but it was 0.4% slower and its outputs weren’t bit-identical. We left it out. CUDA graphs for prefill were also slower at 4K. For the seven fusions we did keep, we verified in the logs that they actually ran.
FP4 attention
We experimented with FP4 attention as well. In our emulation, the worst layer had 1.8 to 2.4 times the error of the FP8 recipe. There’s also no FP4 kernel for this attention shape on sm120, the GPU architecture we’re using. We stopped there rather than building the final recipe around it.
Prompt pruning
We also experimented with dropping parts of the prompt before the model processes it. The pruned 128K prefill finished in 1.4 seconds, versus 16.2 seconds when that same method processed the full prompt. That’s a big reduction in work, but it’s not comparable to a full cold prefill: we’d removed input tokens. On a retrieval-heavy quality panel, the score difference was +0.053 at 128K (interval −0.050 to +0.161, 88 cases) and −0.062 at 32K, with losses on aggregation and variable-tracking tasks. We didn’t take this approach further.
Drafter fine-tuning
We also tried fine-tuning the smaller model used for speculative decoding, expecting an 8.1% improvement based on the forecast. Instead, we measured a 3.1% slowdown and found that 21 of 34 outputs on our panel had changed, so we paused the training work, with the cause still unclear.
The FlashInfer decode loss on short prompts
As mentioned earlier, FlashInfer was 3.9% slower on our mixed short-prompt panel. We haven’t nailed down the cause, and that’s still something worth investigating.
What carries over
The clearest result is at long context: a cold 128K-token prompt reaches its first token about seven seconds sooner than with tuned vLLM on this GPU. The gain narrows at shorter lengths, and the fastest attention path still needs broader quality validation, so applying this recipe elsewhere means checking both latency and quality on the workload that will actually run.
A few findings from the optimization process are worth carrying into that work:
- Profile before tuning. Profiling led us to a change that almost halved TTFT at 128K in one step.
- Measure every precision change. FlashInfer with a BF16 KV cache beat FP8 by 4.2 seconds. Fewer bits don’t automatically mean faster.
- Put the low precision where the work is. On a 128K prompt, most full-attention work is past position 8,192. Using FP8 there took us from 14.7 to 11.4 seconds while keeping BF16 for the earlier positions.
- Test a long-context recipe on long contexts. Short benchmarks can’t tell you what happens at positions they never reach.
If you’re running long prompts on your own GPUs, tell us about your setup. We’d like to see how much of this carries over.
