Efficient model architectures create new opportunities for inference optimization. They also change where execution time goes. Qwen Sparse Attention (QSA) introduces an indexing pipeline. Wider residual streams add projections and memory traffic. Multi-token prediction (MTP) can reduce the number of target-model passes per output token in speculative decoding, but adds draft computation and speculative state management.
This post explains how we optimized Qwen3.8-Flash-Next in TokenSpeed: making sparse selection and attention efficient, fusing computation across residual boundaries, reducing repeated work during MTP, and using programmatic dependent launch to overlap independent preparation between the remaining kernels.
Model architecture
Qwen3.8-Flash-Next is a multimodal mixture-of-experts (MoE) model and an early preview of the Qwen4 architecture. The main model has 125 billion parameters, with 6 billion activated per token. The release also includes 51 billion n-gram embedding parameters and a 4-billion-parameter MTP module. For background, see Qwen’s official introduction.

Figure 1. Qwen3.8-Flash-Next model architecture and multi-token prediction.
Three architectural features shape the inference workload:
- Hybrid attention. Gated DeltaNet (GDN) summarizes history through recurrent state. QSA selects relevant context at micro-block granularity.
- Four-branch Gated Residual. Dynamic gates control how sublayers read from and update four residual branches.
- N-gram embeddings. Local token context indexes an embedding table, adding model capacity with little computation.
TokenSpeed implements the model in the qwen4_exp model family, including per-layer embedding (PLE) and a single-layer draft model for MTP.
Serving benchmarks
We benchmarked TokenSpeed on 4 NVIDIA GB300 GPUs using frozen SWE-Smith conversations and AgentX. SWE-Smith reports a per-user output rate calculated from mean time per output token. AgentX reports P90 interactivity.
Both benchmarks use NVFP4 model quantization (using the nvidia/Qwen3.8-Flash-Next-NVFP4), BF16 activations and key-value (KV) caches, tensor parallelism (TP) of 4, expert parallelism (EP) of 4, FlashInfer TensorRT LLM MoE, 3 MTP draft steps, and 4 verification tokens. To accelerate prefill, set TOKENSPEED_QWEN4_EXP_QSA_MAX_LOGITS_MB=2048 in the server environment, especially at larger batch sizes.
SWE-Smith conversations
Each SWE-Smith conversation has between 10 and 15 turns. We configure the first turn with 50,000 input tokens and each subsequent turn with 800 new input tokens. We set the output limit to 500 tokens per turn.
Figure 2 shows how the per-user output rate and throughput per GPU change as the number of concurrent conversations increases. Each label shows the number of concurrent conversations (batch size). The y-axis shows output throughput in tokens per minute per GPU. We calculate this value by multiplying the server’s aggregate output throughput in tokens per second by 60 and dividing by 4.
The x-axis shows the per-user output rate in tokens per second per user. EvalScope measures time to first token (TTFT) from request submission to the first streamed response chunk. For each successful turn, it calculates time per output token (TPOT) as (request latency − TTFT) / (output tokens − 1). TokenSpeed’s agentic benchmark converts the arithmetic mean of these TPOT values to a rate using 1000 / mean TPOT (ms). Each successful turn has equal weight in the mean. This client-side measurement includes scheduling stalls and streaming overhead after the first response chunk.

Figure 2. SWE-Smith output throughput per GPU and per-user output rate across batch sizes.
Increasing the batch size from 1 to 32 raised output throughput from 7,321.5 to 29,005.5 tokens per minute per GPU. The per-user output rate fell from 685.9 to 95.7 tokens per second per user. Measured MTP acceptance length remained stable: 3.231 tokens per iteration at batch size 1 and an average of 3.234 tokens per iteration across the other 5 batch sizes.
To run the SWE-Smith benchmark, use the agentic_bench.sh script on a system with 4 NVIDIA GB300 GPUs and TokenSpeed installed. Ensure that port 8000 is available.
From the TokenSpeed repository root, run the benchmark:
bashbash test/agentic_benchmark/Qwen3.8-Flash-Next/tokenspeed/agentic_bench.sh
The script prepares the dataset, starts the server, tests concurrency levels of 1, 2, 4, 8, 16, and 32, and writes summary.csv to the output directory printed at startup.
AgentX benchmark
AgentX measures aggregate output throughput and interactivity at different request concurrency levels. We tested each level for 60 minutes using Qwen3.8-Flash-Next-NVFP4, FP32 state-space model (SSM) states, a BF16 KV cache, an 8,192-token prefill chunk, a 256K-token context limit, and 3 MTP draft steps with a shared indexer. We configured a synthetic acceptance-length target of 2.32, including the bonus token.
In Figure 3, each label shows request concurrency. The x-axis shows P90 interactivity in tokens per second per user. AgentX calculates this metric as the reciprocal of the 90th percentile of per-request inter-token latency (ITL), excluding TTFT. The y-axis shows aggregate output throughput across all 4 GPUs.

