Skip to content

qwen4_exp: Strict and Spark modes require SparkQwen's native-precision paths - #268

Merged
AzeezIsh merged 8 commits into
Atlas-Inf:mainfrom
Enntity:sq-pr/modes
Oct 30, 2026
Merged

AzeezIsh merged 8 commits into
Atlas-Inf:mainfrom
Enntity:sq-pr/modes

Conversation

@data-angel

Copy link
Copy Markdown
Contributor

Part of #220. Stacked on #267: review the top commit only. It needs #265 and #266 merged first; it builds without them, because it only checks the environment.

What

ATLAS_QWEN4EXP_SERVING_MODE=strict|spark now refuses to start unless each of these is set to 1:

  • ATLAS_QWEN4EXP_MXFP8_DECODE
  • ATLAS_QWEN4EXP_PREFILL_W8A8
  • ATLAS_QWEN4EXP_MXFP8_SHARED
  • ATLAS_QWEN4EXP_PREFILL_W4A4

Outside a mode they stay opt-in. mode.rs loses its "no implementation here" paragraph.

Why

A mode is the promise that SparkQwen serves 0.4.0's bytes. Those bytes need all four paths (Benchmarks in #265). Without this contract a mode could start on main's other numerics silently.

Benchmarks

None of its own. This is a startup contract; the series' measurements are in #265.

Tests

  • modes_require_the_native_precision_paths, written first: it failed, then passed.
  • The existing mode tests and the spark-server preflight qwen_mode tests pass.
  • fmt, clippy and doc pass.

Authorship

AI-authored (Claude Code). No human-written code.

🤖 Generated with Claude Code

data-angel and others added 6 commits October 29, 2026 21:23
…under a mode

Enntity's quantize_bf16_to_nvfp4_weight_rne (CUDA's nearest-even E4M3
scale and E2M1 conversion) had no kernel in this stack, so under
ATLAS_QWEN4EXP_SERVING_MODE mode::weight_quantizer() named the standard
converter and the draft copies did not carry Enntity's rounding.

The kernel lands as a qwen3.8-flash-next shadow of common/'s
quantize_bf16_to_nvfp4.cu (the common file included unchanged, one entry
point added; body byte-identical to Enntity's glm-5.3-flash file, which
Enntity shares into this target by symlink -- here the GLM target is left
untouched). weight_quantizer() names it whenever a mode is selected, as
Enntity's does, and the draft head's NVFP4 copy (ATLAS_QWEN4EXP_DRAFT_HEAD_NVFP4,
Spark) now takes it like the MTP drafter already did. Unset: the standard
converter everywhere, as before. Under draft TP both ranks build the head
copy from the mode, which startup parity already pins. PDL lists unchanged.

check_qwen4exp_kernel_names.py follows a shadow's .cu include (Enntity
7e056d6's translation_unit) so the included entry points still resolve.

Ported from Enntity/atlas 9b25f57 (mode.rs weight_quantizer,
qwen4exp_draft_head.rs, glm-5.3-flash/nvfp4/quantize_bf16_to_nvfp4.cu via
f4d95a1/70c35846, scripts/dev/check_qwen4exp_kernel_names.py), AGPL-3.0-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_MTP_BF16_ATTN / _ROUTER)

The MTP loader requantized the drafter layer's BF16 Q/K/V/O and router to
NVFP4. ATLAS_QWEN4EXP_MTP_BF16_ATTN=1 builds the drafter body with
attn_proj_bf16 (the --attn-proj-dtype bf16 arms) on its own TP=1 config
only. ATLAS_QWEN4EXP_MTP_BF16_ROUTER=1 gives the drafter Enntity's MoE:
the checkpoint's BF16 router (gate_nvfp4 None, on the scalar BF16 arms as
Enntity runs it, not the target's row-invariant tiers) and the shared
expert as an NVFP4 copy (mode::weight_quantizer) fused into the expert
kernels, in place of this stack's NVFP4 router copy and BF16-native
shared-expert chain. Enntity removed its _ROUTER switch when the BF16
router became its only drafter MoE (28611c0), so either serving mode
selects it here too. Each switch is on only at 1; both default off, and
unset (no mode) keeps today's drafter byte for byte. The target is
untouched. Drafts only, on the drafting rank, so as in Enntity neither is
a startup-parity setting.

The switches are read in one place, helpers::MtpPrecision (Enntity's
helpers.rs mtp_drafter_config / mtp_router_nvfp4 after 030ec26), with
the lookup injectable for the unit tests.

Ported from Enntity/atlas 15ecb5e, 030ec26, the drafter hunk of
28611c0 and the mtp.rs/helpers.rs hunks of 7e056d6 (AGPL-3.0-only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…contract)

With ATLAS_QWEN4EXP_MTP_BF16_ATTN implemented, the serving-mode drafter
flags take Enntity's contract: Strict requires MTP_BF16_ATTN=1 beside
DRAFT_HEAD_NVFP4=0, Spark MTP_BF16_ATTN=0 beside DRAFT_HEAD_NVFP4=1. The
file header no longer lists the switch among the ones this stack lacks
(and, since the previous commits, no longer says the RNE converter is
missing). REQUIRED_FLAGS are unchanged.

Ported from Enntity/atlas 9b25f57 mode.rs drafter_flags (7e056d6),
AGPL-3.0-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…PDL list

It enters PDL before reading its inputs, as production lists it; the PDL
list check fails without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tches

Under ATLAS_QWEN4EXP_MTP_BF16_ATTN=1 (Strict) the drafter's attention is
BF16, and the KV-only rows of the MTP absorb and the prompt pass
(ATLAS_QWEN4EXP_MTP_PREFILL) fell back to the full Q/K/V phase: every
prompt row projected Q too, about 0.2 ms a token of Strict TTFT (2K 0.70 ->
1.34 s, 16K 3.9 -> 7.2 s on 03/04 against 0.4.0). K and V now go through
dense_gemv_batchm in groups of up to eight rows (the scalar GEMV's K order
and reduction tree), as in SparkQwen 0.4.0; Q is never read.

Ported from Enntity/atlas 9263250 (production's dense_mx check is main's
QuantWeight::Mxfp8, already excluded by the k/v weight checks); its GPU
test reads production-only checkpoint helpers and is not carried.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A serving mode now refuses to start unless ATLAS_QWEN4EXP_MXFP8_DECODE,
_PREFILL_W8A8, _MXFP8_SHARED and _PREFILL_W4A4 are each 1: the tensor-core
MXFP8 decode tiers, W8A8 prefill, the EP-split MXFP8 shared expert and the
W4A4 routed prefill that make the modes serve SparkQwen 0.4.0's bytes. They
stay opt-in outside a mode. (The switches arrive in their own PRs; this
only checks the environment, so it builds without them.)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor

Conflict with main resolved: normal git merge origin/main — kept both flag contracts; doc-comment-only resolution in weight_loader/qwen4_exp/mode.rs (same as #267). clippy+fmt clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	crates/spark-model/src/weight_loader/qwen4_exp/mode.rs
Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	crates/spark-model/src/weight_loader/qwen4_exp/mode.rs
@AzeezIsh
AzeezIsh merged commit 89921b5 into Atlas-Inf:main Oct 30, 2026
1 check passed
@data-angel
data-angel deleted the sq-pr/modes branch November 3, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants