Skip to content

[WS1][CUDA][Qwen3-Next] Batch-invariance matrix for the full model, 97/97 cells bitwise (RFC #428 stack 8/11) - #544

Merged
Flink-ddd merged 32 commits into
RL-Align:test-qwennextfrom
fusheng-ji:feat/ws1-qwen3-next-batch-invariance-ci
Nov 19, 2026
Merged

Flink-ddd merged 32 commits into
RL-Align:test-qwennextfrom
fusheng-ji:feat/ws1-qwen3-next-batch-invariance-ci

Conversation

@fusheng-ji

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

Copy link
Copy Markdown
Contributor

Stack: #466 (merged) → #467 → #468 → #469 → #503 → #507 → #543 → this PR → #549 → #557 → benchmarks (#551), base test-qwennext; merges after #543. This PR's own diff. RFC #428 row batch_invariance_ci, CUDA.

What

  • Stage bi after a passed l2, under the same certified provider profile: 97 pinned cells (rl_engine/validation/models/qwen3_next/qwen3_next_bi_cases.py, qwen3_next_bi_manifest.json), compared bitwise on response tokens, BF16 logits, FP32 logprobs, the embedding and every layer, sub-node and state digest.

    Family Cells The target runs Compared with
    concurrency 13 with 0-63 companions, first or last the target alone, same chunk plan
    interference 10 companion content, lengths, arrival in prefill/decode, generation length; or arriving after them the target alone, same chunk plan
    chunk 66 prompts 63-1024 around 64/128/528/1024, chunk 64/128, first chunk 1/63/65 the replay engine's recompute (train/rollout boundary)
    packing 8 replay THD batch with 1-7 neighbours, first or last the replay of the target alone
  • Native rollout: version 2 requests run one traced target next to untraced companions; the exact-prefill scheduler admits each request at its arrival step, pins the target's planned chunk at every step and fails on any preemption.

  • Replay: variable-length THD packing with a traced target.

  • Reports: bi-matrix.json names each failing cell's first divergent layer, sub-node and family; the chain report gains a batch_invariance section.

  • gtest: bitwise judgments compare raw bits (signed zero, NaN/Inf and dtype count) instead of allclose with zero tolerance (rl_engine/validation/operators/forward_invariance.py); the dense Qwen3-8B gtest suite still passes.

  • Layout as reviewed on [WS1][CUDA][Qwen3-Next] TP distributed logprob parity: fixed reduction order, selected-token logprob exact across NCCL settings (RFC #428 stack 9/11) #549: the BI runner is tools/validation/models/qwen3_next/qwen3_next_batch_invariance.py; the BI plot is in the benchmark PR ([WS1][CUDA][Qwen3-Next] Comparison benchmarks and plots for the Qwen3-Next stack: MoE, attention, logprob, EP (RFC #428 stack 11/11) #551); raw evidence is a release ZIP.

Prior art & reuse decision

N/A for a kernel: this PR adds a test matrix over the providers of #503-#543. The scheduler pinning reuses vLLM 0.30.0's scheduler (long_prefill_token_threshold, chunked prefill) rather than a custom engine; the cell judgments reuse WS1's forward_invariance comparison.

Results (B200, TP4, official checkpoint)

Qwen3-Next batch invariance

One panel per cell family; a cell is green when the target's tokens, logits, logprobs and every layer digest are bitwise equal to its reference (concurrency N = 1 has no "last" position).

Stage Result
preflight passed
layers passed (5 real-weight TP4 gates, native scheduler 16 cases)
l2 16/16 bitwise rollout vs replay, every layer / sub-node / state digest
bi, full suite 97/97 cells bitwise (concurrency 13/13, interference 10/10, chunk 66/66, packing 8/8)

The quick suite (5 cells, including 64 concurrent requests) passed first as calibration. Summary, tested commit and commands: reports/experiments/qwen3_next/qwen3-next-batch-invariance-b200.md; raw stage records and bi_matrix.json ZIP (SHA-256 9312770b…54634), measured at 759755e.

Status

History

Tests

python -m pytest -q tests/models/qwen3_next/test_qwen3_next_bi_cases.py tests/validation/common/test_tensor_identity.py tests/models/qwen3_next/test_qwen3_next_chain_report.py \
    tests/models/qwen3_next/test_qwen3_next_evidence_redaction.py tests/validation/operators/test_forward_invariance.py tests/validation/operators/test_gradient_invariance.py
python -m pytest -q tests/models/qwen3_next/check_qwen3_next_bi_requests.py         # imports vLLM
python tools/validation/models/qwen3_next/qwen3_next_run.py --stage bi --previous <l2 run> --bi-suite {quick,full} ...
Check Result
Qwen3-Next CPU list in ci.yml + digest + forward-invariance tests 474 passed (99 CUDA-only skips)
layout check, pre-commit on all files, operator-case registry clean / up to date
dense gtest under the raw-bit judgment (Qwen3-8B C3/C4) 159 passed
after the refactor, B200: dense gtest + invariance judgments 227 passed
provider GPU checks incl. check_qwen3_next_bi_requests.py 142 passed (after the refactor); 208 passed at the stack top

Scope

CUDA, TP4 × EP1. The rollout profile caps a cell at 64 requests and 1040 tokens per sequence (prompt 1025 is out of range).

Results (H100 / Hopper, TP4 + batch-invariance CI subset)

Run on validation commit 91b77274 plus 2a8f18e4. 4 × NVIDIA H100 80GB, torch 2.13.0+cu130, vLLM 0.30.0, NCCL 2.29.7, checkpoint revision 9c7f2fbe. Raw data: hopper-qwen3-next/pr544.

At the time of this run the four-GPU preflight was gated on B200 (topology_mismatch: requires exactly four B200 GPUs), so commit 2a8f18e4 (the Hopper allowance from #557) was applied locally on top of the PR head; nothing else differs. Since c49419ae the allowance is part of this PR (from #543); the full 97-cell run at the new head is pending (see Status). Build flags: KERNEL_ALIGN_FORCE_SM90=1 KERNEL_ALIGN_DET_GEMM_SM90=1 TORCH_CUDA_ARCH_LIST=9.0. For full-model l2 on 4 × H100, local validation commits load Megatron recompute without DDP / optimizer (no giant FP32 grad buffer). These commits are for Hopper evidence only and are not merged upstream; patches are under pr_assets.

Stage Result
preflight passed
layers (all layer and scheduler gates) passed
l2 passed
bi (--bi-suite quick, CI batch-invariance matrix) passed

See chain/.

RFC RL-Align#428 batch_invariance_ci (CUDA).

- Stage bi (after a passed l2, same certified profile): 97 pinned cells in
  rl_engine/testing/qwen3_next_bi_cases.py / qwen3_next_bi_manifest.json.
  concurrency (1-64 requests, target first or last), interference
  (companion content, lengths, arrival during prefill/decode, generation
  lengths), chunk boundaries (prompts 63-1024 around 64/128/528/1024, chunk
  64/128, first chunk 1/63/65, compared with the replay recompute) and
  replay THD packing (1-7 neighbours, target first or last). A quick CI
  subset runs one cell per family plus 64 concurrent requests.
- Native rollout: version 2 requests run one traced target next to
  untraced companions; the exact-prefill scheduler admits each request at
  its arrival step, pins the target's planned chunk at every step and
  fails on any preemption; the trace records only the target.
- Replay: packed_layout() packs variable-length neighbours with the traced
  target in one THD batch.
- bi-matrix.json names each failing cell's first divergent layer, sub-node
  and layer family; the chain report gains a batch_invariance section, and
  the evidence publisher takes the bi run with --also.
- gtest: bitwise judgments compare raw bits (signed zero, NaN/Inf and
  dtype now count), not allclose with zero tolerance.

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

Batch-invariance chunk cells use prompts such as 129 tokens; the state-shape check only admitted the four L2 lengths, which their own validators already pin.

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

Merge the migrated full-model chain and move the batch-invariance work into
the new layout: the case generator and manifest into
rl_engine/validation/models/, the stage runner into tools/validation/models/,
its tests into tests/models/qwen3_next/. The raw-bit comparison for bitwise
judgments now lives in the canonical
rl_engine/validation/operators/forward_invariance.py (the old module is a
compatibility alias). The evidence README gives the commands in the current
layout and says where the runners were at the measured commit; no measured
file changed (SHA256SUMS verified).

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

coderabbitai Bot commented Oct 11, 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: e440dda0-44e7-4d6c-8e34-87b37e1c5292

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

tools/validation/models/plot_qwen3_next_batch_invariance.py draws, from the
published evidence only, one panel per cell family (concurrency, chunk
boundaries, interference, packing); a cell is green when tokens, logits,
logprobs and every layer digest are bitwise equal to its reference.

Signed-off-by: Wenbo Ji <[email protected]>
@fusheng-ji
fusheng-ji force-pushed the feat/ws1-qwen3-next-batch-invariance-ci branch from 1d5242e to 27515f8 Compare October 12, 2026 22:25
…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 the runner under ci/.

Signed-off-by: Wenbo Ji <[email protected]>
Per the layout review on RL-Align#549, this branch's own files move the way RL-Align#549
already moved them: the BI cases and manifest to
rl_engine/validation/models/qwen3_next/, the BI runner to
tools/validation/models/qwen3_next/, with imports and tests following.
The BI plot moves to the Qwen3-Next benchmark PR, and the committed BI
evidence is replaced by the summary RL-Align#549 already publishes (ZIP release
attachment, SHA-256, tested commit, commands).

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

Copy link
Copy Markdown
Contributor Author

Replies to the nine OpenCodeReview summary items:

  1. pyproject.toml L21, transformers range: same as the [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 reply: ==5.13.1 in the base would make the qwen3-next extra, which pins 5.17.0, unsatisfiable. Not changed.
  2. qwen3-next-provider-gpu.yml L34, paths: filter: fixed in part, in 2e85d223. pyproject.toml is added, because it now holds the pins. rl_engine/validation/operators/** is not added: no check_qwen3_next_* module imports forward_invariance; its users are validation/models/chain_gate.py and the chain report, which test_qwen3_next_chain_report.py runs on every PR in the CPU job.
  3. ci.yml L97, tests missing from the list: fixed in 2e85d223. test_qwen3_next_training_checkpoint.py and test_qwen3_next_vime_runtime_actor.py are in the CPU list; with CUDA hidden and vLLM blocked, they and two other unlisted CPU tests pass (70 passed, 4 skipped for the missing megatron). test_qwen3_next_vllm_attention_metadata.py imports vLLM at module level, so it cannot run in that job: it is in the provider job's pytest list instead (7 passed on vLLM 0.30.0).
  4. deterministic_attention.cu L222-L224, ROCm rejects D=256: not changed. D=256 is exercised on CUDA only (Qwen3-Next full attention) and I have not run it on ROCm, so the ROCm gate stays at 128 until that exists.
  5. deterministic_attn.py L31, Triton twin hard-codes 128: the behaviour is not changed; 2e85d223 adds a comment at _HEAD_DIMS. The twin raises ValueError for any D other than 128 (rl_engine/backends/shared/triton/attention/deterministic_attn.py:813-814) instead of diverging, so D=256 has no twin and fails loudly. Widening the twin is a separate change.
  6. qwen3_next_vllm_worker.py L29-L33, shared_l2_trace set after super().__init__(): not changed. Worker.__init__ in vLLM 0.30.0 does not call execute_model; the first call comes from warm-up and serving after construction (vllm/v1/worker/gpu_worker.py:811 is inside the warm-up method).
  7. qwen3_next_vllm.py L185-L190, aliased state in the no-reset path: not changed; the aliasing is the update. packed_recurrent_sequence returns the state it was given, and the result is written back with conv.copy_ and recurrent.copy_. The reset path clones because it has to zero the reset slots first. metadata_sequences raises unless the active requests have distinct positive slots (qwen3_next_vllm.py:84-85).
  8. qwen3_next_vllm_model.py L194, FP32 shared-expert activation: not changed. The training side does the same: qwen3_next_tp_blocks.py:375 computes (F.silu(gate.float()) * up.float()).to(hidden.dtype).
  9. qwen3_next_native_rollout.py L384-L387, ForceFrozenTokens indexing: not changed. The per-request callable receives that request's generated token ids (the output_tok_ids that AdapterLogitsProcessor registers, vllm/v1/sample/logits_processor/interface.py:386), and the version is fixed by the preflight at 0.30.0. index not in range(16) raises, so a shifted index could not pass silently.

@fusheng-ji

Copy link
Copy Markdown
Contributor Author

Replies to the three OpenCodeReview summary items:

  1. run_qwen3_next_chain_gate.sh L26-L29: fixed in 4e2c33af (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 81be0811); see the [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 reply.
  2. pyproject.toml L38, torch==2.13.0 without the CUDA label: not changed. ==2.13.0 does match 2.13.0+cu130, and the CUDA build is checked where it matters: the preflight raises environment_mismatch: requires CUDA toolkit 13.0.88 and a CUDA 13.0 torch runtime on torch.version.cuda != "13.0" (qwen3_next_preflight.py:99-102), and the provider job asserts torch.__version__ == "2.13.0+cu130". A requirement with the +cu130 label can only resolve against an index that serves local-labelled wheels, which the default index does not, so it would make pip install -e ".[qwen3-next]" fail on a host that has the right wheel installed already.
  3. deterministic_attention.cu L232-L233, same-device check: not changed; the validator already has it. check_deterministic_attention_inputs requires q.device() == k.device() && q.device() == v.device() (deterministic_attention.cu:204-205) and the mask to match q (:246-247), and the backward calls the same function (:578) before OptionalCUDAGuard.

fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 14, 2026
Provider job, chain preflight (failed at rollout-smoke), logprob prior art over
13 NCCL settings, EP matrix at 2c699e3, RL-Align#557 gates at f935bf3, RL-Align#549 parity
at 30c0e5a, RL-Align#543/RL-Align#544 preflight at their own heads. Redacted.

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

@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.

The batch-invariance changes look good and follow #497, please carry over #543’s Hopper fixes and validate the full 97-case suite on the submitted code before merging.

Comment on lines +87 to +88
if actual != expected:
raise ValueError("Worker imported a different CUDA binary than its stage built")

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
expected comes from the archived record, whose path is str(binary) built from Path(source).absolute() in archive_provider_binary (no symlink resolution), while imported_provider_identity() returns str(Path(filename).resolve(strict=True)). Whenever the workspace/build root is reached through a symlinked component (macOS /tmp → /private/tmp, container bind mounts, symlinked install trees), the same binary yields two different path strings, so this check raises "Worker imported a different CUDA binary than its stage built" even though the digests already match. Compare the content identity (sha256), and only treat paths as distinct when the expected path really resolves elsewhere.

Suggestion:

Suggested change
if actual != expected:
raise ValueError("Worker imported a different CUDA binary than its stage built")
if actual["sha256"] != expected["sha256"]:
raise ValueError("Worker imported a different CUDA binary than its stage built")

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

Signed-off-by: Wenbo Ji <[email protected]>
Comment on lines +115 to +120
for name, pinned in (
("transformers", "5.17.0"),
("triton", "3.7.1"),
("flashinfer-python", "0.6.18.post1"),
):
assert version(name) == pinned, f"{name} {version(name)} != {pinned}"

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
This block hard-asserts exact provider versions (transformers==5.17.0, triton==3.7.1, flashinfer-python==0.6.18.post1), but those exact pins live only in the new [project.optional-dependencies] qwen3-next extra. The base transformers dependency is now the range >=5.13.1,<=5.17.0 and the cuda extra allows flashinfer-python>=0.6.0,<0.7, so any install that does not explicitly request the qwen3-next extra (e.g. pip install -e .[cuda,vllm], or a constraints-free resolve) can legitimately land on a different in-range version and hard-fail this assertion for every PR touching the watched paths, regardless of code correctness. Ensure the install step in this job installs the qwen3-next extra (or otherwise pins these versions) before this assertion runs, otherwise the gate is environment-coupled rather than evidence of the intended runtime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Intended. The job installs nothing: it runs on a self-hosted runner that holds the audited Qwen3-Next runtime, and the step is there to fail when that runtime drifts. A different in-range version is a different runtime than the one the evidence was produced with, so failing is the expected result.

@fusheng-ji

Copy link
Copy Markdown
Contributor Author

OpenCodeReview (summary item, run of 2026-11-17) · ci/scripts/run_qwen3_next_chain_gate.sh (L42-L44): The gate validates cells type and schema version but never validates that passed is a boolean.

Fixed in bef6d13a on #543, merged into this PR in c6bd8466. A passed that is not a JSON boolean now goes through invalid() and exits 2. Checked by hand on a real chain report: true exits 0, false exits 1, and "false", 1 and null exit 2. No published chain report changes: build_report writes a Python bool.


if not native_tile_stats_available():
raise RuntimeError("Qwen3-Next logprob requires rebuilt CUDA tile-stat kernels")
selected, lse, entropy = CudaVocabParallelLogprobOp().apply_with_entropy(

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
apply_with_entropy is imported from the CUDA backend (CudaVocabParallelLogprobOp in rl_engine/backends/cuda/logprob/vocab_parallel_logp.py), but a repo search finds the method only defined in rl_engine/reference/logprob/vocab_parallel_logp.py. If the CUDA op does not inherit/implement apply_with_entropy (and accept num_vocab_tiles, validate, with_entropy_grad, deterministic), every Qwen3-Next training/rollout logprob call raises AttributeError/TypeError at runtime. Please confirm the CUDA class actually exposes this exact signature before merging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CudaVocabParallelLogprobOp subclasses VocabParallelLogprobOp (rl_engine/backends/cuda/logprob/vocab_parallel_logp.py:116) and inherits apply_with_entropy with that signature from rl_engine/reference/logprob/vocab_parallel_logp.py:683. The CUDA class sets use_native_tile_stats to its CUDA tile kernel, which the inherited path calls.

@Flink-ddd
Flink-ddd merged commit b215517 into RL-Align:test-qwennext Nov 19, 2026
9 checks passed
Flink-ddd pushed a commit that referenced this pull request Nov 19, 2026
Flink-ddd pushed a commit that referenced this pull request Nov 19, 2026
Flink-ddd pushed a commit that referenced this pull request Nov 19, 2026
…rovider job, #503 bias grad gate) into #549

Signed-off-by: Wenbo Ji <[email protected]>
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 19, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
…10-29).

Includes Run A/B reports, logs, and operators collection failure bundle for B200 review.
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
…e (2026-10-29).

Run A/B reports, logs, and operators collection bundle under pending/h100-qwen3-next-543-544/.
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
… evidence.

Operators and layers passed; L2 failed on Megatron load_checkpoint signature; timeout reruns attached.
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
Provider job, chain preflight (failed at rollout-smoke), logprob prior art over
13 NCCL settings, EP matrix at 2c699e3, RL-Align#557 gates at f935bf3, RL-Align#549 parity
at 30c0e5a, RL-Align#543/RL-Align#544 preflight at their own heads. Redacted.

Signed-off-by: Wenbo Ji <[email protected]>
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-model platform: cuda Specific optimizations or bugs in NVIDIA graphics cards (such as FlashInfer, TMA optimizations) qwen WS1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants