Skip to content

Qwen3.8 Flash Next ​

Qwen3.8-Flash-Next is a multimodal MoE model and an early preview of the Qwen4 architecture, playing for Qwen4 the role Qwen3-Next played for Qwen3.5. It pairs a 125B-parameter main model with 51B of N-gram embeddings (6B activated per token), supports 262,144 tokens of context natively and 1M with YaRN, and upgrades four axes of the hybrid design:

  • GDN + QSA hybrid attention
  • 4-branch Gated Residual
  • N-gram (predictive latent) embeddings
  • Muon optimization

In TokenSpeed, the model runs as a hybrid linear-attention (GDN) and full-attention model with optional predictive latent embeddings (PLE), optional QSA sparse attention, and a one-layer MTP draft. Dense and MoE checkpoints share the same launch command.

Prerequisites ​

Before you start, prepare the following resources:

  • A TokenSpeed environment with the ts command available. For installation instructions, see Getting started.
  • For the NVIDIA example, four NVIDIA GPUs and access to the Qwen/Qwen3.8-Flash-Next-FP8 checkpoint.
  • For the AMD examples, one or two AMD MI350X/MI355X (gfx950) GPUs and access to the amd/Qwen3.8-Flash-Next-Quark-MXFP4 checkpoint.

Start on NVIDIA ​

  1. Start the FP8 checkpoint with tensor parallelism across four GPUs and three MTP speculative steps:

    bash
    ts serve \
        --model Qwen/Qwen3.8-Flash-Next-FP8 \
        --trust-remote-code \
        --tensor-parallel-size 4 \
        --quantization fp8 \
        --moe-backend flashinfer_trtllm \
        --speculative-algorithm MTP \
        --speculative-num-steps 3
  2. After startup, verify that the server is ready.

Tune MoE routing on SM107 ​

On SM107, also set FLASHINFER_ROUTING_FORCE_BLOCK_PER_TOKEN=0 (FlashInfer 0.7.4) in the server's environment. It changes which routing kernels FlashInfer runs for this model's routes (512 experts, top-10, softmax). By default, from 32 to 256 tokens per MoE call, FlashInfer splits routing into a block-per-token top-k kernel and a permutation kernel; with the variable set, it runs one fused single-cluster kernel. With the variable set, from 257 to 1024 tokens it uses the warp-per-token top-k kernel instead of the block-per-token one. Calls below 32 or above 1024 tokens are unchanged, and the routed experts and weights are bit-identical either way. With MTP 3 steps, the target's MoE calls route 4 tokens per request, so a batch of 8 requests makes 32-token calls.

FlashInfer's default for this route comes from a routing-only sweep that covered SM100 and SM103 as well, and FlashInfer labels the variable a benchmarking override. The following timings were measured only on SM107, with the NVFP4 checkpoint at TP1 (BF16 router logits), so they are not a measurement of the FP8 command in this document. The token ranges, which depend only on the expert count, top-k, and token count, are the same for the FP8 command. FlashInfer reads the variable once per process for all of its custom (non-grouped) routing, whose default was tuned across expert counts and top-k, so set it only for this model.

The following table compares routing and decode-step timings with FlashInfer's default routing and the override. In the routing column, the first value uses the default and the second uses the override. Routing per MoE layer runs from the end of the hyper-connection mix to the start of FC1:

Decode batchRouting per MoE layerDecode step
14.4 -> 4.4 us-0.6% (noise)
813.3 -> 9.2 us-3.5% (median of 3 runs)
3215.7 -> 12.0 us-2.9%
6418.3 -> 15.3 us-1.3%
12821.0 -> 20.7 us-0.1%

A 16k-token prefill chunk is unchanged.

GSM8K CI validation ​

The GSM8K CI task serves the NVFP4 checkpoint on two B200 GPUs with MTP3 and BF16 recurrent state. It enables --enable-deferred-gdn-state and requires at least 96% accuracy on the GSM8K test split. For the launch and evaluation settings, see the GSM8K CI task configuration.

Start on AMD ​

On AMD MI350X/MI355X (gfx950), serve the AMD Quark MXFP4 checkpoint, which quantizes the routed and shared experts to MXFP4 and keeps the rest, including the MTP layer, in BF16.

Serve on one GPU ​

