Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
cbdc00a
feat(qwen3-next): MoE route/combine contract with a batch-invariant g…
fusheng-ji Oct 9, 2026
fce346d
feat(qwen3-next): TP4 GDN, convolution and D=256 attention mixers
fusheng-ji Oct 9, 2026
362b80b
docs(qwen3-next): MoE route/combine contract, prior-art and TP4 evide…
fusheng-ji Oct 9, 2026
89b5212
Merge MoE route/combine evidence into the TP4 mixers
fusheng-ji Oct 9, 2026
bd13adc
test(qwen3-next): prior-art runner for the TP4 D=256 attention core
fusheng-ji Oct 9, 2026
c318687
docs(qwen3-next): TP4 mixer gates and D=256 attention prior-art evide…
fusheng-ji Oct 9, 2026
ce07836
Merge TP4 mixer evidence into the full-model chain
fusheng-ji Oct 9, 2026
92e93a4
feat(qwen3-next): full-model chain with first-drift localisation
fusheng-ji Oct 9, 2026
d6106c2
feat(qwen3-next): batch-invariance matrix for the full model
fusheng-ji Oct 9, 2026
02c576c
fix(qwen3-next): native state shapes for any prompt that fits the rol…
fusheng-ji Oct 9, 2026
193805d
Merge the evidence publisher fix into the batch-invariance matrix
fusheng-ji Oct 9, 2026
f431bad
fix(qwen3-next): evidence publisher redacts every recorded site path
fusheng-ji Oct 9, 2026
dc79953
test(qwen3-next): measure Megatron-core/TE and SGLang in the MoE prio…
fusheng-ji Oct 9, 2026
53dce6e
docs(qwen3-next): MoE prior art with Megatron-core/TE and SGLang meas…
fusheng-ji Oct 9, 2026
3c40295
Merge the MoE prior-art update into the TP4 mixers
fusheng-ji Oct 10, 2026
a97a6fe
test(qwen3-next): measure FlashAttention-4, Transformer Engine and Me…
fusheng-ji Oct 10, 2026
137d0fb
fix(qwen3-next): merge flat and per-size attention latency sections
fusheng-ji Oct 10, 2026
f01ab18
Merge test-qwennext refactor and migrate Qwen3-Next code and tests
fusheng-ji Oct 10, 2026
6b74b80
Merge test-qwennext refactor and migrate Qwen3-Next code and tests
fusheng-ji Oct 10, 2026
7317e5a
style(tools): mark the Qwen3-Next TP gate imports after sys.path setu…
fusheng-ji Oct 10, 2026
5cacf98
style(tools): mark the Qwen3-Next TP gate imports after sys.path setu…
fusheng-ji Oct 10, 2026
52b97e3
fix(qwen3-next): type annotations for mypy in the MoE prior-art runner
fusheng-ji Oct 11, 2026
d44704b
Merge the MoE prior-art type fix into the TP4 mixers
fusheng-ji Oct 11, 2026
4d7d3d8
fix(qwen3-next): type annotations for mypy in the attention prior-art…
fusheng-ji Oct 11, 2026
c331746
Merge test-qwennext refactor and migrate the Qwen3-Next full-model chain
fusheng-ji Oct 11, 2026
7bf6ef7
Merge test-qwennext refactor and migrate the Qwen3-Next batch-invaria…
fusheng-ji Oct 11, 2026
e485f0f
Merge the full-model chain evidence (c67ec14) into the migrated chain
fusheng-ji Oct 11, 2026
b66a8d0
build(pre-commit): leave the byte-exact Qwen3-Next chain evidence unt…
fusheng-ji Oct 11, 2026
13ba74a
Merge the full-model chain evidence into the batch-invariance matrix
fusheng-ji Oct 11, 2026
848ea44
build(pre-commit): leave the byte-exact batch-invariance evidence unt…
fusheng-ji Oct 11, 2026
84a7bfe
test(qwen3-next): pin the case-manifest subprocess rootdir to its tem…
fusheng-ji Oct 11, 2026
6684427
Merge the case-manifest test fix into the batch-invariance matrix
fusheng-ji Oct 11, 2026
cbb7b3d
docs(qwen3-next): figure for the full-model chain evidence
fusheng-ji Oct 11, 2026
e5a6987
Merge the chain evidence figure into the batch-invariance matrix
fusheng-ji Oct 11, 2026
9cc2fbc
docs(qwen3-next): figure for the batch-invariance evidence
fusheng-ji Oct 11, 2026
bddabba
test(qwen3-next): digest every TP4 cross-rank point and compare acros…
fusheng-ji Oct 11, 2026
99c244a
test(qwen3-next): require TP4 == TP1 for selected logprob and LSE only
fusheng-ji Oct 11, 2026
c5cea58
test(qwen3-next): prior art for the vocabulary-parallel selected-toke…
fusheng-ji Oct 11, 2026
da566bb
test(qwen3-next): no raw torch.distributed reduction in Qwen3-Next fo…
fusheng-ji Oct 11, 2026
f3a213d
docs(qwen3-next): TP distributed logprob contract and evidence figure
fusheng-ji Oct 11, 2026
682c233
test(qwen3-next): publisher for the distributed logprob parity evidence
fusheng-ji Oct 11, 2026
16171f5
docs(qwen3-next): record the prior-art NCCL-setting results and latency
fusheng-ji Oct 12, 2026
1106e46
refactor(qwen3-next): focus TP review on validation and externalize e…
fusheng-ji Oct 12, 2026
a9d0ba8
fix(qwen3-next): hash validation artifacts on Python 3.10
fusheng-ji Oct 12, 2026
722ef1c
docs(qwen3-next): record post-review B200 validation results
fusheng-ji Oct 12, 2026
d8333f4
fix(validation): stream artifact SHA-256 on Python 3.10
fusheng-ji Oct 12, 2026
b5708e9
fix(validation): retain batch invariance with Python 3.10 hashing
fusheng-ji Oct 12, 2026
7756969
fix(validation): keep standalone evidence runtime free of torch imports
fusheng-ji Oct 12, 2026
6c7c49c
fix(validation): keep standalone evidence runtime free of torch imports
fusheng-ji Oct 12, 2026
5a5aed4
fix(ci): resolve the repository root from ci/scripts/ in the Qwen3-Ne…
fusheng-ji Oct 13, 2026
25ded88
fix(ci): resolve the repository root from ci/scripts/ in the Qwen3-Ne…
fusheng-ji Oct 13, 2026
ffa0d1d
fix(ci): resolve the repository root from ci/scripts/ in the Qwen3-Ne…
fusheng-ji Oct 13, 2026
343c8c9
Merge the batch-invariance fixes into the TP logprob PR
fusheng-ji Oct 13, 2026
4746836
test(qwen3-next): drop the duplicate file_sha256 import left by the m…
fusheng-ji Oct 13, 2026
4daf3c4
Merge the latest #469 branch into the MoE route branch
fusheng-ji Oct 14, 2026
57216db
refactor(qwen3-next): MoE route branch to the reviewed layout
fusheng-ji Oct 14, 2026
f7338a7
Merge the MoE route layout change; TP4 mixers to the reviewed layout
fusheng-ji Oct 14, 2026
4ceaa22
Merge the TP4 mixers layout change into the full-model chain branch
fusheng-ji Oct 14, 2026
0d04347
refactor(qwen3-next): full-model chain to the reviewed layout
fusheng-ji Oct 14, 2026
0f5266d
Merge the full-model chain layout change into the batch-invariance br…
fusheng-ji Oct 14, 2026
299ea4c
refactor(qwen3-next): batch-invariance branch to the reviewed layout
fusheng-ji Oct 14, 2026
d18e0ff
Merge the batch-invariance layout change into the TP logprob branch
fusheng-ji Oct 14, 2026
d84fbf3
style(qwen3-next): black-format the relocated runtime path in the dig…
fusheng-ji Oct 15, 2026
e7d08a8
Merge the digest-test formatting fix
fusheng-ji Oct 15, 2026
c86ce74
Merge the digest-test formatting fix
fusheng-ji Oct 15, 2026
32040a7
docs(qwen3-next): record the full chain rerun on the stack top
fusheng-ji Oct 18, 2026
b59f628
Merge branch 'feat/ws1-qwen3-next-full-model-chain' into feat/ws1-qwe…
fusheng-ji Oct 18, 2026
7b71b93
docs(qwen3-next): record the full BI suite rerun on the stack top
fusheng-ji Oct 18, 2026
0165a26
Merge branch 'feat/ws1-qwen3-next-batch-invariance-ci' into feat/ws1-…
fusheng-ji Oct 18, 2026
8943c14
docs: move the measurement outputs out of the pull request
fusheng-ji Oct 19, 2026
0fdbf80
docs: move the measurement outputs out of the pull request
fusheng-ji Oct 19, 2026
46d5108
docs: move the measurement outputs out of the pull request
fusheng-ji Oct 19, 2026
8fd657c
docs: move the measurement outputs out of the pull request
fusheng-ji Oct 19, 2026
3d4fb2e
docs: move the measurement outputs out of the pull request
fusheng-ji Oct 19, 2026
bc43113
docs: point commit hashes at the rewritten history
fusheng-ji Oct 23, 2026
f9b85d1
docs: point commit hashes at the rewritten history
fusheng-ji Oct 23, 2026
4f61a39
docs: point commit hashes at the rewritten history
fusheng-ji Oct 23, 2026
804f0a4
docs: point commit hashes at the rewritten history
fusheng-ji Oct 23, 2026
78fc14a
docs: point commit hashes at the rewritten history
fusheng-ji Oct 23, 2026
68240ec
Merge #469 after #467 landed in test-qwennext
fusheng-ji Oct 26, 2026
b36b8f6
Merge #503 after #467 landed in test-qwennext
fusheng-ji Oct 26, 2026
d243839
Merge #507 after #467 landed in test-qwennext
fusheng-ji Oct 26, 2026
eb04b15
Merge #543 after #467 landed in test-qwennext
fusheng-ji Oct 26, 2026
fe6ed38
Merge #544 after #467 landed in test-qwennext
fusheng-ji Oct 26, 2026
cfbd101
Merge #469 review fixes
fusheng-ji Oct 26, 2026
d53ac95
ci(qwen3-next): trigger the provider job on validation/common
fusheng-ji Oct 26, 2026
c9a0aed
Merge #503 review fixes
fusheng-ji Oct 26, 2026
b9390f3
ci(qwen3-next): trigger the provider job on the CUDA sources it builds
fusheng-ji Oct 26, 2026
47b0c78
Merge #507 review fixes
fusheng-ji Oct 26, 2026
73872d5
chore(qwen3-next): executable operator-gate script; say what is check…
fusheng-ji Oct 26, 2026
9220f1a
Merge #543 review fixes
fusheng-ji Oct 26, 2026
b3bd4ea
Merge #544 review fixes
fusheng-ji Oct 26, 2026
9800e1a
Merge #469 second-round review fixes
fusheng-ji Oct 26, 2026
d849e18
Merge #503 second-round review fixes
fusheng-ji Oct 26, 2026
ecafcc2
Merge #507 second-round review fixes
fusheng-ji Oct 26, 2026
349d6ba
Merge #543 second-round review fixes
fusheng-ji Oct 26, 2026
e20c29b
Merge #544 second-round review fixes
fusheng-ji Oct 26, 2026
5ffd4c3
ci: run test_file_digest.py once in the CPU job
fusheng-ji Oct 26, 2026
d78b22b
ci(qwen3-next): trigger the provider job on the code this PR's checks…
fusheng-ji Oct 27, 2026
dfb0832
Merge #543 provider path-filter fix
fusheng-ji Oct 27, 2026
db1eb37
ci(qwen3-next): trigger the provider job on the distributed collectives
fusheng-ji Oct 27, 2026
3f7cf6e
Merge #544 provider path-filter fixes
fusheng-ji Oct 27, 2026
62cc122
fix(workload): sync operator case ids with pytest collection
fusheng-ji Nov 13, 2026
fd87c0e
feat(vime): load the Megatron model without DDP or an optimizer for r…
fusheng-ji Nov 13, 2026
f2e9aa9
Merge #543 operator-case ids and no-DDP recompute into #544
fusheng-ji Nov 13, 2026
7849c9c
Merge #544 operator-case ids and no-DDP recompute into #549
fusheng-ji Nov 13, 2026
1c68102
fix(vime): pass skip_load_to_model_and_opt to the VIME checkpoint loader
fusheng-ji Nov 13, 2026
1472e8f
Merge #543 load_checkpoint fix into #544
fusheng-ji Nov 13, 2026
dee7a78
Merge #544 load_checkpoint fix into #549
fusheng-ji Nov 13, 2026
2e85d22
ci(qwen3-next): assert the full pinned runtime, retrigger on pyprojec…
fusheng-ji Nov 13, 2026
74a1b1a
ci(qwen3-next): reject a malformed chain report with an explicit chec…
fusheng-ji Nov 13, 2026
7fee591
Merge #543 OCR round fixes into #544
fusheng-ji Nov 13, 2026
33e0ff6
Merge #544 OCR round fixes into #549
fusheng-ji Nov 13, 2026
4e2c33a
fix(ci): route unreadable chain reports to exit 2; fail closed on a m…
fusheng-ji Nov 14, 2026
81be081
Merge fix/543-ocr-r8 into fix/544-ocr-r8
fusheng-ji Nov 14, 2026
30c0e5a
Merge fix/544-ocr-r8 into fix/549-ocr-r8
fusheng-ji Nov 14, 2026
b15de6e
Merge branch 'test-qwennext' into feat/ws1-qwen3-next-distributed-log…
Flink-ddd Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,38 @@ jobs:

