Repository navigation
[graph_trainer] Enable Kimi K2.7 in GraphTrainer - #5835
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 GraphTrainerKimiK25Model and its flavor builder so Kimi K2.7 (MLA flex attention with YaRN RoPE, MoE with shared experts) trains through GraphTrainer with SimpleFSDP, TP, EP, and PP. A vision encoder, QK clipping, or CP raises ValueError. QK clipping appends each step's attention logits to a Python list that the optimizer hook reads, and a traced step does not replay the append, so the GraphTrainer builder (without_qk_clip) uses plain flex attention. GraphTrainerModel.parallelize takes precedence over KimiK25Model's, so the wrapper repeats its CP check. Add a text-only debugmodel_text flavor (the debug decoder without its vision encoder). register_qk_clip_hook read the "loss" mesh with get_mesh, which raises without data or context parallelism, so every single-GPU Kimi K2.7 run failed at trainer construction. It now uses get_optional_mesh, and qk_clip skips the max all-reduce when there is no mesh. The test recipe returns a plain Trainer.Config because it trains with AdamW: the Kimi trainer config's DistMuon-only validation rejects TP whenever the config is re-validated. The Kimi K3 numerics helper is shared as _kimi_numerics. Testing: - test_bitwise_deterministic.py::TestKimiK27BitwiseDeterministic: 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). - test_numerics.py::test_moe_kimi_k2_7_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. - tests/unit_tests/gpu/models/kimi_k2_7/test_qk_clip.py passes.
SherlockNoMad
added a commit
that referenced
this pull request
Nov 9, 2026
Stacked on #5835. ## Summary (human-written) <!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why this approach, and what you checked yourself. --> ## Why GraphTrainer already runs Muse Glimmer in its integration tests, but nothing checks its numerics against eager, so a GraphTrainer change could silently alter Muse Glimmer's loss. The vision flavor (`debugmodel_mm`) also fails deep in tracing with a data-dependent-shape error instead of a clear message. **Example.** ```python to_graph_trainer_config(muse_glimmer_debugmodel_mm(), GraphTrainerMuseGlimmerModel.Config) # Before: fails during make_fx with a data-dependent-shape error # After: ValueError at config time: GraphTrainer MuseGlimmer supports # text-only flavors; got a vision encoder. ``` ## What changed - `graph_trainer/muse_glimmer/model.py`: the config rejects a vision encoder with `ValueError`, like Kimi K3, Kimi K2.7, and Qwen3.5 earlier in this stack. - Bitwise harness classes for Varlen and FlexAttention; a FlexAttention test recipe; 4-GPU numerics configs (FSDP2 + TP2); README row. ## Numerics Eager FSDP2 vs GraphTrainer, seed 42, deterministic, `scripts/loss_compare.py --assert-equal`. Measured on base `0f3481537`. Rebasing onto `d0ab95e46` changed only recipe field names in this diff (#5776, #5779); re-verification on the new base is in progress. | Config | GPUs | Result | | --- | --- | --- | | `debugmodel`, FlexAttention, FSDP2 + TP2, 20 steps | 4x GB300 | loss and grad_norm bitwise identical | | `debugmodel`, PP2 Interleaved1F1B, 10 steps | 2x GB300 | loss and grad_norm bitwise identical | The 4-GPU comparison uses FlexAttention. FA4's Varlen backward is not deterministic for full causal attention on Blackwell, so two Varlen eager runs with FSDP2 + TP2 already differ in grad_norm at step 1. ## Testing - `test_bitwise_deterministic.py::TestMuseGlimmerBitwiseDeterministic` and `TestMuseGlimmerFlexAttnBitwiseDeterministic` (1 GPU): eager vs aot_fx_trace, trace vs precompile, and `numerics_changing_optim` run-to-run produce bitwise identical loss, model hash, and gradient hash. - `test_numerics.py::test_dense_muse_glimmer_aot_fx_trace_vs_eager` (4 GPUs): the FSDP2 + TP2 row above. - The PP row was run locally; it is not a CI test. ## Known issues / follow-ups - CP is not covered. - Next in the stack: Muse Spark (in progress).
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 #5834.
Summary (human-written)
Why
Kimi K2.7 (MLA flex attention with YaRN RoPE, MoE with shared experts) has no
GraphTrainer model class. Separately, every single-GPU Kimi K2.7 run with QK
clipping fails at trainer construction on
main, becauseregister_qk_clip_hookreads the"loss"mesh withget_mesh, which raiseswhen neither data nor context parallelism is enabled.
Example.
What changed
graph_trainer/kimi_k2_7/:GraphTrainerKimiK25Model, itsbuild_model_config, andwithout_qk_clip. A vision encoder, QK clipping,or CP raises
ValueError. QK clipping appends each step's attention logitsto a Python list that the optimizer hook reads, and a traced step does not
replay the append, so the GraphTrainer builder uses plain flex attention.
GraphTrainerModel.parallelizetakes precedence overKimiK25Model's, sothe wrapper repeats its CP check.
models/kimi_k2_7/flavors.py: new text-onlydebugmodel_textflavor.models/kimi_k2_7/qk_clip.py:get_optional_mesh("loss");qk_clipskipsthe max all-reduce without a mesh.
test_qk_clip.pymocks the new call.torchtitan_recipes/tests/graph_trainer/kimi_k2_7.py. Itreturns a plain
Trainer.Configbecause it trains with AdamW: the Kimitrainer config's DistMuon-only validation rejects TP whenever the config is
re-validated.
numerics.py: the Kimi K3 numerics helper is shared as_kimi_numerics;README row.
Numerics
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_text, FSDP2 + TP2 + EP2, 20 stepsdebugmodel_text, PP2 Interleaved1F1B, 10 stepsTesting
test_bitwise_deterministic.py::TestKimiK27BitwiseDeterministic(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. It
runs on 1 GPU, so it also covers the
"loss"mesh fix.test_numerics.py::test_moe_kimi_k2_7_aot_fx_trace_vs_eager(4 GPUs): theFSDP2 + TP2 + EP2 row above.
tests/unit_tests/gpu/models/kimi_k2_7/test_qk_clip.pypasses.Known issues / follow-ups
ValueError(TODOs ingraph_trainer/kimi_k2_7/).