For multi-turn agentic traffic with long, mostly reused prompts, serve one replica per GPU at TP1.

  1. Start the server. Replace <N> with the maximum sequence count and the matching CUDA graph capture size, <host GB per GPU> with the Host KV cache capacity in GB per GPU, and <per-concurrency flags below> with the flags from the table row that matches your target concurrency:

    bash
    ts serve \
        --model amd/Qwen3.8-Flash-Next-Quark-MXFP4 \
        --trust-remote-code \
        --tensor-parallel-size 1 \
        --quantization mxfp4 \
        --max-model-len 262144 \
        --max-num-seqs <N> \
        --max-cudagraph-capture-size <N> \
        --mamba-ssm-dtype bfloat16 \
        --kvstore-size <host GB per GPU> \
        --kvstore-write-policy write_back \
        --enable-state-checkpoint-in-forward \
        --checkpoint-retention-requests 0 \
        --retraction-snapshot-host-gb 4 \
        --speculative-algorithm MTP \
        --speculative-num-steps 3 \
        --speculative-eagle-topk 1 \
        --speculative-num-draft-tokens 4 \
        <per-concurrency flags below>
  2. After startup, verify that the server is ready.

  • The Host KV cache, not device kernels, decides throughput here: the next turn of a conversation reuses its earlier prompt after the Device cache has evicted it. write_back copies only evicted pages to Host, and --enable-state-checkpoint-in-forward keeps a GDN state at each prompt's last page boundary so the next turn resumes there instead of recomputing the prompt. Size --kvstore-size so that it, the retraction snapshot pool (--retraction-snapshot-host-gb), and the offloaded PLE table fit in the host memory per GPU with headroom. TokenSpeed's B300 AgentX recipe uses 236 GB with a 4 GB snapshot pool. For compaction stalls, see Serve on two GPUs.
  • Set --max-num-seqs above the target concurrency; the following settings were tuned with about twice the concurrency.

Choose the flags for your target concurrency from the following table:

ConcurrencyPer-concurrency flags
1-2--decode-monokernel --speculative-draft-lm-head-quantization fp8_weight_only --hf-overrides '{"ple_embed_dtype":"float8_e4m3fn","ple_offload_embedding":false}'
4-16--speculative-draft-lm-head-quantization fp8_weight_only --speculative-draft-moe-quantization mxfp4 --hf-overrides '{"ple_embed_dtype":"float8_e4m3fn","ple_offload_embedding":true}'
24-32The flags for 4-16, plus --kv-cache-dtype fp8_e4m3
48 and up--speculative-draft-moe-quantization mxfp4 --kv-cache-dtype fp8_e4m3 --hf-overrides '{"ple_embed_dtype":"float8_e4m3fn","ple_offload_embedding":true}'
  • At one or two requests, the decode monokernel runs each layer of the verify and draft steps in one launch. It reads the PLE table from device memory, so keep the FP8 table on the GPU, and it refuses MXFP4 draft experts.
  • From four requests up, KV capacity bounds throughput, so keep other device memory small: the FP8 PLE table stays in pinned host memory, and from 24 requests up the KV cache is FP8.
  • The FP8 draft LM head speeds up draft steps of up to 32 rows and slows larger ones, so drop it from 48 requests up.
  • Prefill graphs cost device memory per capture bucket rather than per token, mostly HIP driver memory held by each instantiated graph. Setting DEBUG_HIP_FORCE_GRAPH_QUEUES=0 in the server environment drops the graph queues' per-graph kernel-argument pools and returns that memory to the KV cache without a measured speed cost. It is a HIP runtime debug setting, so recheck it after a ROCm upgrade. --disable-prefill-graph frees more but costs prefill throughput; a shorter --prefill-graph-capture-token-sizes ladder sits between the two.

Serve on two GPUs ​

  1. Start the MXFP4 checkpoint with tensor parallelism across two GPUs:

    bash
    ts serve \
        --model amd/Qwen3.8-Flash-Next-Quark-MXFP4 \
        --trust-remote-code \
        --tensor-parallel-size 2 \
        --quantization mxfp4 \
        --max-num-seqs 16 \
        --max-cudagraph-capture-size 16 \
        --kvstore-size 32 \
        --speculative-algorithm MTP \
        --speculative-num-steps 3
  2. After startup, verify that the server is ready.