- name: Run Mocked Hardware Discovery Tests
run: |
python -m pytest tests/runtime/test_dispatch.py -v
python -m pytest tests/runtime/test_dispatch.py tests/validation/common/test_file_digest.py -v
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest tests/ops/attention/test_attention_correctness.py -q -rs
python -m pytest tests/validation/operators/test_forward_invariance.py tests/contracts/test_tolerance_contract.py tests/validation/operators/test_ws1_workload.py tests/validation/operators/test_gradient_invariance.py tests/validation/operators/test_elementwise_inventory.py tests/validation/operators/test_four_judgment_matrix.py tests/validation/operators/test_op_checks.py tests/validation/operators/test_operator_inputs.py tests/benchmarks/test_profiler.py tests/validation/operators/test_kv_consistency.py tests/models/qwen3/test_ws1_qwen3_dense.py tests/validation/models/test_ws1_chain_integration.py tests/models/qwen3_next/test_qwen3_next_norm.py tests/models/qwen3_next/test_gdn_state_contract.py -q
python -m pytest tests/validation/operators/test_forward_invariance.py tests/contracts/test_tolerance_contract.py tests/validation/operators/test_ws1_workload.py tests/validation/operators/test_gradient_invariance.py tests/validation/operators/test_elementwise_inventory.py tests/validation/operators/test_four_judgment_matrix.py tests/validation/operators/test_op_checks.py tests/validation/operators/test_operator_inputs.py tests/benchmarks/test_profiler.py tests/validation/operators/test_kv_consistency.py tests/models/qwen3/test_ws1_qwen3_dense.py tests/validation/models/test_ws1_chain_integration.py tests/models/qwen3_next/test_qwen3_next_norm.py tests/models/qwen3_next/test_gdn_state_contract.py tests/validation/common/test_tensor_identity.py tests/models/qwen3_next/test_qwen3_next_forward_contract.py tests/models/qwen3_next/test_qwen3_next_tp_blocks.py tests/models/qwen3_next/test_qwen3_next_tp_gdn.py -q
python -m pytest -q \
tests/models/qwen3_next/test_qwen3_next_binary_evidence.py \
tests/models/qwen3_next/test_qwen3_next_case_manifest.py \
tests/models/qwen3_next/test_qwen3_next_checkpoint.py \
tests/models/qwen3_next/test_qwen3_next_engine_weights.py \
tests/models/qwen3_next/test_qwen3_next_environment_identity.py \
tests/models/qwen3_next/test_qwen3_next_failure.py \
tests/models/qwen3_next/test_qwen3_next_imported_binary.py \
tests/models/qwen3_next/test_qwen3_next_installed_provider_identity.py \
tests/models/qwen3_next/test_qwen3_next_l2.py \

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 28-module qwen3_next block was appended to the "Run Mocked Hardware Discovery Tests" step, which does not build the rl_engine._C extension and is CPU-only. Several of the newly listed modules (e.g. test_qwen3_next_imported_binary.py, test_qwen3_next_installed_provider_identity.py, test_qwen3_next_storage.py, test_qwen3_next_training_checkpoint.py, test_qwen3_next_l2.py) exercise compiled-extension, vLLM-import or on-disk binary/provider evidence paths. Any module that imports those at module scope without pytest.importorskip/skip markers will fail collection here, turning the required CI job red instead of skipping. Please confirm each newly added module is import-safe on a runner without the extension/vLLM (or split these into their own step with the appropriate skip guard).

