Repository navigation
[WS1][CUDA][Qwen3-Next] Strict GDN recurrence in one launch per layer - #744
fusheng-ji wants to merge 24 commits into
Conversation
…pped The step only asserted four visible GPUs. A missing vLLM, kernel or dtype support makes these modules skip, and pytest exits 0 for an all-skipped run, so the job reported a real-model pass that never ran. Apply the provider step's guard: tee the log, fail on any skip and require at least one pass. Signed-off-by: Wenbo Ji <[email protected]>
The case recorder wrote "skipped" for every report with wasxfail, so a non-strict xpass of a mandatory case showed up as a skip. Record xfail and xpass as themselves. The verdict is unchanged: xfail counts as a skip and xpass as a failure, and either fails the run. Signed-off-by: Wenbo Ji <[email protected]>
…constructor SharedQwenWorker assigned shared_l2_trace and the execution mode after Worker.__init__. vLLM 0.30.0's constructor calls no model method, so nothing read them early, but an override reached from a later vLLM's constructor would raise AttributeError. Assign both first; the contract test checks they exist when the native constructor runs. Signed-off-by: Wenbo Ji <[email protected]>
…ckages On an H100 host every rollout smoke aborted while FlashInfer loaded (__ffi_repr__ already registered): apache-tvm-ffi 0.1.16 in the user site-packages was imported ahead of the environment's own copy. The user site comes first on sys.path, so a package there replaces the environment's copy, and the environment identity listed both without flagging it. current_identity() now raises environment_mismatch when a distribution in the user site also exists in another installation root, and names the packages and PYTHONNOUSERSITE=1. Packages only in the user site are still recorded as before. The chain usage doc says so. Signed-off-by: Wenbo Ji <[email protected]>
On four H100s the l2 recompute failed in Megatron's validate_args, which requires CUDA_DEVICE_MAX_CONNECTIONS=1 with tensor parallelism. The B200 runs did not hit the check. The dense launcher already sets it; the Qwen3-Next stage environment did not. Set it next to the thread limits, outside provider_config.runtime_env, so the run manifest does not change. It limits the hardware work queues and does not change any kernel's arithmetic. The B200 chain has not been rerun with it. Signed-off-by: Wenbo Ji <[email protected]>
packed_recurrent_sequence launched vLLM's packed decode kernel once per token position from Python, so the GDN layers cost about 0.28 ms per token per layer on a B200, independent of batch and cache size. With 36 GDN layers that was about 10 ms per prompt token in strict vLLM prefill, VIME replay and the training forward. The forward now calls vLLM 0.30.0's fused_recurrent_gated_delta_rule, which runs the same per-token update with the same tiles (BK=128, BV=32, one warp, three stages) and the time loop inside one launch. It takes g and beta as inputs; a small Triton kernel computes them with the decode kernel's own loads, casts and expressions. Computing them in PyTorch instead changes low bits, so the copy is required. The backward differentiates the old per-token decode loop, now decode_loop_sequence, so gradients come from the same computation as before. GDNProviderConfig.recurrence is renamed, so an older certificate does not cover this provider. check_qwen3_next_gdn_sequence.py now also requires the one-launch forward to equal the decode loop bit for bit (output, final state, untouched slots of a 362-slot bank, mixed and zero lengths), and the gradients of both to be equal. On one B200 the layer takes 2.3 ms instead of 348 ms for 1024 tokens. Signed-off-by: Wenbo Ji <[email protected]>
…20261119 Signed-off-by: Wenbo Ji <[email protected]>
…perf/qwen3-next-gdn-fused-recurrence Stacks the one-launch GDN recurrence on the follow-up PR, which itself merged test-qwennext 12d5041. Signed-off-by: Wenbo Ji <[email protected]>
Bits against the per-token loop, the real-weight TP4 / EP4 chain and the strict path's time before and after, with a link to the raw results (release ZIP) and how to reproduce them. Signed-off-by: Wenbo Ji <[email protected]>
Signed-off-by: Wenbo Ji <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
📄
|
|
@fusheng-ji The automated OCR review has completed. Please review and address all automated review bot findings, then push your updates. Maintainers will begin manual review after the bot findings have been addressed. |
probe_environment ran qwen3_next_runtime.py --json with check_output, so a refusal in the child (environment_mismatch for a shadowing user site) reached the launcher as a bare 'returned non-zero exit status 1'. It now captures the child's stderr and raises a ProcessFailure with its tail and failure_kind. New test with a refusing stand-in interpreter (fails on the old code). Signed-off-by: Wenbo Ji <[email protected]>
…s against a reference The one-launch forward relied on vLLM 0.30.0 returning initial_state itself as the final state when inplace_final_state is set, and discarded the returned tensor. It now checks that the returned final state is the cloned bank and raises otherwise, so a provider that returned a separate tensor could not leave the state stale. The gradient check compared the one-launch backward with the decode loop, and both differentiate the same loop. A new check compares the forward and every input gradient with FP64 autograd of an independent PyTorch gated delta rule written from the kernel (relative error 1.4e-4 to 2.3e-3; a 10% wrong decay gives 2.4e-2 to 4.0e-2, over the 1e-2 bound). Signed-off-by: Wenbo Ji <[email protected]>
Any pip install --user leaves pip (and often wheel) in the user site next to the environment's copies, and the guard refused every run on such a machine although no stage imports them. They are now exempt. setuptools stays in the check: torch.utils.cpp_extension imports it for the JIT builds the stages allow. New test. Signed-off-by: Wenbo Ji <[email protected]>
Signed-off-by: Wenbo Ji <[email protected]>
|
Replies to the four OpenCodeReview findings routed to the summary (run on
GDN checks at this PR's head: 44 passed, on a B200 with |
| raise ProcessFailure( | ||
| f"environment probe exited with {result.returncode}:\n{tail}", | ||
| failure_kind=failure_kind(text=tail), | ||
| ) |
There was a problem hiding this comment.
The new refusal path depends on two helper contracts that are not changed in this diff: ProcessFailure(...) must accept a failure_kind= keyword, and failure_kind must accept a text= keyword here while the new test in test_qwen3_next_environment_identity.py calls failure_kind(error) with the exception positionally. If failure_kind only accepts one of these forms (or ProcessFailure has no failure_kind attribute/kwarg), both probe_environment and test_probe_keeps_the_child_refusal_and_its_failure_kind raise TypeError instead of surfacing the child's environment_mismatch, i.e. the refusal this PR is adding is lost. Please confirm/align the signatures (e.g. def failure_kind(error=None, *, text=None) and a failure_kind parameter on ProcessFailure) so the child message and its kind are preserved.
There was a problem hiding this comment.
Not changed: both signatures are already the ones asked for, in tools/validation/models/qwen3_next/qwen3_next_runtime.py:
class ProcessFailure(RuntimeError)has__init__(self, message, *, failure_kind)and storesself.failure_kind;def failure_kind(error=None, *, text="")returnserror.failure_kindfirst when it is a known kind, and otherwise classifies the error ortext.
So failure_kind(text=tail) in probe_environment and failure_kind(error) in the tests are both valid calls. test_probe_keeps_the_child_refusal_and_its_failure_kind runs that path with a child that refuses with environment_mismatch, and asserts the kind survives.
…ownloads are served as attachments); RL-Align#744 plot script Signed-off-by: Wenbo Ji <[email protected]>
…d lengths The FP64 reference gradient test now also runs lengths (16, 0, 9, 32), the mixed-length case that so far only had the self-comparison against the decode loop. That test is renamed for what it checks: the backward differentiates the decode loop by design, so it covers the wiring, not the gradient math. The rollout-sized bank case says the op is functional (the caller's bank keeps every byte, the slots it reads included), and the docstring says the input state is not modified. Signed-off-by: Wenbo Ji <[email protected]>
|
Reply to the OpenCodeReview finding routed to the summary (run on
|
| def _fused_sequence(qkv, a, b, A_log, dt_bias, state, indices, boundaries, *, num_k_heads, scale): | ||
| lengths = [end - start for start, end in zip(boundaries, boundaries[1:])] | ||
| if not max(lengths, default=0): | ||
| return qkv.new_empty((0, state.shape[1], 128)), state |
There was a problem hiding this comment.
The zero-token branch of _fused_sequence returns the caller's state tensor object unchanged, whereas every other path (and _PackedDecode.forward) returns a fresh clone. Because _PackedSequence.forward is a torch.autograd.Function and state is a normal forward input (often a leaf that requires_grad), returning an input as-is as a Function output means autograd will try to install a grad_fn on that same leaf tensor, which is not supported and can raise / corrupt the graph. It also makes packed_recurrent_sequence's "caller's state is not modified" invariant inconsistent: the returned state aliases the input, so mutating it later mutates the caller's tensor. This is reachable via a batch where all sequences have zero length (e.g. cu_seqlens=[0, 0]). Return a fresh tensor instead of the input, e.g. state.clone().
Suggestion:
| return qkv.new_empty((0, state.shape[1], 128)), state | |
| return qkv.new_empty((0, state.shape[1], 128)), state.clone() |
There was a problem hiding this comment.
Fixed in 7af7dad3: the all-empty path now returns state.contiguous().clone(), a new bank as on every other path.
New test test_all_empty_sequences_return_a_new_bank_and_backpropagate. It runs cu_seqlens = [0, 0] and checks three things: the returned bank does not share storage with the input, it is equal to it, and its gradient flows back to the input. On the old code it fails on the storage check (both data_ptr()s were equal). The GDN check set gives 46 passed on one B200.
…mpty The all-empty path returned the caller's bank itself, so the output aliased it, unlike every other path. It now returns a clone. New test, which fails on the old code: a new bank, equal to the input, and its gradient flows back. The gradient tests also assert that every gradient exists and is non-zero: the wiring test for each input, and the FP64 check for each reference gradient, so a zero reference cannot make the relative error vacuous. Signed-off-by: Wenbo Ji <[email protected]>
|
Replies to the three OpenCodeReview findings routed to the summary (run on 1.
2.
3.
|
…e constructor The existing check builds the worker without a config, so the mode it sees is None. The new check passes a config with an identity and asserts that the mode activated for it is already set when vLLM's Worker.__init__ runs; it fails if the worker drops the mode. Signed-off-by: Wenbo Ji <[email protected]>
Signed-off-by: Wenbo Ji <[email protected]>
|
Replies to the two OpenCodeReview findings routed to the summary (run on 1.
2.
|
| if not max(lengths, default=0): | ||
| # A new bank, as on every other path: the output must not alias the caller's state. | ||
| return qkv.new_empty((0, state.shape[1], 128)), state.contiguous().clone() |
There was a problem hiding this comment.
This forward special-cases an all-empty batch, but the backward path has no matching guard: _PackedSequence.backward calls _decode_loop, and decode_loop_sequence calls it directly, yet _decode_loop ends with an unconditional return torch.cat(outputs).index_select(0, order), state. With all sequences empty (max(lengths) == 0) the loop never runs, so outputs is empty and torch.cat([]) raises RuntimeError: expected a non-empty list of Tensors. The newly added test_all_empty_sequences_return_a_new_bank_and_backpropagate calls .backward() on exactly this case and will therefore fail, and decode_loop_sequence on an empty batch crashes too. Add an early return in _decode_loop (e.g. when max(lengths, default=0) == 0, return qkv.new_empty((0, state.shape[1], 128)), state preserving the grad link) so backward mirrors the forward's empty handling.
There was a problem hiding this comment.
Not changed: _decode_loop already handles the all-empty case, so the backward does not reach torch.cat([]).
- After its loop,
_decode_loopreturns early when no token ran:if not outputs: return qkv.new_empty((0, state.shape[1], 128)), state(qwen3_next_gdn.py, lines 180-181).statekeeps its gradient link, so the backward passes the bank's gradient through. test_all_empty_sequences_return_a_new_bank_and_backpropagateruns the backward on this case, and it passes: 46 passed at7af7dad3(1 × B200), withstate.grad == 2 * state.
…s a failure The worker execution-mode test also checks that the activator gets the configured identity itself, so a dropped or different identity fails it. A strict xpass gets its own case in the plugin test: pytest reports it as "failed" without wasxfail, and the report counts it under failures. Signed-off-by: Wenbo Ji <[email protected]>
Signed-off-by: Wenbo Ji <[email protected]>
…ownloads are served as attachments); RL-Align#744 plot script Signed-off-by: Wenbo Ji <[email protected]>
…_assets The release ZIPs were re-uploaded with the B200 PCI bus IDs masked, and pr_assets was rewritten to remove host and user identifiers. The merged batch-invariance, chain and EP4 logprob reports cite the ZIPs' new SHA-256, and the two RMSNorm docs link pr_assets c44f3f1 (was 692c408), which holds the same files. Signed-off-by: Wenbo Ji <[email protected]>
Signed-off-by: Wenbo Ji <[email protected]>
The release ZIP was re-uploaded with the B200 PCI bus IDs and a site home path masked; the report cites its new SHA-256. Signed-off-by: Wenbo Ji <[email protected]>
…ownloads are served as attachments); RL-Align#744 plot script Signed-off-by: Wenbo Ji <[email protected]>
The release asset qwen3-next-gdn-one-launch-b200-h100.zip was repacked with the numeric user and group IDs masked in its environment records and replaced. Update the SHA-256 the report cites. Signed-off-by: Wenbo Ji <[email protected]>
What
rl_engine/integrations/engines/train/vllm/qwen3_next_gdn.py,63d46013).gandbetawith the decode kernel's own expressions: softplus threshold 20,-exp(A_log) * softplus(a + dt_bias),sigmoid(b).fused_recurrent_gated_delta_rulethen runs the same per-token update with the same tiles (BK 128, BV 32, one warp, three stages), with the time loop inside the kernel.decode_loop_sequence, so gradients are unchanged.qwen3_next_provider.py).GDNProviderConfig.recurrencebecomesvllm-0.30.0-fused-recurrent-decode-gating, so a certificate made for the old code does not cover the new one.tests/models/qwen3_next/check_qwen3_next_gdn_sequence.py). Seven new checks compare the one-launch forward with the loop bit for bit, including a 362-slot state bank and mixed and zero lengths, and compare the gradients.reports/experiments/qwen3_next/qwen3-next-gdn-one-launch-b200-h100.md,76fbaadc).63d46013ae913959be9b0285)76fbaadcbb02a313a648241e0d5741f07e4c504c)7b5550b37af7dad394704c3e,69a74a5a,4ee99ab7a20cb715,41f79bbe,cfeadffd)9c0e5595a3374d26Prior art & reuse decision
fused_recurrent_gated_delta_rule(time loop inside one launch)g/betacomputed in PyTorchfused_recurrent_gated_delta_rule_packed_decode, per token (the old path)decode_loop_sequence, for backwardDecision: reuse vLLM 0.30.0's fused recurrent kernel with the decode kernel's own tiles, and write only the gating kernel, because PyTorch gating is up to 3e-5 off the decode kernel.
Left: one GDN layer on 1 × H100, the per-token loop against the one launch, all four cases bit-identical. Right: strict rollout prefill (time to the first token) on 4 × B200 before and after. Both from the files in the ZIP.
Results (B200 / Blackwell)
output_max_abs0.0). The one launch takes 1.14 / 3.19 / 4.49 / 2.15 ms for 64, 1024, 3365 and 16 × 512 tokens. The GDN, convolution and core checks: 43 passed.213a9bcd(the fix merged with the speed test's first commits, which do not touch the strict path):preflight,layers,l2andbi(full) passed; 97 / 97 cells; chain reportpassed=True, 16 cells; gate 17 passed.preflight,layersandl2passed.f5100979)213a9bcd)Results (H100 / Hopper)
At
213a9bcdon 4 × H100:preflight,layers,l2andbipassed; 97 / 97; gate rc 0.preflight,layersandl2passed (the first attempt met a foreign job on the node; the rerun passed).Invalid device idgroup, as in [WS1][CUDA][Qwen3-Next] Follow-up to the RFC #428 stack: CI skip guard, case outcomes, worker attributes, user-site guard, CUDA_DEVICE_MAX_CONNECTIONS #740.Status
a3374d26, stacked on [WS1][CUDA][Qwen3-Next] Follow-up to the RFC #428 stack: CI skip guard, case outcomes, worker attributes, user-site guard, CUDA_DEVICE_MAX_CONNECTIONS #740 (cfeadffd). Merge [WS1][CUDA][Qwen3-Next] Follow-up to the RFC #428 stack: CI skip guard, case outcomes, worker attributes, user-site guard, CUDA_DEVICE_MAX_CONNECTIONS #740 first; this branch then needs no change. Every commit is signed off.213a9bcd: the fix63d46013plus benchmark files.History
a648241e.0d5741f0:7b5550b3.failure_kindsignatures needed no change.7b5550b3:7af7dad3.1e-2bound.7af7dad3: both findings are in [WS1][CUDA][Qwen3-Next] Follow-up to the RFC #428 stack: CI skip guard, case outcomes, worker attributes, user-site guard, CUDA_DEVICE_MAX_CONNECTIONS #740's files.a20cb715, merged in94704c3e).94704c3e: no change. The decode loop already returns early on an all-empty batch, and the new test runs its backward. The finding has a reply. [WS1][CUDA][Qwen3-Next] Follow-up to the RFC #428 stack: CI skip guard, case outcomes, worker attributes, user-site guard, CUDA_DEVICE_MAX_CONNECTIONS #740's test commit is merged in69a74a5a.Tests
pytest check_qwen3_next_gdn_sequence.py check_qwen3_next_gdn_bridge.py check_qwen3_next_shared_core.py check_qwen3_next_core_matrix.py check_qwen3_next_conv_bridge.py_Cin the checkout, head0d5741f0ae913959, plus the independent-reference check)213a9bcdpytest check_qwen3_next_gdn_sequence.py7b5550b3pytest check_qwen3_next_gdn_sequence.py check_qwen3_next_gdn_bridge.py check_qwen3_next_shared_core.py check_qwen3_next_core_matrix.py check_qwen3_next_conv_bridge.py7af7dad3ae913959; 1 × H100 at213a9bcdpytest tests/models/qwen3_next/0ce47260(contains this PR)test_qwen3_next_training_checkpoint.pygroup:Invalid device idonce the cuDNN path is set, as on the B200 and H100 nodesmypy --ignore-missing-imports rl_engine/test-qwennext, in two other files)pre-commit run --from-ref be9b0285 --to-ref HEADScope / Known limitations
recurrenceenforces.