The preceding configuration caps the batch at 16 sequences for latency; raise --max-num-seqs and --max-cudagraph-capture-size together for throughput. Keep ReplaySSM, the default.

--kvstore-size 32 caps the Host KV cache at 32 GB per GPU. The default (twice the Device KV, about 96 GB per GPU here) keeps much more Host memory mapped for the GPU, and while the Linux kernel compacts memory and migrates those pages, the GPU stalls. On hosts with fragmented memory, this behavior showed as 10-30 s pauses during decode. Raise the size if long prefixes are reused after the Device cache evicts them, or drop the Host cache with --disable-kvstore if they are not. On the host side, disabling proactive compaction (sysctl vm.compaction_proactiveness=0) removes the background trigger.

Verify the server ​

After starting any configuration, query the readiness endpoint from another terminal. If you changed the server's host or port, replace 127.0.0.1:8000 with your values:

bash
curl --fail http://127.0.0.1:8000/readiness

When the server is ready, curl exits with status 0. HTTP errors produce a nonzero exit status.

Optional: Override model configuration ​

All keys are optional and can be combined in a single --hf-overrides JSON object:

bash
--hf-overrides \
  '{"ple_embed_dtype":"float8_e4m3fn","index_share_for_mtp_iteration":true}'
  • ple_embed_dtype: "float8_e4m3fn": store the PLE n-gram embedding table in FP8 to save memory. A BF16 checkpoint uses one BF16 scale for the whole table, including across ranks. For a split BF16 table, the prescan requires a standard safetensors checkpoint. Each rank scans its own rows for the absolute maximum. The ranks reduce these maxima and use the resulting scale to quantize each shard during normal weight loading. When omitted, the table keeps the checkpoint's format: checkpoints that ship it in FP8, such as Qwen/Qwen3.8-Flash-Next-FP8 and nvidia/Qwen3.8-Flash-Next-NVFP4, keep it in FP8, and other checkpoints store it in the model's compute dtype.
  • ple_offload_embedding: keep the PLE table in pinned host memory when true or GPU memory when false. When omitted, TokenSpeed enables offloading on NVIDIA CUDA and disables it on other platforms.
  • index_share_for_mtp_iteration: true: reuse the QSA top-k selection across MTP steps. Checkpoints that already set text_config.index_share_for_mtp_iteration=true do not need this flag.

Optional: Cache PLE table rows in HBM ​

Pass --enable-ple-hot-cache to cache recently read PLE table rows in HBM. The cache defaults to off and applies only to offloaded BF16 or scalar-scaled FP8 tables with 16 n-gram heads and head dimension 160 or 512 on supported NVIDIA GPUs. TOKENSPEED_PLE_HOST_CACHE_SLOTS sets the capacity per shard when the flag is enabled (default 524288 slots; must be a power of two greater than one). At head dimension 160, the cache uses 84 MiB for FP8 or 164 MiB for BF16 per shard. At head dimension 512, it uses 260 MiB or 516 MiB, respectively. Miss staging is temporary and adds to those amounts.

Enabling the flag requires a Qwen4-Exp target with PLE layers and offloading. Unsupported model, cache geometry, dtype, or GPU configurations fail at startup. CUDA library loading errors propagate directly. Online-quantized and checkpoint FP8 tables both use the table-wide scale for hot-cache lookups. Small lookups (fewer than 256 tokens) and CUDA graph capture/replay also use regular host gather.

FlatKV cache ​

Qwen4-Exp uses FlatKV by default, putting target and draft KV, GDN, PLE, and QSA fields on one shared physical plane while preserving their logical groups. Qwen3.8-Flash-Next has five groups, with all GDN layers in one group. Each group packs pages according to its payload and alignment. Full-history K/V and compressed QSA use translated atom-page IDs; state and recent windows retain explicit strides. No KV gather is introduced.

This layout requires PP=1, uniform K/V heads within each compute view, and non-MXFP8 KV. It reduces padding for partially filled groups; a full-attention parent that was already full keeps the same useful KV bytes per token. Use --no-qwen4-exp-flat-kv for the plane-based layout. L3 compatibility follows the resulting cache layout.

TokenSpeed documentation