tests/models/qwen3_next/test_qwen3_next_layers.py \
tests/models/qwen3_next/test_qwen3_next_logprob_adapter.py \
tests/models/qwen3_next/test_qwen3_next_native_recompute.py \
tests/models/qwen3_next/test_qwen3_next_operator_gates.py \
tests/models/qwen3_next/test_qwen3_next_profile.py \
tests/models/qwen3_next/test_qwen3_next_rl_fixture.py \
tests/models/qwen3_next/test_qwen3_next_rotary_dtype.py \
tests/models/qwen3_next/test_qwen3_next_storage.py \
tests/models/qwen3_next/test_qwen3_next_training_audit.py \
tests/models/qwen3_next/test_qwen3_next_training_checkpoint.py \
tests/models/qwen3_next/test_qwen3_next_training_closeout.py \
tests/models/qwen3_next/test_qwen3_next_training_export.py \
tests/models/qwen3_next/test_qwen3_next_vime_runtime_actor.py \
tests/models/qwen3_next/test_qwen3_next_subnode.py \
tests/models/qwen3_next/test_qwen3_next_chain_report.py \
tests/models/qwen3_next/test_qwen3_next_run.py \
tests/models/qwen3_next/test_qwen3_next_evidence_redaction.py \
tests/models/qwen3_next/test_qwen3_next_bi_cases.py \
tests/models/qwen3_next/test_qwen3_next_tp_reductions.py

