Repository navigation
[rl] Qwen3.5 Unified Path in RL (bitwise parity, cudagraph, TP+DP/EP) - #3957
Merged
Merged
Conversation
wwwjn
force-pushed
the
wwwjn/qwen35-gdn-vllm-clean
branch
4 times, most recently
from
July 22, 2026 18:03
452fb33 to
9173d86
Compare
wwwjn
force-pushed
the
wwwjn/qwen35-gdn-vllm-clean
branch
5 times, most recently
from
July 22, 2026 20:02
6c426ca to
21848e7
Compare
wwwjn
commented
Jul 22, 2026
| activation: str = "silu" | ||
| kernel: GatedDeltaKernel.Config | ||
|
|
||
| def __init__(self, config: Config): |
Contributor
Author
There was a problem hiding this comment.
Add a new layer of abstraction in pretraining torchtitan which helps sort out the GDN computation, and can be replaced in vllm_wrapper.py
wwwjn
marked this pull request as ready for review
July 22, 2026 22:13
tianyu-l
requested changes
Jul 23, 2026
| return result[0] | ||
|
|
||
|
|
||
| class GatedDeltaCore(Module): |
Contributor
There was a problem hiding this comment.
Is Core a name widely accepted?
- now it's kernel inside core
- why not core inside kernel?
Contributor
Author
There was a problem hiding this comment.
Not really, the name "core" is not widely used. And we have two options here:
- Wrap and replace the whole GDN class with input/output projection
- Only wrap and replace the "core" part like we did for
inner_attention(), but have a better name , egGatedDeltaInnerAttentionorGatedDeltaConvRecurrence
From vllm side, it doesn't really matter which option we choose, because vllm only require the state cache read and write part register enough information, it doesn't really care about input/output projection
wwwjn
requested review from
yichuan-w
and removed request for
drisspg,
liangel-02 and
shuhuayu
July 23, 2026 02:30
liangel-02
reviewed
Jul 23, 2026
yichuan-w
reviewed
Jul 23, 2026
wwwjn
force-pushed
the
wwwjn/qwen35-gdn-vllm-clean
branch
from
July 23, 2026 15:09
49dac2f to
5c0773b
Compare
wwwjn
force-pushed
the
wwwjn/qwen35-gdn-vllm-clean
branch
2 times, most recently
from
August 19, 2026 20:47
a26aff9 to
6d6d65c
Compare
…ity, cudagraph, TP/EP) Runs torchtitan's hybrid Qwen3.5 (GatedDeltaNet linear-attention + full-attention [+ MoE]) inside vLLM for generation, borrowing only vLLM's paged conv/ssm cache and using the same fla kernels the trainer uses. Under batch-invariant mode the generator is bitwise-identical to the trainer forward -- the prerequisite for on-policy RL. Core: - gdn.py VLLMGatedDeltaNetCore: parameterless core owning only vLLM cache plumbing + fla kernels; conv + gated-delta recurrence run against the paged conv/ssm state (fla-only, no vLLM conv kernel). Recurrent-everywhere (prefill == decode) with fp32 recurrence + always-materialized initial state under BI. Registered as a real vLLM custom op (graph-split boundary). - Swappable core: GatedDeltaNet.core is a dense GatedDeltaCore in training, swapped to VLLMGatedDeltaNetCore in vLLM; both share the [B,L,...] + cu_seqlens signature. cu_seqlens from packed positions (#3892) resets state per packed sample. - Tensor parallelism: GDN head-sharded via a single local_map (training) and a DTensor<->local bridge (generator); qwen3_5 sharding honors enable_sequence_parallel (trainer SP on, generator SP off). TP + DP + EP compose for MoE flavors. - cudagraph FULL_DECODE_ONLY; align-mode mamba prefix caching. - Both paged states kept fp32 for bitwise parity: the ssm state AND the conv state (mamba_cache_dtype defaults to bf16, which makes decode round-trip the conv state through bf16 each step and drift from the single-pass prefill conv). Tests performed: - Batch-invariant parity (TestBitwiseParityQwen35Varlen): trainer<->generator prefill and generator decode-vs-prefill both bitwise (0.0) at TP=1 and TP=2; trainer batch invariance bitwise. - Generator TP=2 via generate.py: coherent, correct output; cudagraph FULL_DECODE_ONLY captured. - TP + DP + EP (debugmodel_moe) fwd+bwd OK (FSDP-DP and replicate-DP). - Non-BI pretraining conv path unchanged (identical loss). Co-authored-by: yichuan-w <[email protected]>
Co-authored-by: yichuan-w <[email protected]>
- Rename GatedDeltaCore -> GatedDeltaNetCore for the dense training core (model.py, __init__.py, and callsite comments). - Add get_first_inner_attention_config() and use it in the generator, trainer, controller, generate.py, and the bitwise-parity test in place of ad-hoc layer-0 / inline scans (hybrid models have no layer-0 attention). - Extract _configure_gdn_hybrid_model() for vLLM's hybrid-state contract. - Reword gdn.py into a paged-cache adapter; note that fused_recurrent_gated_delta_rule is shape-specialized on sequence length, which is why batch-invariant mode casts recurrence inputs to fp32. - Trim now-redundant comments/docstrings in config_registry, tests, and CI.
Run FLA's gated-delta recurrence once over the whole batch (decode and
prefill sequences delimited by cu_seqlens) instead of two per-segment calls.
torchtitan already runs recurrent-everywhere and the kernel processes each
sequence independently, so the merge is free; in batch-invariant mode (fp32
inputs) the recurrent kernel is shape-invariant, so every sequence's result
is bitwise-unchanged.
The convolution stays split by request type (decode -> single-token update
kernel, prefill -> varlen kernel): FULL-captured pure decode cannot run the
varlen conv, whose chunk-index prep host-syncs, which CUDA-graph capture
forbids. The unified initial-state gather uses plain integer indexing on the
captured pure-decode path (every decode resumes) and the boolean-mask gather
only on the eager prefill/mixed path, so no data-dependent indexing / host
sync enters a captured graph.
Also add docstrings noting get_state_{dtype,shape} are required by vLLM's
MambaBase interface, and expand the cu_seqlens-rebasing comments.
Verified: TestBitwiseParityQwen35Varlen (Qwen3.5-9B, TP=2, FULL_AND_PIECEWISE
cudagraph) -- all 3 subtests bitwise-identical (max_delta=0.00e+00), including
test_vllm_decode_vs_prefill, with 0 cudagraph-capture errors.
The GDN recurrence ran the sequential recurrent kernel for prefill and decode alike. Batch-invariant mode requires that (the trainer's BI forward uses the recurrent kernel, so the generator must match it bitwise), but non-BI prefill left throughput on the table. _run_recurrence now takes a use_chunk flag and calls fla.ops.gated_delta_rule.chunk_gated_delta_rule (parallel chunked scan) when it is set; _forward sets it for non-batch-invariant prefill/mixed batches (num_prefills > 0 and not batch-invariant). Batch-invariant mode and pure decode keep the recurrent kernel (decode is a single token and stays cudagraph-capturable). Both kernels share the same (q, k, v, g, beta, initial_state, output_final_state, cu_seqlens) interface and final-state layout, so the paged gather/scatter is unchanged. Verified: chunk vs recurrent numerically equivalent on a mixed varlen batch (bf16 inputs + fp32 initial_state); BI parity unchanged (TestBitwiseParityQwen35Varlen, 9B TP=2, all subtests max_delta=0.00e+00).
wwwjn
force-pushed
the
wwwjn/qwen35-gdn-vllm-clean
branch
from
August 19, 2026 23:35
6d6d65c to
94678a4
Compare
fegin
added a commit
that referenced
this pull request
Aug 20, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * __->__ #4242 Both #3957 and #4238 try to fix test_validate.py, which then cause merge conflict and cause duplicated fields.
wwwjn
added a commit
that referenced
this pull request
Sep 9, 2026
## Why The Qwen3.5 debug integration test in https://github.com/pytorch/torchtitan/actions/runs/34312737649/job/102342893821 generated rollouts indefinitely without producing a training step. Random-init policies can give every rollout in a group the same reward. With `drop_zero_std_reward_groups=True`, every such group is discarded, so the generator keeps replenishing work while the trainer waits forever for a batch. This is the same invariant addressed for earlier debug configs in #3802; the Qwen3.5 debug config added in #3957 omitted the override. ## What - Set `drop_zero_std_reward_groups=False` for the Qwen3.5 debug config. - Add the corresponding CLI override centrally to every command produced by the RL CI integration-test launcher, including multi-run tests. - Record consecutive untrainable groups at the batcher boundary: - each complete batch-sized block of untrainable groups emits a warning; - any trainable group resets the count; - 10 consecutive untrainable batches raise `RuntimeError` instead of hanging indefinitely. - Remove the resolved silent-hang TODO and add regression tests for the CI override, warnings, reset behavior, and terminal error. This follows Prime-RL’s generalized no-progress protection: https://github.com/PrimeIntellect-ai/prime-rl/blob/main/src/prime_rl/orchestrator/train_sink.py ## Testing - `python -m pytest torchtitan/experiments/rl/tests/test_async_controller.py torchtitan/experiments/rl/tests/test_rollout_utils.py -q` (27 passed) - Targeted watchdog tests after the final naming change (3 passed). - Targeted pre-commit hooks passed (Pyrefly skipped because RL experiments/tests are excluded by repository configuration and the configured local PyTorch tree is unavailable). - Python compilation passed for all changed files. - Validated that all 8 commands currently produced by the RL CI launcher contain the override. The focused launcher pytest could not be collected locally because this checkout environment lacks `grain`; CI installs the project requirements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In collaboration with and based on @yichuan-w 's works #3756
What & why
Runs torchtitan's hybrid Qwen3.5 (GatedDeltaNet linear-attention + full-attention [+ MoE]) inside vLLM for generation, borrowing only vLLM's paged conv/ssm cache and using the SAME
flakernels the trainer uses. Under batch-invariant mode the generator is bitwise-identical to the trainer forward -- the prerequisite for on-policy RL.Supported Feature
gdn.pyVLLMGatedDeltaNetCore: parameterless core owning only vLLM cache plumbing + fla kernels. conv + gated-delta recurrence run against the paged conv/ssm state (fla-only; no vLLM conv kernel -- it differs ~4e-4 and breaks parity). Recurrent-everywhere (prefill == decode) with fp32 recurrence + materialized initial state under BI. Registered as a real vLLM custom op (graph-split boundary).GatedDeltaNet.coreis a denseGatedDeltaCorein training, swapped toVLLMGatedDeltaNetCorein vLLM; both share the[B,L,...]+cu_seqlenssignature. cu_seqlens sourced from packed positions ([RL][qwen3_5] GDN: reset conv/recurrent state at packed sample boundaries #3892) resets state per sample.local_map(training) and a DTensor<->local bridge (generator); qwen3_5 sharding now honorsenable_sequence_parallel(trainer SP on, generator SP off).GatedDeltaNet.coreis a denseGatedDeltaCorein training, swapped toVLLMGatedDeltaNetCorein vLLM; both share the[B,L,...]+cu_seqlenssignature. cu_seqlens sourced from packed positions ([RL][qwen3_5] GDN: reset conv/recurrent state at packed sample boundaries #3892) resets state per sample.local_map(training) and a DTensor<->local bridge (generator); qwen3_5 sharding now honorsenable_sequence_parallel(trainer SP on, generator SP off).Validation
debugmodel_moe): fwd+bwd OK for DP + TP + EP.