Repository navigation
[graph_trainer] Enable Qwen3.5 in GraphTrainer - #5834
Draft
SherlockNoMad wants to merge 1 commit into
Draft
SherlockNoMad wants to merge 1 commit into
SherlockNoMad wants to merge 1 commit into
Conversation
Add GraphTrainerQwen35Model and its flavor builder so Qwen3.5 (Gated DeltaNet and gated full-attention layers, MRoPE, MoE with a shared expert) trains through GraphTrainer with SimpleFSDP, TP, EP, and PP. Qwen3.6 and Qwen3.8 reuse Qwen35Model, so to_graph_trainer_config converts their flavors to the same wrapper. A vision encoder or CP raises ValueError: the vision encoder builds per-batch shapes from host-side image grids, and the GDN CP metadata (ContextParallelLinearAttentionMetadata and its Attention Gym routing) is not a traceable pytree yet. Add a text-only debugmodel_moe_text flavor (the debug MoE decoder without its vision encoder); qwen3_6 and qwen3_8 bind with_vision=True for their existing debugmodel_moe. GraphTrainer now requires dataloader.max_num_documents for linear-attention models. Without it, the varlen cu_seqlens length depends on each batch's document count, and the trace bakes the first batch's GDN chunk capacity into the packed kernels. A later batch with more documents overruns that capacity and reads uninitialized memory: on FSDP with deterministic algorithms (the fused GDN path), grads became NaN from step 2 in about a third of runs, and in every run with memory_policy="none". Fused chunk GDN takes BF16 Q/K/V only, so the bitwise harness gains a param_dtype for single-GPU runs that skip FSDP's mixed-precision cast, and hash_model hashes BF16 tensors through an int16 view because NumPy has no bfloat16. Testing: - test_bitwise_deterministic.py::TestQwen35MoEBitwiseDeterministic: eager vs aot_fx_trace, trace vs precompile, and numerics_changing_optim run-to-run are bitwise identical in loss, model hash, and gradient hash (GB300). The full file passes (30 passed, 10 skipped). - test_numerics.py::test_moe_qwen35_aot_fx_trace_vs_eager: eager FSDP2 vs GraphTrainer with FSDP2+TP2+EP2 on 4 GPUs, loss and grad_norm bitwise identical for 20 steps. - Local: Interleaved1F1B PP2 eager vs GraphTrainer on 2 GPUs, loss and grad_norm bitwise identical for 10 steps.
This branch has not been deployed
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.
Stacked on #5833.
Summary (human-written)
Why
Qwen3.5 (Gated DeltaNet and gated full-attention layers, MRoPE, MoE with a
shared expert) has no GraphTrainer model class. Enabling it also exposed a
silent failure for any linear-attention model in GraphTrainer. Without
dataloader.max_num_documents, the varlencu_seqlenslength depends on eachbatch's document count, and the trace bakes the first batch's GDN chunk
capacity into the packed kernels. A later batch with more documents overruns
that capacity and reads uninitialized memory.
Example.
What changed
graph_trainer/qwen3_5/:GraphTrainerQwen35Modeland itsbuild_model_config. Qwen3.6 and Qwen3.8 reuseQwen35Model, so theirflavors convert to the same wrapper. A vision encoder or CP raises
ValueError: the vision encoder builds per-batch shapes from host-side imagegrids, and the GDN CP metadata (
ContextParallelLinearAttentionMetadataandits Attention Gym routing) is not a traceable pytree yet.
graph_trainer/trainer.py:GraphTrainingEnginerequiresdataloader.max_num_documentswhen the model has linear attention.models/qwen3_5/flavors.py: new text-onlydebugmodel_moe_textflavor.qwen3_6andqwen3_8bindwith_vision=Truefor their existingdebugmodel_moe(mechanical).param_dtypefor single-GPU runs, which skip FSDP'smixed-precision cast (fused chunk GDN takes BF16 Q/K/V only).
tests/utils.pyhashes BF16 tensors through an int16 view because NumPy hasno bfloat16.
torchtitan_recipes/tests/graph_trainer/qwen3_5.py(fixedmax_num_documents); 4-GPU numerics configs; README row and note.User-facing changes
max_num_documents=Nonetrains and can silently produce NaN gradsValueErrorat engine constructionNumerics
Eager FSDP2 vs GraphTrainer, seed 42, deterministic,
scripts/loss_compare.py --assert-equal. Measured on base0f3481537.Rebasing onto
d0ab95e46changed only recipe field names in this diff(#5776, #5779); re-verification on the new base is in progress.
debugmodel_moe_text, FSDP2 + TP2 + EP2, 20 stepsdebugmodel_moe_text, PP2 Interleaved1F1B, 10 stepsTesting
test_bitwise_deterministic.py::TestQwen35MoEBitwiseDeterministic(1 GPU):eager vs aot_fx_trace, trace vs precompile, and
numerics_changing_optimrun-to-run produce bitwise identical loss, model hash, and gradient hash.
test_numerics.py::test_moe_qwen35_aot_fx_trace_vs_eager(4 GPUs): theFSDP2 + TP2 + EP2 row above.
Known issues / follow-ups
ValueError(TODO ingraph_trainer/qwen3_5/model.py).