- name: Run Cross-Configuration Contract Tests (CPU-safe)
run: |
Expand Down
41 changes: 38 additions & 3 deletions .github/workflows/qwen3-next-provider-gpu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# RFC #428 Qwen3-Next provider comparisons: the C1/C3/C4 norm providers and the C6
# GDN decode-step goldens, each checked against the real vLLM 0.30.0 provider.
# RFC #428 Qwen3-Next provider comparisons: the C1/C3/C4 norm providers, the C6
# GDN decode-step goldens, the shared GEMM/MoE route-combine provider and the TP4
# GDN/convolution/attention mixers, each checked against the real vLLM 0.30.0 provider.
#
# These check_ files import vLLM, so the default pytest collection never runs them
# (tests/integrations/common/test_framework_operator_integrations.py asserts vLLM is not imported). This
Expand All @@ -23,10 +24,25 @@ on:
paths:
- "rl_engine/backends/**"
- "rl_engine/reference/**"
- "csrc/cuda/attention/**"
- "rl_engine/models/qwen3_next/**"
- "rl_engine/integrations/engines/train/vllm/qwen3_next*"
- "rl_engine/validation/models/qwen3_next*"
- "tools/validation/models/*qwen3_next*"
- "rl_engine/validation/models/qwen3_next/**"
- "tools/validation/models/qwen3_next/**"
- "tests/models/qwen3_next/**"
- "rl_engine/config/**"
- "rl_engine/validation/common/**"
- "csrc/cuda/norm/**"
- "csrc/bindings/**"
- "rl_engine/contracts/**"
- "csrc/cuda/logprob/**"
- "rl_engine/integrations/engines/rollout/vllm/qwen3_next*"
- "rl_engine/integrations/common/qwen3_next*"
- "rl_engine/integrations/orchestrators/vime/experiments/qwen3_next/**"
- "rl_engine/distributed/algorithms/collectives.py"
- "pyproject.toml"
- ".github/workflows/qwen3-next-provider-gpu.yml"
workflow_dispatch:
inputs:
Expand Down Expand Up @@ -92,6 +108,16 @@ jobs:
assert torch.__version__ == "2.13.0+cu130"
assert vllm.__version__ == "0.30.0"
assert torch.cuda.is_available()

