Skip to content

[WS1][CUDA][Qwen3-Next] Comparison benchmarks and plots for the Qwen3-Next stack: MoE, attention, logprob, EP (RFC #428 stack 11/11) - #551

Merged
Flink-ddd merged 84 commits into
RL-Align:test-qwennextfrom
fusheng-ji:feat/qwen3-next-logprob-benchmarks
Nov 19, 2026
Merged

Flink-ddd merged 84 commits into
RL-Align:test-qwennextfrom
fusheng-ji:feat/qwen3-next-logprob-benchmarks

Conversation

@fusheng-ji

@fusheng-ji fusheng-ji commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Stack: … → #549 → #557 → this PR, base test-qwennext; merges after #557; kept draft until the validation PRs land. This PR's own diff.

What

Per the layout review on #549, every comparison benchmark and plot of the Qwen3-Next stack lives here, under benchmarks/models/qwen3_next/; the validation PRs keep only checks and CI tests. Code is moved from the validation PRs with imports and paths adjusted, except the new EP benchmark.

Validation PR Candidates module Runner Plot
#503 routed MoE moe_route_candidates.py qwen3_next_moe_prior_art.py plot_qwen3_next_moe_prior_art.py
#507 full attention attention_candidates.py qwen3_next_attention_prior_art.py plot_qwen3_next_attention_prior_art.py
#543 chain — — plot_qwen3_next_chain.py
#544 batch invariance — — plot_qwen3_next_batch_invariance.py
#549 TP logprob logprob_candidates.py qwen3_next_logprob_prior_art.py plot_qwen3_next_distributed_logprob.py
#557 moe_ep_candidates.py qwen3_next_moe_ep_prior_art.py plot_qwen3_next_moe_ep.py

Miles and verl are measured, not read: thirdparty_sources.py imports their own kernels unmodified from checkouts of pinned commits (radixark/miles@23d3d38, volcengine/verl@e5a627c) and records the SHA-256 of every file used. New here: qwen3_next_miles_moe_backward.py (Miles' routed-MoE backward, 20 identical launches on the real layer-0 weights, RL-Kernel as the control), qwen3_next_logprob_backward.py (verl, Miles and RL-Kernel logprob backward), miles_fused and verl_fused in the logprob candidates, and plot_qwen3_next_thirdparty.py.

Results summaries (download link, SHA-256, tested commit, commands) are in reports/experiments/qwen3_next/: qwen3-next-logprob-comparison-b200.md, qwen3-next-moe-ep-comparison-b200.md and qwen3-next-thirdparty-comparison-b200.md here; the MoE-route, attention, chain and BI summaries in their validation PRs.

Prior art & reuse decision

N/A: benchmarks only. The reuse decisions are in each validation PR; this PR provides the code that measures them.

Results

Expert-parallel MoE (new, for the EP PR), layer 0 real weights, EP4 under 13 NCCL settings and EP1, 4 × B200, measured at 7db4a14b (summary, raw results ZIP, SHA-256 2375ec36…97c6cf):

Candidate Fwd EP4 == EP1 Fwd distinct results / 13 NCCL settings Fwd repeat / batch inv. Bwd EP4 == EP1 (dx, dW) Bwd batch inv. Max abs vs FP64 EP4 fwd 64 / 1024 / 4096 tokens EP4 bwd
RL-Kernel EP4 yes 1 yes / yes yes, yes yes 1.8e-5 1.85 / 2.27 / 4.08 ms 51 ms
vLLM + vLLM all-reduce no 1 yes / yes no backward – 8.7e-4 0.35 / 0.48 / 0.68 ms –
vLLM, VLLM_BATCH_INVARIANT=1 no 1 yes / yes no backward – 8.7e-4 0.41 / 0.51 / 0.81 ms –
vLLM + NCCL all_reduce no 5 yes / no no backward – 8.7e-4 0.39 / 0.52 / 0.74 ms –
FlashInfer cutlass_fused_moe (CUTLASS) no 1 yes / yes no backward – 8.7e-4 0.33 / 0.39 / 0.48 ms –
Megatron alltoall no 13 no / no no, no no 4.2e-5 11.8 / 14.6 / 14.9 ms 41 ms
Megatron allgather no 13 no / no no, no no 2.5e-5 10.8 / 13.2 / 13.6 ms 37 ms
Megatron alltoall, deterministic yes 1 yes / yes no, no no 4.2e-5 12.7 / 15.4 / 15.9 ms 42 ms
Megatron allgather, deterministic no 1 yes / yes no, no no 2.5e-5 11.6 / 14.3 / 15.0 ms 40 ms

Qwen3-Next EP MoE prior art

Miles and verl (for #503, #549, EP PR), measured at 6ad63611 (MoE backward, logprob forward) and 03a5898e (logprob backward, TP1 and TP4) (summary, raw results ZIP, SHA-256 d0eaa326…f2ff):

Miles and verl vs RL-Kernel

Measurement Miles verl RL-Kernel
routed-MoE backward, 20 identical launches: dx / dW gate/up / dW down equal the first 1 / 20 each (BF16 tl.atomic_add) no MoE kernel 20 / 20
routed-MoE dx of probe rows alone == in batch (10 cells) 0 / 10 – 10 / 10
logprob forward, TP4 == TP1 no no yes
logprob forward, distinct TP4 results over 13 NCCL settings 2 2 1
logprob backward, 10 launches equal (TP1) 10 / 10 10 / 10 10 / 10
logprob backward row gradient, probe rows alone == in batch (10 cells; logits of Miles and RL-Kernel from the batch-invariant GEMM) 10 / 10 1 / 10 10 / 10
logprob backward, TP4 == TP1 no no yes
logprob backward, distinct TP4 results over 13 NCCL settings (10 launches each) 2 2 1

Miles' MoE backward is not reproducible; both libraries' logprob forward depends on the NCCL algorithm like Megatron's and VIME's. Their logprob backward also depends on the NCCL algorithm at TP4 (it consumes the all-reduced forward statistics) and differs from TP1, while RL-Kernel's does not. Not what the source suggested: verl's backward tl.atomic_add did not change the bits between launches, and its forward atomic_add only runs for reduction sum/mean.

TP logprob (#549): measured in #549 (summary and ZIP there): TP4 median latency 2.55 ms (RL-Kernel), 1.51 ms (vLLM), 0.57 ms (Megatron), 0.56 ms (VIME); invariance as in #549.

The routed-MoE, attention, chain and BI figures are rendered by the moved plot scripts from the ZIPs attached to their PRs (checked: each renders from the downloaded evidence layout).

Figures of the validation PRs, rendered by the plot scripts in this PR from the evidence ZIPs of those PRs:

#503 routed MoE #507 attention
MoE route prior art TP4 attention prior art
#543 full-model chain #544 batch invariance (97 / 97 cells; reruns at EP1 and EP4 in #544 and #557)
Chain on the stack top Batch invariance

Status

History

Tests

python benchmarks/models/qwen3_next/qwen3_next_moe_ep_prior_art.py --help
torchrun --nproc-per-node 4 benchmarks/models/qwen3_next/qwen3_next_moe_ep_prior_art.py --checkpoint <ckpt> --output runs/ep4-default
torchrun --nproc-per-node 1 benchmarks/models/qwen3_next/qwen3_next_moe_ep_prior_art.py --checkpoint <ckpt> --output runs/ep1
python benchmarks/models/qwen3_next/qwen3_next_moe_ep_prior_art.py --merge runs/ep4-default runs/ep4-<...> runs/ep1 --out report.json
Check Result
every runner --help and every plot rendered from its published evidence passed
pre-commit on all files clean

Scope

CUDA, B200. Benchmarks and plots only.

Rank r owns experts [128r, 128r+128) at full intermediate width; attention,
GDN, embedding, LM head and the shared expert stay TP4. The MoE input is
replicated, so dispatch is local: every rank computes the same routes,
evaluates its own routes with the fixed-config grouped GEMM (through vLLM's
expert_map), and the ranks exchange those rows with the deterministic
collective's all-gather; every rank then applies the ordered FP32 combine.
Backward keeps expert weight gradients on their owner and sums each token's
route contributions in ascending expert order, as the EP1 path does.
Add the EP4 real-weight gate and CPU placement tests.

Signed-off-by: Wenbo Ji <[email protected]>
…E recompute

The launcher takes --ep {1,4}; the run's topology and provider config record
it, so every stage, certificate and identity comparison binds to it, and the
layers stage runs the EP4 MoE gate instead of the TP4 one at EP4.

vLLM: expert parallelism must match the identity, with linear placement; the
bound model checks 128 full-width local experts and that vLLM's expert map is
[128r, 128r+128) on rank r, and SharedVLLMMoE evaluates them with
shared_moe_ep. VIME: EP4 x ETP1 is accepted next to EP1 x ETP4; SharedVIMEEPMoE
requires Megatron's EP rank to equal the TP rank and loads only this rank's
experts. Training and EP4 weight export stay EP1-only and fail closed.

Signed-off-by: Wenbo Ji <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6ef62429-ff40-44b1-8f86-d16efdfc7d8d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@fusheng-ji
fusheng-ji force-pushed the feat/qwen3-next-logprob-benchmarks branch from 48516ee to 3bc3f7e Compare October 12, 2026 19:11
@fusheng-ji
fusheng-ji force-pushed the feat/qwen3-next-logprob-benchmarks branch from 1026162 to 8f675f3 Compare October 12, 2026 22:26
…xt gate scripts

The scripts moved from ci/ to ci/scripts/ with the repository refactor but
still resolved the root one directory up, so the preflight operator gates
looked for ci/tools/validation/models/qwen3_next_operator_gates.py.

Signed-off-by: Wenbo Ji <[email protected]>
The EP4 MoE gate moves to tools/validation/models/qwen3_next/ with the other
Qwen3-Next gates, following the maintainer's layout review on the TP PR.

Signed-off-by: Wenbo Ji <[email protected]>
The scheduler and L2 matrix validators still required topology ep=1, so the
EP4 layers stage failed after all of its gates had passed. Both now use
supported_topology (TP4/PP1/CP1 with EP 1 or 4), and the chain report's config
fingerprint records the measured expert parallelism. Training stays EP1-only.

Signed-off-by: Wenbo Ji <[email protected]>
The disclaimer said TP4 x EP1 and the backend profile was the EP1 one
for every chain. Both now follow the topology recorded in the L2
matrix; EP1 reports are unchanged.

Signed-off-by: Wenbo Ji <[email protected]>
Adds the expert-parallel section to the distributed logprob contract
(placement, local dispatch, byte-only route exchange, combine and
gradient order, fail-closed topologies) and a short summary of the
TP4 x EP4 preflight, layers and L2 run measured at 1c4ae26. The raw
JSON is a ZIP release attachment; the summary records its SHA-256 and
the commands that reproduce it.

Signed-off-by: Wenbo Ji <[email protected]>
Runs RL-Kernel's EP4 routed MoE, vLLM's expert-parallel fused_experts
(default and VLLM_BATCH_INVARIANT=1) and Megatron-core's MoELayer with
the alltoall and allgather dispatchers on the same replicated input at
EP4 and EP1. Each launch records the output digest, repeatability,
batch invariance, the error against an FP64 evaluation and latency; the
merge step compares EP4 with EP1 and EP4 launches under different NCCL
settings.

Signed-off-by: Wenbo Ji <[email protected]>
…anges

Clearing it around every call made each timed default-mode call look up
the tile config file again, which inflated vLLM's default latency.

Signed-off-by: Wenbo Ji <[email protected]>
With torch.use_deterministic_algorithms(True) Megatron's token unpermute
uses index_add_ instead of scatter_add_, so its deterministic mode is a
separate candidate. The runner sets CUBLAS_WORKSPACE_CONFIG for every
candidate. Adds the figure renderer for the merged report.

Signed-off-by: Wenbo Ji <[email protected]>
Seven candidates on real layer-0 weights at EP4 under 13 NCCL settings
and at EP1, measured at 225c5a4; raw JSON and the figure are a ZIP
release attachment.

Signed-off-by: Wenbo Ji <[email protected]>
…ce, backward

Adds FlashInfer's cutlass_fused_moe (CUTLASS grouped GEMM) with
ep_size/ep_rank, and runs vLLM's expert kernel with vLLM's own
all-reduce dispatch as deployed (the NCCL-only combine stays as a
separate candidate). Batch invariance is now a grid of batch sizes
8-1024 with the probe rows first, middle and last; the candidates that
train (RL-Kernel, Megatron) also report input and owned-expert weight
gradient digests, repeatability, the same grid on the input gradient
and backward latency; forward latency covers 64-4096 tokens.

Signed-off-by: Wenbo Ji <[email protected]>
… moves here

Per the layout review on RL-Align#549, the remaining comparison benchmarks and
plots of the Qwen3-Next stack join this PR under benchmarks/models/qwen3_next/:
the routed-MoE and full-attention prior-art candidates and runners, their
plots, and the chain and batch-invariance plots. Code is unchanged apart
from imports and paths; the validation PRs keep only checks and CI tests.

Signed-off-by: Wenbo Ji <[email protected]>
@fusheng-ji

Copy link
Copy Markdown
Contributor Author

Replies to the six OpenCodeReview summary items. The plot fixes are compiled but I have not re-rendered the figures from the evidence.

  1. run_qwen3_next_chain_gate.sh L21-L22, bare assert: fixed in 74a1b1a6 (the script belongs to [WS1][CUDA][Qwen3-Next] Full-model chain: vLLM rollout vs VIME recompute, raw-bit through two updates and a reload (RFC #428 stack 7/11) #543 and reaches this PR through the merge). The checks are explicit now: a malformed report exits 2 with the missing field or schema named, a failed gate still exits 1. Run with PYTHONOPTIMIZE=1 on an empty report it exits 2.
  2. plot_qwen3_next_attention_prior_art.py L106, KeyError on accuracy: fixed in 026e0440. A candidate without it gets NaN and no label, as in the MoE sibling.
  3. same file L112, all-zero x-limit: fixed in 026e0440. The upper bound ignores NaN and falls back to 1.0 for an all-zero column.
  4. plot_qwen3_next_thirdparty.py L160-L161, cell keys from names[0]: fixed in 026e0440. A cell a grid did not run is drawn grey instead of raising KeyError. The columns still come from the Miles MoE grid.
  5. plot_qwen3_next_distributed_logprob.py L55-L57, iterdir(): fixed in 026e0440. Only directories count as runs, and a missing default run exits with a message.
  6. plot_qwen3_next_moe_ep.py L100, hard-coded ep4-default: fixed in 026e0440. A missing ep4-default launch exits with a message that names it. The name stays: it is the launch the sort key and the reference both use.

@fusheng-ji

Copy link
Copy Markdown
Contributor Author

One OpenCodeReview summary item:

  1. run_qwen3_next_chain_gate.sh L26-L29, JSON-only keys: fixed in 4e2c33af (merge 2c699e3f). first_drift_family is required explicitly because it is a payload key and not a dataclass field, cells must be an object, and the load no longer leaks the file handle; every failure exits 2. A report without first_drift_family now exits 2 with the field named.

@Flink-ddd Flink-ddd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the benchmark changes; please merge after #557 is ready.

…ine_routes

The EP4 MoE gate compared only the routed experts on fixed routes. Each
token count now also runs the whole routed block end to end
(shared_moe_ep: shared_router, stable_top10_routes, the experts and
combine_routes) against shared_moe (EP1) on the same weights, bitwise: the
output, route indices and weights, the input gradient, the router weight
gradient and the owned experts' weight gradients. The router weight
gradient must be non-zero and identical on every rank. The four new case
ids are mandatory in the layer contract.

Signed-off-by: Wenbo Ji <[email protected]>
…, EP4 router/combine gate) into RL-Align#551

Signed-off-by: Wenbo Ji <[email protected]>
lq = [s[0].shape[0] for s in seqs]
lk = [s[1].shape[0] for s in seqs]
blocks = [(n + block - 1) // block for n in lk]
k_cache = torch.zeros(sum(blocks), block, HKV, D, device="cuda", dtype=torch.bfloat16)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performance · high
_vllm_triton.run allocates and fills the paged K/V caches (and builds the block table) on every call, and _latency times the whole run via _sample_us. For decode (lq=1, kv=8192) the actual unified_attention kernel is a few microseconds while zeroing/copying ~8 MB of cache dominates, so this candidate's decode_us_kv8192 is far larger than varlen candidates that do no such setup. The reported decode/prefill latencies are therefore non-equivalent and would support a wrong conclusion about the kernel. Build the cache once outside the timed closure (per fixed shape) and time only the kernel launch.

Comment on lines +272 to +274
dw13 = torch.stack([e.linear_fc1.weight.grad for e in experts])
dw2 = torch.stack([e.linear_fc2.weight.grad for e in experts])
return x.grad, dw13, dw2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug · high
_megatron.backward reads .grad after layer.zero_grad(set_to_none=True) and torch.stacks them. Experts that received no routed tokens are not part of the autograd graph, so their .weight.grad stays None, and torch.stack raises TypeError. candidate_report invokes cand.backward(probe, dprobe) with only PROBE=8 rows (80 top-10 slots spread over 128/512 experts), so most experts are unselected and this path will almost certainly crash the whole measurement (the backward section is one of the few spots not wrapped in try/except). Materialize missing grads as zeros before stacking.

Suggestion:

Suggested change
dw13 = torch.stack([e.linear_fc1.weight.grad for e in experts])
dw2 = torch.stack([e.linear_fc2.weight.grad for e in experts])
return x.grad, dw13, dw2
dw13 = torch.stack([
e.linear_fc1.weight.grad
if e.linear_fc1.weight.grad is not None
else torch.zeros_like(e.linear_fc1.weight)
for e in experts
])
dw2 = torch.stack([
e.linear_fc2.weight.grad
if e.linear_fc2.weight.grad is not None
else torch.zeros_like(e.linear_fc2.weight)
for e in experts
])
return x.grad, dw13, dw2

…in the provider job, RL-Align#503 bias grad gate) into RL-Align#557

check_qwen3_next_vllm_model_contract.py stays only in this PR's four-GPU step, which already runs it.

Signed-off-by: Wenbo Ji <[email protected]>
…in the provider job, RL-Align#503 bias grad gate) into RL-Align#551

Signed-off-by: Wenbo Ji <[email protected]>
Candidates with per-batch setup now expose prepare(seqs) -> launch: packing
and cu_seqlens for the varlen engines, the paged KV cache and block table
for vLLM Triton, FlashInfer's plan, and the bottom-right masks for SDPA and
Megatron run once per shape, as an engine does once per step for all
layers. Latency times launch() only; run(seqs) is prepare(seqs)() so the
batch-invariance checks still cover the setup. Before, the Triton
candidate zeroed and copied the whole KV cache and FlashInfer planned
(with a device-to-host copy) inside every timed sample.

The backward timing now probes each candidate once and leaves out one that
raises, as the forward already did, and --only builds only the selected
candidates.

Signed-off-by: Wenbo Ji <[email protected]>
The attention merge stops when both reports measured the same candidate,
and replaces a candidate the base recorded as unavailable with the extra
report's entry, so a candidate's verdicts and latency come from one
process. The MoE EP and logprob runners give a usage error for --merge
without --out, or a measurement without --checkpoint and --output.

Signed-off-by: Wenbo Ji <[email protected]>
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 18, 2026
…t rerun

Step 5: the RL-Align#507 attention prior art on H100 with RL-Align#551's timing fix
(per-batch setup out of the timed region), plus a bundle of the local
OCR fixes (fix/551-flink-r1 at 2c0cd1e, prerequisites ea999fd and
6248771).

Signed-off-by: Wenbo Ji <[email protected]>
@fusheng-ji

Copy link
Copy Markdown
Contributor Author

OpenCodeReview (summary item, run of 2026-11-17) · ci/scripts/run_qwen3_next_chain_gate.sh (L44-L44): The gate only checks that passed is present (and that cells is a dict); it never type-checks passed, first_drift or first_drift_family.

Fixed on #543 in bef6d13a and merged up to this PR (ea79d7ae). A passed that is not a JSON boolean exits 2 as an invalid report, and only true exits 0. No published chain report is affected.

@fusheng-ji

Copy link
Copy Markdown
Contributor Author

OpenCodeReview (summary item, run of 2026-11-17) · benchmarks/models/qwen3_next/attention_candidates.py (L573-L575): The forward calls_for helper probes each candidate with try/except and drops ones that raise, but this backward dict is built from ready unconditionally.

Fixed in 73e5b5fb. The backward timing now probes each candidate's grad_batch once and leaves out one that raises, as the forward already did. The failure stays recorded in that candidate's batch-invariance entry. No published number changes.

@fusheng-ji

Copy link
Copy Markdown
Contributor Author

OpenCodeReview (summary item, run of 2026-11-17) · benchmarks/models/qwen3_next/attention_candidates.py (L591-L591): candidates() is invoked before filtering, so it still runs every factory, including _megatron_local (initializes an NCCL process group / model-parallel state as a global side effect) and _flashinfer (allocates a 256 MB workspace held for the whole run).

Fixed in 73e5b5fb. The candidates are now a key → factory table, and --only picks the keys before any factory runs. No published number changes.

@fusheng-ji

Copy link
Copy Markdown
Contributor Author

OpenCodeReview (summary item, run of 2026-11-17) · benchmarks/models/qwen3_next/qwen3_next_attention_prior_art.py (L78-L78): merge keeps base candidate metadata but then _merge_latency(base["latency"], extra["latency"]) recursively overwrites latencies for any key present in both, and there is no check that the extra report's candidate keys are disjoint from base's.

Fixed in 2c0cd1e1. merge now stops with an error naming the keys when both reports measured the same candidate. If the base report lists a key as unavailable, the extra report's measured entry replaces it whole, so the batch-invariance result and the latency of one candidate always come from the same process. The published report is not affected: its two halves had disjoint keys.

@fusheng-ji

Copy link
Copy Markdown
Contributor Author

OpenCodeReview (summary item, run of 2026-11-17) · benchmarks/models/qwen3_next/qwen3_next_moe_ep_prior_art.py (L234-L236): --out is not required=True and --checkpoint/--output are never validated.

Fixed in 2c0cd1e1, in this runner and in qwen3_next_logprob_prior_art.py and qwen3_next_logprob_backward.py. --merge without --out is now a usage error, and so is a measurement launch without --checkpoint or --output. Both are rejected before any work starts.

fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 18, 2026
… rerun

Rerun of the RL-Align#507 attention prior art on B200 with the RL-Align#551 runner at
2c0cd1e (per-batch setup outside the timed region). Batch-invariance
verdicts and accuracy are unchanged; latencies, the archive link and its
SHA-256 are updated, and the summary records the Transformer Engine
2.20.2 and Megatron-core 0.20.0 versions of this run.

Signed-off-by: Wenbo Ji <[email protected]>
@Flink-ddd
Flink-ddd merged commit bcc549b into RL-Align:test-qwennext Nov 19, 2026
9 checks passed
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.

3 participants