feat(trainer): recurrent GDN forward matching vLLM decode for Qwen3.5 - #3214
Draft
hubert-marek wants to merge 1 commit into
Draft
feat(trainer): recurrent GDN forward matching vLLM decode for Qwen3.5#3214hubert-marek wants to merge 1 commit into
hubert-marek wants to merge 1 commit into
Conversation
The trainer computes GatedDeltaNet with FLA's chunked kernel while vLLM generates tokens with a fused recurrent kernel — two different algorithms whose outputs diverge in the low bits and compound through the recurrent state, producing a trainer/inference logprob mismatch on every sampled token. Add a `model.gdn_recurrent_forward` flag that runs the GDN forward through vLLM's own `fused_sigmoid_gating_delta_rule_update` kernel (imported lazily, so parity tracks vLLM rather than a vendored copy), with a chunked backward via FLA since the recurrent kernel has no backward. Gradients are unchanged from the training path; only forward activations move onto the generator's kernel. Off by default; not supported with context parallelism. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
The trainer computes GatedDeltaNet (Qwen3.5's linear attention) with FLA's chunked kernel, while vLLM generates tokens with a fused recurrent kernel. These are two different algorithms for the same function; their outputs diverge in the low bits and the divergence compounds through the recurrent state, so every sampled token carries a trainer/inference logprob mismatch that no amount of
cu_seqlensplumbing removes.This PR adds a
model.gdn_recurrent_forwardflag that runs the GDN forward through vLLM's ownfused_sigmoid_gating_delta_rule_updatekernel, with a chunked backward via FLA (the recurrent kernel has no backward — computingdgwithout materializing every state is an open problem). Gradients are bit-identical to the current training path; only forward activations move onto the generator's kernel.initial_state=None+ssm_state_indices=Nonemakes vLLM's kernel recompute full packed sequences from a zero state — exactly the training case, no cache machinery.Status / open items
This is a draft for early review. Known gaps, in order of when I'll hit them:
tests/unit/train/models/test_qwen3_5_gdn_parity.pyis the gate.autograd.Functionsaves tensors inforward; under the default fullcheckpoint_wrapperthis runs inside recompute and needs verification/fixing on GPU.mismatch_kl → 0additionally needs the server run with an fp32 SSM cache (vllm_extra: mamba_ssm_cache_dtype = "float32", no code change) and, for full parity, a recurrent GDN prefill on the vLLM side.Test plan
pytest tests/unit/train/models/test_qwen3_5_gdn_parity.py -v -son GPU (kernel parity, backward-equals-chunked, module wiring, conv diagnostic)mismatch_kl/all/meanvs a flagged-off baselineCo-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Made with Cursor