Figure 3. AgentX aggregate throughput and P90 interactivity across concurrency levels.
Increasing concurrency from 1 to 32 raised aggregate output throughput from 202.74 to 1,177.20 tokens/s, while P90 interactivity fell from 374.64 to 33.95 tokens/s/user.
How the architecture shapes decoding costs
At small batch sizes, decoding time depends on more than floating-point computation. Loading weights, preparing metadata, moving intermediate tensors, launching kernels, and waiting for dependencies also affect latency. Qwen3.8-Flash-Next exposes several sources of this overhead:
| Component | Supporting work |
|---|---|
| QSA | History compression, scoring, top-k selection, and cache-slot mapping |
| Gated Residual | Branch normalization, gate projections, mixing, and residual updates |
| PLE | Context indexing, embedding access, short convolution, and state updates |
| MTP | Draft execution, verification, and accepted-state commit |
| GDN | Convolution, gating, recurrent-state access, and normalization |
We address these costs in order:
- Remove work whose result is no longer needed.
- Reuse calculations within their valid lifetime.
- Fuse neighboring operations to reduce launches and intermediate traffic.
- Overlap independent preparation while preserving data dependencies.
Sparse attention optimizations
Selecting context takes work too: history compression, block scoring, top-k selection, and cache-slot mapping all contribute to latency. TokenSpeed therefore optimizes the selection pipeline as well as attention itself.
QSA groups tokens into micro-blocks of 4 consecutive tokens and computes a compressed index key for each block. For each query, the indexer selects up to 512 complete blocks, covering up to 2,048 token positions. QSA also includes tokens in the current incomplete block without top-k selection. This block contains at most 3 tokens, so TokenSpeed reserves 3 additional slots. The selection buffer has a fixed width of 2,051.
TokenSpeed uses the request’s page table to map these logical token positions to physical KV cache slots and masks out invalid entries. Attention then reads the original per-token KV entries rather than the compressed index keys.

Figure 4. The four stages of QSA execution.
Top-k selection over valid blocks
TokenSpeed writes QSA block scores to an FP32 buffer and uses a persistent radix selector to find the k highest-scoring blocks. The selector receives each query’s valid block count, so when the actual context is shorter than the capacity captured in a CUDA Graph, it skips padded columns in the score buffer.
Compressed-key reuse during verification
MTP verification scores consecutive queries against the same compressed history. TokenSpeed groups up to 4 queries from one request and loads each compressed-key tile once for the group. Each query retains its own scores, complete-block frontier, head reduction, and top-k selection. Ragged layouts use 1 query per group.
The scoring tile contains 128 compressed blocks instead of 512. With four 128-dimensional BF16 index heads, a tile shared by 4 queries uses 36,864 bytes of shared memory. The previous tile, which served 1 query, used 132,096 bytes.
| Requests per batch | Previous tile (µs) | Shared-key tile (µs) |
|---|---|---|
| 1 | 6.61 | 2.69 |
| 32 | 157.90 | 31.75 |
These GB300 microbenchmarks measure scoring only. They use 4 queries per request, programmatic dependent launch (PDL), repeated inputs, and effective contexts of about 51,000 to 61,000 tokens. Each CUDA Graph contains 100 calls. Results are medians from 15 replays across three rounds with alternating execution order.
Sparse attention pipeline in CuTe DSL
After block selection, attention reads directly from physical KV cache slots. For supported GB300 configurations, TokenSpeed uses a kernel written in the CuTe domain-specific language (CuTe DSL), specialized for the model’s attention geometry. It handles ordinary decoding and MTP verification with BF16 queries and either BF16 or FP8 E4M3 KV caches.
The diagram abbreviates cooperative thread array (CTA), distributed shared memory (DSM), tensor memory (TMEM), and matrix multiply-accumulate (MMA).