# The rest of the pinned set in pyproject.toml's qwen3-next extra.
from importlib.metadata import version

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}"
PY
- name: Build the extension against that runtime
# The runner is long-lived: remove any extension or build tree left by an earlier
Expand All @@ -118,10 +144,19 @@ jobs:
print("rl_engine._C:", loaded)
PY
- name: Check pinned providers in their own process
# The FP32 router needs IEEE Triton dots from process start.
env:
TRITON_F32_DEFAULT: ieee
run: |
set -o pipefail
log="$RUNNER_TEMP/provider-pytest.log"
python3 -m pytest -q -rs tests/models/qwen3_next/check_qwen3_next_norm_providers.py tests/models/qwen3_next/check_gdn_recurrent_golden.py | tee "$log"
python3 -m pytest -q -rs tests/models/qwen3_next/check_qwen3_next_norm_providers.py tests/models/qwen3_next/check_gdn_recurrent_golden.py \
tests/models/qwen3_next/check_qwen3_next_forward.py tests/models/qwen3_next/check_qwen3_next_attention.py \
tests/models/qwen3_next/check_qwen3_next_gdn_bridge.py tests/models/qwen3_next/check_qwen3_next_gdn_sequence.py \
tests/models/qwen3_next/check_qwen3_next_conv_bridge.py tests/models/qwen3_next/check_qwen3_next_core_matrix.py \
tests/models/qwen3_next/check_qwen3_next_shared_core.py tests/models/qwen3_next/check_qwen3_next_paged_attention.py \
tests/models/qwen3_next/check_qwen3_next_batch_invariance.py tests/models/qwen3_next/check_qwen3_next_bi_requests.py \
tests/models/qwen3_next/test_qwen3_next_vllm_attention_metadata.py | tee "$log"
# Fail closed: these modules skip as a whole when CUDA or vLLM is missing, and pytest
# exits 0 for an all-skipped run. A skipped provider check is not provider evidence.
if grep -Eq '^SKIPPED|[0-9]+ skipped' "$log"; then
Expand Down
46 changes: 46 additions & 0 deletions ci/scripts/run_qwen3_next_chain_gate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Qwen3-Next chain-report adapter checks; with a report path, also validate that report.
# bash ci/scripts/run_qwen3_next_chain_gate.sh [chain-report.json]
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT"
PY="${PY:-python3}"
export PYTHONPATH="$ROOT${PYTHONPATH:+:$PYTHONPATH}"
"$PY" -m pytest -q tests/models/qwen3_next/test_qwen3_next_chain_report.py
if [ "$#" -ge 1 ]; then
"$PY" - "$1" <<'PY'
import dataclasses, json, sys

