Repository navigation
fix(qwen3_5, qwen3_8_flash_next, nemotron_h): per-layer cu_seqlens so FLA's tensor cache matches across AC recompute - #3880
Closed
faresobeid wants to merge 2 commits into
Closed
faresobeid wants to merge 2 commits into
faresobeid wants to merge 2 commits into
Conversation
…or FLA's tensor cache
Contributor
Author
|
Closing: superseded by #3833, which sets fla.utils.FLA_DISABLE_TENSOR_CACHE=True globally (also covers Nemotron-H) and passes cu_seqlens_cpu — fixes the same activation-checkpoint replay mismatch. |
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.
Qwen3.5-MoE (
qwen3_5_moe_text) training withep > 1and activation checkpointing crashes in backward withValueError: Pointer argument cannot be accessed from Triton (cpu tensor?)in torchtitan'sgenerate_permute_indices.Root cause
cu_seqlensmetadata (prepare_chunk_indices, …) with@tensor_cache, which matches arguments by tensor identity.cu_seqlensobject. The first linear-attention layer misses that cache in the forward. In its AC recompute (it runs last in backward) it hits the cache, so the recompute runs fewer ops (feweraten::_to_copy, among others).(op, invocation index). The AC policy MUST_SAVEs CUDA→CPU copies, which includes the EP dispatcher's.cpu()of the split sizes. Because of the shifted index, the.to(torch.int32)insidegenerate_permute_indicesgets that saved CPU tensor back.m_sizes/write_offsetsend up on CPU, and the Triton fill-indices kernel rejects them.m_sizesandwrite_offsetswere oncpuonly in the 4th recompute (layer 0), while their inputtotal_tokens_per_expertwas oncuda:0._to_copyafter the mismatch, so the shift was silent.Fix
Qwen3_5GatedDeltaNettakes a per-layercu_seqlens.clone(). Every layer then starts with a cache miss, in the forward and in the recompute alike, so both passes run the same op sequence. FLA still caches within a layer.Checks (1 node, 2 GPUs per run, released)
SFT, 3 steps, fake data, default AC. The tiny HF-format Qwen3.5-MoE has 4 layers (3 linear + 1 full attention), 16 experts, top-4, hidden 512, random HF init:
Pointer argument cannot be accessed from Triton (cpu tensor?)model.debug4-layer random-init runs with ep=2, all of which complete 3 steps with this PR:Qwen/Qwen3.5-35B-A3B(crashes on main),Qwen/Qwen3-30B-A3B,zai-org/GLM-4.5-Air. (random_initleaves zero weights, so these only check the code path.)ruff check/ruff format --checkare clean.pytest -m "not gpu" tests/unit/orchestrator tests/unit/test_configs.py tests/unit/train: 441 passed, 1 failed. The failure istest_cpu_adam.py::test_native_cpu_adamw_matches_fused_torch_and_preserves_gradients, which also fails on origin/main here.Same pattern in other models
qwen3_8_flash_next/gated_delta_net.pyandnemotron_h/mamba.pyalso pass the sharedcu_seqlensinto FLA's identity cache inside checkpointed layers. Both get the same one-line clone.debug.random_init, ep=2, 3 steps: main and this PR both finish with the same losses (11.7835 ×3). Each Nemotron-H block holds only one mixer (mamba, MoE, or attention), so on main the shifted replay inside a mamba block never reaches a saved MoE.cpu(). The clone keeps the forward and the recompute consistent there anyway.prime_kernelshas noindexed_attentionkernel, so main and this PR both fail to build the model. The fix is by analogy with Qwen3.5: the GatedDeltaNet and the MoE share one decoder layer.Relation to #3864 (closed)
#3864 fixed the same FLA-cache-vs-AC-recompute mismatch for
cp > 1. It builds the FLA CP context once in the model, before the layer loop. It touches the sameforwardin both GatedDeltaNet files and removes the per-layerbuild_cp_context. This PR covers the defaultcp = 1path, where FLA derives its metadata fromcu_seqlensinside each layer. The two fixes are independent. If #3864 is reopened, the conflict is a small context conflict at the top offorward. Under CP the clone only feeds thecu_seqlens.to(...)passed tobuild_cp_context, so it is harmless there.