Figure 5. Adaptive sparse attention and asynchronous operand loading in CuTe DSL.
The launch policy uses the amount of independent query-head output work and the GPU’s streaming multiprocessor (SM) count to choose the number of query rows per thread block, splits along the selected context, and operand-buffer slots:
- For small launches, cooperating thread blocks process separate parts of the selected context to expose more parallelism and combine their partial softmax results through distributed shared memory.
- With BF16 KV caches, larger launches can use fewer splits, down to 1. With 1 split, each thread block processes its selected context locally and merges results with 1 warp per head.
- With BF16 KV caches, sufficiently large launches can assign 2 or 4 query rows to one thread block to reuse shared workspace and tensor-memory allocation. Each query retains its own selected slots and softmax state.
Asynchronous gathers load upcoming key and value tiles while separate warps compute query-key and probability-value products on earlier tiles. Another warp group computes softmax, and barriers coordinate tile readiness and buffer reuse.
For the supported selection width of 2,051 slots, the merge processes the final 3 entries, avoiding a mostly empty tensor-core tile. Split clusters combine results through distributed shared memory; unsplit thread blocks merge these entries within each head’s warp.
Metadata and cache preparation
The scoring and attention kernels use metadata to identify valid history and locate KV entries. TokenSpeed generates token positions, request indices, cache locations, and complete-block counts in a single metadata kernel. It shares these results across kernels within the forward scope where they remain valid, reducing repeated metadata preparation.
TokenSpeed also fuses operations during query preparation and cache writes. The compression kernel can normalize index queries and apply rotary position embeddings (RoPE) while compressing history. For FP8 KV caches, the cache writer quantizes KV values and scatters them to their cache locations in the same kernel. These fusions reduce kernel launches and intermediate memory traffic in the QSA pipeline.
Gated Residual fusion
Gated Residual expands the residual stream into four branches and adds learned operations to read and update them. TokenSpeed reduces the resulting overhead by fusing the mixer and, where dependencies allow, combining each residual update with the next normalization.

Figure 6. Four residual branches around attention and mixture-of-experts sublayers.
Residual mixer fusion
The four-branch Gated Residual mixer has 2,560 hidden dimensions per branch and a projection rank of 320. For aligned BF16 or FP16 inputs, one Blackwell CuTe DSL kernel combines the down projection, scaling, sigmoid linear unit (SiLU) activation, up projection, sigmoid gates, and final weighted mean in one launch.

Figure 7. The fused Gated Residual mixer.
Asynchronous operand loads overlap with tensor-core computation. Thread blocks in a split-K cluster combine partial down-projection results before the up projection consumes the activated result. Token count determines tile size, split-K, and pipeline depth. Wider tiles reuse weights across more tokens, and persistent workers reuse temporary storage across tiles. During warmup, the runtime checks kernel occupancy and limits the number of workers so cooperating clusters can run together.
The table compares the fused mixer with the previous portable fallback on a GB300 GPU with 152 SMs (SM103), using BF16 inputs, 324 projection rows, a scale of 1, PDL, and CUDA Graphs after warmup. The speedups apply only to this mixer benchmark.
| Token rows | Portable fallback (µs) | Fused CuTe DSL (µs) | Speedup |
|---|---|---|---|
| 32 | 30.61 | 8.38 | 3.65× |
| 128 | 43.02 | 14.03 | 3.07× |
Eligible inputs with at most 256 token rows automatically use the fused mixer. Larger inputs use the unfused implementation by default.
Residual update and normalization fusion
The residual update produces the input to the next mixer’s normalization:
Here R is the residual stream, O is the sublayer output, a contains injection logits, and w is the normalization weight of the consuming mixer.
Separate kernels write the updated residual R′ to memory and reload it for normalization. A fused kernel computes both in one thread block and stores both outputs.

Figure 8. Separate and fused residual update and normalization.
Both outputs remain necessary: later residual updates consume the unnormalized state, and MTP needs the final residual representation.
Fusion applies only when the updated residual feeds normalization directly. PLE, vision deepstack additions, and required pre-attention or final all-gathers consume the residual before normalization. At those boundaries, the runtime updates the residual before the intervening operation and normalizes it at the consuming mixer.
Reducing work per output token with MTP
MTP can reduce target-model passes per output token by adding draft work. The cost per output token depends on the time spent drafting, verifying, and committing state, divided by the number of tokens produced per round:
Tcommit is the time required to update persistent model state to reflect the accepted token prefix after verification.
TokenSpeed reduces these costs by reusing draft selections, writing verification state directly to its destination, and batching updates to accepted state.
QSA selection reuse across draft steps
Qwen3.8-Flash-Next supports sharing QSA selections across MTP draft steps, which TokenSpeed enables with the index_share_for_mtp_iteration model configuration option. The first draft step selects KV cache slots, and later steps reuse those slots within the same drafting round.