from rl_engine.validation.models.chain_gate import ChainGateReport
from rl_engine.validation.models.qwen3_next.qwen3_next_chain_report import COMPATIBLE_SCHEMA, SCHEMA_VERSION



def invalid(message):
"""Reject a malformed report with exit 2, apart from exit 1 for a failed gate."""
print(f"invalid chain report: {message}", file=sys.stderr)
sys.exit(2)


try:
with open(sys.argv[1]) as handle:
report = json.load(handle)
except (OSError, ValueError) as error:
invalid(f"cannot read {sys.argv[1]!r} as JSON: {error}")
if not isinstance(report, dict):
invalid(f"top level is {type(report).__name__}, expected an object")
# first_drift_family is added to the payload by build_report; it is not a dataclass field.
missing = ({f.name for f in dataclasses.fields(ChainGateReport)} | {"first_drift_family"}) - set(report)
if missing:
invalid(f"lacks report fields: {sorted(missing)}")
if not isinstance(report["cells"], dict):
invalid(f"cells is {type(report['cells']).__name__}, expected an object")
for key, expected in (("schema_version", SCHEMA_VERSION), ("compatible_schema", COMPATIBLE_SCHEMA)):
if report.get(key) != expected:
invalid(f"{key} is {report.get(key)!r}, expected {expected!r}")
print(f"passed={report['passed']} first_drift={report['first_drift']} "
f"family={report['first_drift_family']} cells={len(report['cells'])}")
sys.exit(0 if report["passed"] else 1)
PY
fi
10 changes: 10 additions & 0 deletions ci/scripts/run_qwen3_next_operator_gates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Required operator acceptance and diagnostics use separate declared case sets.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT"
PY="${PY:-python3}"
OUT="${QWEN3_NEXT_EVIDENCE_DIR:?Set QWEN3_NEXT_EVIDENCE_DIR to an artifact directory}"
export PYTHONPATH="$ROOT${PYTHONPATH:+:$PYTHONPATH}"
exec "$PY" tools/validation/models/qwen3_next/qwen3_next_operator_gates.py --out "$OUT" \
--suite "${QWEN3_NEXT_OPERATOR_SUITE:-all}"
2 changes: 1 addition & 1 deletion ci/scripts/run_ws1_gtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ print("[ws1-gtest] C8 gate passed")
PY

