Notes from an independent NVFP4 port of Qwen3.8-Flash-Next

#82
by alexmv2025 - opened

We run Qwen3.8-Flash-Next in our own C++/CUDA inference engine (no PyTorch at
runtime) on a single RTX 5090. The 336 GB BF16 release converts in place to a
164 GB tree. Only a 3.6 GiB dense graph is device-resident; the 24 576 routed
experts live in a 63.6 GB pinned host arena and are streamed per token through a
device slot cache, and the 96 GiB n-gram table is memory-mapped and read a page
at a time. Load takes about 50 s (the arena build dominates), and decode runs at
42.8 tokens/s at 2 048 tokens.

What worked well

  • Determinism is solid. The control prompt answers "Paris", and three
    independent runs produce byte-identical full-vocabulary logits. A second model
    instance in the same process answers identically, which matters here because
    the expert-residency bookkeeping is process-lifetime state.
  • All four of our parity gates pass on real weights: a financial-services
    formula set (3/3), a compiler-syntactic code set (3/3), a determinism/near-tie
    set (3/3), each captured from the source weights rather than from a template.
  • The tool wire is unambiguous. The template's
    <tool_call><function=NAME><parameter=K>V… XML is parsed without heuristics,
    and a real-weight round-trip produced the get_weather call with
    {"city":"Paris"}. One template delta over the earlier Qwen 3.x checkpoints
    (the closed think block on assistant history turns) plus this member's own
    preserve_thinking and empty-system-turn defaults had to be reproduced
    byte-for-byte (see below) — with them, multi-turn and tool turns frame exactly
    as the checkpoint's own Jinja template does.
  • 4-bit is enough for this checkpoint. Unlike some models we have ported, the
    body tolerates NVFP4 throughout — with two deliberate exceptions, the LM head
    and the n-gram table (below). No residual weight plane was needed.

Checkpoint facts that are easy to get subtly wrong

  1. The LM head must not be quantized. At 4 bits the logit noise is ~0.5,
    which exceeds this model's typical top-1/top-2 margin; the argmax flips. We
    keep lm_head in BF16 (an extra 1.2 GB) and quantize everything else,
    including the embedding table.

  2. There are three distinct model-type names. The top level is
    qwen4_exp, the text sub-config is qwen4_exp_text, and the architecture is
    Qwen4ExpForConditionalGeneration — with language_model_only: false
    because the release still ships a 333-tensor vision tower. A loader that keys
    on one name silently skips or misclassifies the other. We strip and count the
    vision tower (skipped_visual_tensors: 333).

  3. The EOS ids disagree between files. config.json says 248044,
    generation_config.json says [248046, 248044], and tokenizer_config.json
    names <|im_end|> as the EOS token. Reading only the config makes the model
    run to the token budget whenever it ends with <|im_end|> — the common
    ending. We take both ids. (Suggestion to the authors: make config.json
    authoritative and consistent with generation_config.json.)

  4. pad_token_id is null in the text config while the tokenizer pads with
    248044, which is also the secondary EOS.
    A padded batch therefore looks
    like a batch that stopped. We never batch, but an implementer who does will
    find this quickly. (Suggestion: ship a pad id that is not a stop id.)

  5. rope_parameters.mrope_interleaved: true with mrope_section [11,11,10]
    is the multimodal branch.
    The text decoder rotates 64 of its 256 head dims
    with a plain rotary table (θ = 1e7); applying the M-RoPE sections to text
    positions corrupts them. If you only run text, ignore that block. (Suggestion:
    document which sub-block the text path consumes.)

  6. ple_layer_ids: [2] but the tensors are layers.1.ple.*. One is
    1-based and the other 0-based. Getting it wrong either fails to find the
    table or injects it into the wrong layer; the model still produces fluent
    text, which is the worst failure mode. We gate the converter on
    ple_layer_ids == [layer_idx + 1].

  7. The n-gram (PLE) table is 96 GiB of BF16 in 128 shards — larger than every
    other weight in the model combined.
    It must be memory-mapped and gathered
    per token, not loaded. (Suggestion: a quantized or int16 copy would cut the
    tree by ~40 %.)

  8. generation_config.json samples by default (do_sample: true,
    temperature 1.0, top_k 20, top_p 0.95). Any parity work has to pin
    greedy explicitly, exactly as we do.

  9. MTP is declared but inert: mtp_num_hidden_layers: 1, mtp.hybrid,
    mtp_use_hidden_state_from_layer: null. We convert and count it under
    deferred and never apply it.

  10. The decode working set is the whole expert set. 512 experts at
    intermediate 640 per layer × 48 layers means each expert is only ~2.7 MB,
    but a token touches ten of them per layer, and the union over a decode run
    is effectively all 24 576. A bounded LRU over file-backed mmaps measured
    9.2 tokens/s against the pinned arena's 32 on the same card; pinning the
    whole set is the only thing that pays here. Budget host RAM for it.

Measured

result
SelfCheck ("Paris") PASS ×3, bit-identical logits, logits_hash 2e3bcd090441ad65, top-1 id 11751
Financial-services formula set 3/3
Compiler-syntactic code set 3/3
Determinism / near-tie set 3/3, byte-identical token streams
Native tool round-trip get_weather {"city":"Paris"} in 26 tokens
Decode throughput, 2 048 tokens 42.98 t/s (auto), 33.88 t/s (strict); TTFT 193 / 198 ms
Residency 3 615 MiB device-resident; 63.6 GB pinned host arena; ~50 s load
Expert cache 5 350 / 4 319 slots, hit rate 0.86, ~300 MB streamed per token

What we did not run

  • The 262 144-token window. We verified short/medium prompts and the
    2 048-token protocol; the full window's KV and recurrent state exceed this
    card, and the expert-cache capacity is already the limiting factor.
  • MTP / speculative decoding — the layer is stored (counted) but never runs.
  • Any multimodal path — the vision tower is stripped; this is a text-only
    port.
  • Sampling quality. All parity numbers are greedy; the sampler is wired but
    the checkpoint's own do_sample defaults were not benchmarked.

Overall a well-specified checkpoint once the three traps above are known
(LM-head precision, EOS id disagreement, and the PLE index base). The one thing
that cost real time was the capacity behaviour: throughput moves 10-30 % with
expert-cache size, so a "regression" here is usually less VRAM, not slower code.

BMH SelfCheck Model Standard

Sign up or log in to comment