Figure 9. QSA selection reuse within one MTP drafting round.
Later draft steps skip normalization and RoPE for the index query, along with block scoring, top-k selection, and slot mapping. Key compression and state updates still run, and each step computes sparse attention with its current query.
Direct writes to verification buffers
Speculative execution creates temporary states for candidate tokens, and the runtime must retain only the state for the accepted token prefix. TokenSpeed writes state directly from the producing kernels into rollback or commit storage, avoiding intermediate tensors and copies.
During MTP verification, PLE’s n-gram and short-convolution kernels and the QSA compression kernel write to preallocated verification buffers. The PLE short-convolution kernel adds gated values and hidden states, then writes each token’s rollback window directly to verification scratch buffers, which removes a separate, unused final-state output. After verification determines the accepted token counts, one commit kernel uses those counts to update persistent QSA state across layers.
Accepted-state resolution and commit
For GDN and PLE, a fused page-resolution kernel clamps the accepted length, computes the checkpoint position, and looks up the destination page once per state group. A second kernel maps pages to layers and computes source and destination row indices for batched state updates.
PLE copies the shared n-gram context once, then copies local convolution states across layers in one batched launch. GDN uses the resolved rows to copy convolution state and either copy or replay recurrent state, depending on the configuration. QSA retains its own cross-layer commit kernel.
State ownership during CUDA Graph replay
TokenSpeed’s cache subsystem owns the persistent GDN, PLE, and QSA request caches, and each backend owns its transient verification workspace. After verification, the runner calls a shared commit entry point, and each consumer applies the accepted result to its own state.
CUDA Graph replay updates GPU tensors without rerunning the Python code used during capture, so state commit must rely on live acceptance data and stable workspace ownership.
Kernel preparation overlap with PDL
After reuse and fusion reduce the work, PDL can overlap independent preparation between the remaining kernels. It allows a dependent kernel to become eligible to launch before its producer finishes. The consumer can perform independent setup but must wait before reading data from the producer. For the synchronization requirements, see NVIDIA’s PDL execution model.

Figure 10. Independent preparation overlap with programmatic dependent launch.
TokenSpeed applies this ordering across GDN, Gated Residual, and QSA. A consumer may prepare descriptors, initialize local pipelines, or load weights whose readiness is explicitly guaranteed. It must wait before accessing activations, cache entries, or metadata produced by the preceding kernel.
Latency of dependent kernel chains
On GB300, PDL ordering changes reduce latency for all four kernel chains at batch sizes 1 and 16. GDN decoding plus normalization has the largest relative reduction: 8.5% at batch size 16. At batch size 1, QSA logits selection plus attention saves 1.249 µs. Gated Residual normalization, mixing, and combination reduce latency by about 6% at both batch sizes.
| Kernel chain | Batch size 1 (µs) | Batch size 16 (µs) |
|---|---|---|
| GDN decoding and normalization | 4.606 → 4.354 | 7.930 → 7.254 |
| GDN verification of 4 tokens and normalization | 4.991 → 4.869 | 14.274 → 13.993 |
| Gated Residual normalization, mixing, and combination | 10.116 → 9.491 | 11.171 → 10.531 |
| QSA logits selection and attention | 40.994 → 39.745 | 63.871 → 63.420 |
Each result is the median of five measurements from repeated CUDA Graph replays on the same idle GPU. GDN uses FP32 state. QSA uses 4,096 compressed blocks, 4 index heads, 6 attention heads, and 2,051 selected slots. The residual benchmark rotates 32 weight banks.
The effect depends on the workload. At batch size 4, GDN verification latency increases from 7.167 µs to 7.250 µs.
Freeing GPU memory with PLE table offload
PLE’s n-gram table is large, but each step reads only a small set of rows. TokenSpeed stores the table in pinned host memory and gathers the required rows directly into GPU output buffers through CUDA Unified Virtual Addressing. FP8 storage further reduces the table’s host-memory footprint, and the gather kernel dequantizes each row as it loads it.
Each rank holds a table shard. With tensor parallelism (TP), ranks look up shared token IDs and combine partial results. With data parallelism (DP), ranks first gather token IDs, perform the sharded lookup, and retain their own results. TokenSpeed starts the host-memory gather on a separate CUDA stream at the beginning of the preceding decoder layer, overlapping the lookup with layer computation.

Figure 11. Tensor-parallel and data-parallel PLE lookup paths.
With Qwen3.8-Flash-Next-NVFP4, FP8 PLE storage, and TP4 table sharding, offloading frees about 12.22 GiB of persistent GPU allocations per rank: 11.92 GiB for the table shard and 0.30 GiB for its device-side scale buffer. The full FP8 PLE table accounts for about 38.6% of the checkpoint’s tensor size. The freed memory can support a larger KV cache and higher serving concurrency.
Summary
These optimizations target computation, memory traffic, and waiting while preserving the model’s numerical and state semantics. They also interact: a faster selector increases the relative importance of attention, fusion changes the kernel boundaries available for overlap, and MTP changes matrix shapes and the amount of verification state. Isolated speedups therefore cannot simply be multiplied to predict serving performance.