echo "[ws1-gtest] Qwen3-Next C3/C4 norms (operator scope)"
QWEN3_NEXT_NORM_MANIFEST=rl_engine/validation/models/qwen3_next_norm_manifest.json
QWEN3_NEXT_NORM_MANIFEST=rl_engine/validation/models/qwen3_next/qwen3_next_norm_manifest.json
# --hidden is the model hidden size the manifest pins: validate_norm_dimensions requires
# --hidden 2048 --head-dim 128 for both ops. rms_norm_gated does not run at 2048: its inputs and
# weight are built at --head-dim (128, the GDN value-head width), so the same flags give each
Expand Down
25 changes: 19 additions & 6 deletions csrc/cuda/attention/deterministic_attention.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace {

constexpr int64_t kDeterministicAttentionHeadDim = 128;
constexpr int kSoftmaxThreads = 256;

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -220,15 +219,18 @@ void check_deterministic_attention_inputs(
const int64_t Hkv = k.size(1);
const int64_t Skv = k.size(2);

TORCH_CHECK(D == kDeterministicAttentionHeadDim,
"deterministic_attention: head dim D must be ",
kDeterministicAttentionHeadDim,
", got ",
D);
#if defined(USE_ROCM)
TORCH_CHECK(D == 128, "deterministic_attention: ROCm head dim D must be 128, got ", D);
#else
TORCH_CHECK(D == 128 || D == 256,
"deterministic_attention: CUDA head dim D must be 128 or 256, got ", D);
#endif
TORCH_CHECK(k.size(0) == B && v.size(0) == B,
"deterministic_attention: batch size mismatch between q/k/v");
TORCH_CHECK(v.size(1) == Hkv && v.size(2) == Skv && k.size(3) == D && v.size(3) == D,
"deterministic_attention: k/v shape mismatch");
TORCH_CHECK(B > 0 && Hq > 0 && Hkv > 0,
"deterministic_attention: batch size and head counts must be positive");
TORCH_CHECK(Hq % Hkv == 0,
"deterministic_attention: Hq (",
Hq,
Expand Down Expand Up @@ -573,6 +575,17 @@ std::vector<torch::Tensor> deterministic_attention_backward(
double scale,
torch::optional<torch::Tensor> key_padding_mask) {

check_deterministic_attention_inputs(q, k, v, key_padding_mask);
TORCH_CHECK(grad_output.device() == q.device() && grad_output.scalar_type() == q.scalar_type(),
"deterministic_attention_backward: grad_output must match q device and dtype");
TORCH_CHECK(grad_output.sizes() == q.sizes(),
"deterministic_attention_backward: grad_output must have q shape");
TORCH_CHECK(P.device() == q.device() && P.scalar_type() == at::kFloat,
"deterministic_attention_backward: P must be FP32 on the input device");
TORCH_CHECK(P.dim() == 4 && P.size(0) == q.size(0) && P.size(1) == q.size(1) &&
P.size(2) == q.size(2) && P.size(3) == k.size(2),
"deterministic_attention_backward: P must have shape [B, Hq, Sq, Skv]");

const at::cuda::OptionalCUDAGuard device_guard(at::device_of(q));

auto dO = grad_output.contiguous();
Expand Down
2 changes: 2 additions & 0 deletions docs/operators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ Every operator page should include:
- [Token Embedding](embedding.md)
- [Qwen3-Next RMSNorm (zero-centred)](qwen3-next-rms-norm.md)
- [Qwen3-Next Gated RMSNorm](qwen3-next-rms-norm-gated.md)
- [Qwen3-Next MoE route / combine](qwen3-next-moe-route-combine.md)
- [Qwen3-Next distributed logprob parity (TP)](qwen3-next-distributed-logprob.md)
- [Operator Doc Template](../contributing/operator-doc-template.md)
2 changes: 1 addition & 1 deletion docs/operators/attention.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ for measured peak memory at representative shapes.

## Known Limitations

- First version: `D=128` only (Qwen3-8B alignment).
- Head dim: `D=128` (Qwen3-8B) on CUDA and ROCm; `D=256` (Qwen3-Next full attention) on CUDA only.
- Supported dtypes: BF16, FP16.
- Full materialization of scores/P limits practical sequence length.
- `Hq` must be divisible by `Hkv` (raises `ValueError` otherwise).
Expand Down
86 changes: 86 additions & 0 deletions docs/operators/qwen3-next-distributed-logprob.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Qwen3-Next distributed logprob parity (TP)

## Summary

RFC #428 row `distributed_logprob_parity` asks for a locked TP/EP reduction
order and an exactly equal selected-token logprob between VIME replay and vLLM
rollout. This page covers tensor parallelism (TP4, EP = 1, CP = 1) for
Qwen3-Next-80B-A3B-Instruct. Expert parallelism is a separate PR.

Every place where TP ranks combine values either moves bytes (an NCCL
all-gather, which is exact whatever NCCL algorithm runs) or sums them with
RL-Kernel's fixed-order collective, whose order does not depend on NCCL at all.
No new collective or kernel is added; the row documents and proves the order.

## Entry Point

```python
from rl_engine.models.qwen3_next.qwen3_next_tp import _ReduceFromTP, _CopyToTP
from rl_engine.models.qwen3_next.qwen3_next_logprob import qwen_logprob_contract
from rl_engine.models.qwen3_next.qwen3_next_forward import shared_logprob

contract = qwen_logprob_contract(local_logits, rank=rank, world_size=4)
selected, lse, entropy = shared_logprob(local_logits, targets, contract=contract, tp_group=tp_group)
```

vLLM rollout (`RLKernelQwen3NextForCausalLM.compute_selected_logprobs`) and VIME
replay (`calculate_log_probs_and_entropy`, installed by
`install_vime_logprob_provider`) both call `shared_logprob` on their own
37984-column LM-head shard.

## Contract

| Cross-rank point | Where | Operation | Order / dtype |
| --- | --- | --- | --- |
| Vocabulary-parallel embedding | `qwen3_next_embedding.shared_embedding` | each rank selects its rows, zeros elsewhere; sum | fixed-order collective, BF16; exactly one non-zero term per element |
| Embedding weight gradient | same, backward | stable sort by row, pairwise FP32 tree in token order | local, no collective |
| GDN `out_proj`, attention `o_proj`, MoE routed + shared output | `_ReduceFromTP` in `qwen3_next_tp_gdn`, `qwen3_next_tp_blocks`, vLLM adapters | row-parallel partial sums | fixed-order collective, BF16 |
| Input gradients of column-parallel projections | `_CopyToTP.backward` | sum of per-rank partial gradients | fixed-order collective |
| Selected-token logprob, LSE | `shared_logprob` (WS2 `CudaVocabParallelLogprobOp`) | per-rank FP32 max / sum-exp per tile, all-gather of tile statistics, merge in global tile order over a fixed `[tokens, 64]` grid | FP32; independent of the TP degree |
| Entropy | same | per-shard contributions, all-gather, sum in TP-rank order | FP32; depends on the TP degree (outside the selected-logprob contract) |
| Sampling logits | `compute_logits` (vLLM) | all-gather of the column shards | exact data movement |

RL-Kernel's fixed-order collective (`rl_engine.distributed.algorithms.collectives`,
backend `cuda_ipc_fixed_tree`) stages every rank's input in a symmetric CUDA IPC
buffer and runs one reduction kernel that reads all peers and applies the same
balanced tree on every rank; NCCL is not involved in the arithmetic, so
`NCCL_ALGO`, `NCCL_PROTO` and the channel count cannot change the result. The
logprob all-gathers move per-tile statistics whose merge order is fixed by the
tile index, so changing the TP degree does not change selected logprobs or LSE
either.

Fail-closed: `shared_logprob` rejects a vocabulary other than 151936, CP > 1, a
TP degree other than 1 or 4, non-finite logits and a missing contract; the
fixed-order collective checks on first use that every rank calls it with the
same shape and dtype, and supports only TP sizes 1, 2, 4 and 8. `tests/models/qwen3_next/test_qwen3_next_tp_reductions.py` fails
if a raw `torch.distributed` reduction appears in a Qwen3-Next model, engine or
VIME module (an integer MAX of per-rank flags is the one documented exception).

## Results

Evidence: [`reports/experiments/qwen3_next/qwen3-next-distributed-logprob-b200.md`](https://github.com/fusheng-ji/RL-Kernel/blob/feat/ws1-qwen3-next-distributed-logprob-tp/reports/experiments/qwen3_next/qwen3-next-distributed-logprob-b200.md).

- 13 NCCL settings (defaults; Ring and all-reduce Tree × LL / LL128 / Simple ×
1 channel / default channels), real Qwen3-Next weights, 1024 tokens, 4 × B200:
every point in the contract table has one digest per rank across all
settings, and the TP4 selected logprob and LSE equal TP1. The negative
control -- real attention `o_proj` partials summed with NCCL `all_reduce` --
gives 5 different results over the same settings.
- The full-model chain (#543) shows the end-to-end consequence: selected
logprobs of vLLM rollout and VIME recompute are bitwise equal for 16 cases at
four weight versions.

## Tests

| File | Device | Covers |
| --- | --- | --- |
| `tests/models/qwen3_next/test_qwen3_next_tp_reductions.py` | CPU | no raw NCCL reduction in Qwen3-Next forward paths; the TP reduction uses the fixed-order collective |
| `tools/validation/models/qwen3_next/qwen3_next_logprob_parity.py` + `..._compare.py` | 4 × CUDA | digests at every cross-rank point under each NCCL setting; TP4 == TP1 |
| `tests/distributed/tp/test_vocab_parallel_logp.py` (existing) | CUDA | WS2 TP = n == TP = 1 on synthetic shapes |

## Known Limitations

- TP4 with EP = 1 and CP = 1 only; expert parallelism is the second PR of this row.
- Entropy merges per-shard contributions in rank order and therefore changes
with the TP degree; rollout and replay run the same TP degree, so they still
agree, but entropy is not TP-degree invariant.
Loading
Loading