Repository navigation
[muse_spark] Use varlen attention in the CP-16 LoRA SFT recipe - #5706
Conversation
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 2m 57s —— View job Approve -- please address the items below before merging (one comment fix, an optional |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The change touches only the recipe, it is the smallest way to get varlen into the CP-16 LoRA recipe, and the kernel evidence supports it. The only open point is the 16-GPU run, which belongs to the author or a maintainer.
What this PR does. _muse_spark_816b_a42b now takes an attn_backend argument. The CP-16 LoRA SFT recipe passes "varlen" and pins every varlen layer to SDPBackend.FLASH_ATTENTION, which is FA4 on sm100. The Muse Ulysses CP map gains entries for VarlenInnerAttention and SlidingWindowVarlenInnerAttention. Without them, ContextParallelTransform.transform raises "No CP inner attention configured", because it looks up the exact owner type. The recipe no longer sets the flex FA4 kernel_options and block_size. After this change, the only flex attention left in the model is the vision encoder's (flavors.py:560), and this text-only recipe never runs it.
Example.
recipe: muse_spark_816b_a42b_ultradata_lora_sft_cp16_128k (CP 16, EP 16, Ulysses)
before: layers[*].attention.inner_attention = UlyssesFlexInnerAttention / UlyssesSlidingWindowFlexInnerAttention
kernel_options={"BACKEND": "FLASH"}, block_size=256
after: layers[*].attention.inner_attention = UlyssesVarlenInnerAttention / UlyssesSlidingWindowVarlenInnerAttention
sdpa_backends=[FLASH_ATTENTION]; window layers get window_size=(2047, 0) passed straight to FA4
other recipes calling _muse_spark_816b_a42b: unchanged (still flex)
Must fix
torchtitan_recipes/models/muse_spark.py:836: the comment blames torch for the cuDNN-first order, but the order comes from torchtitan's ownVarlenInnerAttention.Configdefault (inline comment).
Should consider
torchtitan_recipes/models/muse_spark.py:325: typeattn_backendasLiteral["flex", "varlen"]and drop the default, since there are only two callers (inline comment).
Questions
- Will the 16-GPU CP-16 LoRA run (loss and step time, main vs. this PR) happen before merge? Today the recipe's numerics change rests on per-layer kernel comparisons plus 2-GPU debug-model runs. CLAUDE.md asks for loss convergence on computation changes, and that run is the one direct check of the recipe that actually ships.
Details
- Ulysses varlen: after the all-to-all, each rank holds the full sequence for its head shard, so the document-causal and window metadata are the same as without CP. Under CUDA graphs, varlen needs
max_num_documents, and the UltraData loader sets it to 8 (muse_spark.py:697). - The
traverse(VarlenInnerAttention.Config)loop matches subclasses. That includes both Ulysses varlen configs and the sliding-window variant, so all 62 decoder layers get pinned. - The remat save region
attention.inner_attentionis matched by FQN, so attention is still saved, not recomputed, after the backend change. - The new CPU test is the only one that builds this recipe, and the build is where a missing CP-map entry would raise. That part of the test earns its cost.
Not verified: the GPU kernel times and the numerics. I couldn't run the new CPU test in this environment either. CPU CI was skipped because the base branch isn't main.
| for _, inner_attention, _, _ in config.model.traverse(FlexInnerAttention.Config): | ||
| inner_attention.kernel_options = {"BACKEND": "FLASH"} | ||
| inner_attention.block_size = 256 | ||
| # torch's default puts the 128k global layers on cuDNN, ~13% slower than FA4 here. |
There was a problem hiding this comment.
The cuDNN-first order isn't torch's default. It's torchtitan's own VarlenInnerAttention.Config.sdpa_backends default, [CUDNN_ATTENTION, FLASH_ATTENTION] (torchtitan/models/common/attention/attention.py:336). The loop also covers the window layers (traverse matches subclasses), not just the global ones. Suggested wording:
| # torch's default puts the 128k global layers on cuDNN, ~13% slower than FA4 here. | |
| # VarlenInnerAttention defaults to cuDNN first; on the 128k global layers it is ~13% slower than FA4. |
There was a problem hiding this comment.
Reply from claude: applied in 7734e68, with your wording. The default order comes from VarlenInnerAttention.Config.sdpa_backends, and the loop pins the window layers too; those already ran FA4 under the default order.
| seq_len: int | None = None, | ||
| *, | ||
| parallelism: ParallelismConfig | None = None, | ||
| attn_backend: str = "flex", |
There was a problem hiding this comment.
Two small points. This helper has only two callers (:486 and :764), so the "flex" default saves one argument at one call site and hides the choice there. Also, build_model_config accepts only "flex" and "varlen" (torchtitan/models/muse_spark/flavors.py:768). Consider attn_backend: Literal["flex", "varlen"] with no default, and pass attn_backend="flex" at :486.
There was a problem hiding this comment.
Reply from claude: keeping str with the "flex" default.
build_model_configtakesattn_backend: strand validates it (flavors.py:768), sostrmatches the function it forwards to.- The default keeps the Dist-MoE caller (
:486) byte-for-byte unchanged. The PR changes only the CP-16 recipe, and an earlier review round asked for exactly that.
3d56d65 to
7734e68
Compare
|
Reply from claude: on the 16-GPU question: not run yet. It's listed under NOTE and Follow up (loss and step time, main vs this PR), and the PR stays a draft until that run is posted. The evidence so far:
|
b152f1d to
38c378c
Compare
7734e68 to
e130bce
Compare
38c378c to
3f4cc0d
Compare
e130bce to
590bf90
Compare
3f4cc0d to
6c2cb34
Compare
590bf90 to
d8603fc
Compare
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 6s —— View job Approve: the earlier comment fix is in at HEAD, I found nothing new, and the 16-GPU run is still open. See the review. |
There was a problem hiding this comment.
Verdict: Approve -- the earlier must-fix is resolved at HEAD, I found nothing new, and the only open item is the 16-GPU run, which the author has committed to posting before the PR leaves draft.
What this PR does. _muse_spark_816b_a42b now forwards an attn_backend argument to build_model_config. The CP-16 LoRA SFT recipe passes "varlen" and pins every varlen layer to FLASH_ATTENTION, which is FA4 on sm100. The Muse Ulysses CP map gains the two varlen entries. Without them, the exact-type lookup in ContextParallelTransform would raise. Other callers of the builder still get flex.
Example.
recipe: muse_spark_816b_a42b_ultradata_lora_sft_cp16_128k (CP 16, EP 16, Ulysses, max_num_documents=8)
before: 16 global + 46 window layers -> Ulysses flex, kernel_options={"BACKEND": "FLASH"}, block_size=256
after: global -> UlyssesVarlenInnerAttention, window -> UlyssesSlidingWindowVarlenInnerAttention
sdpa_backends=["FLASH_ATTENTION"] (default would be ["CUDNN_ATTENTION", "FLASH_ATTENTION"])
_muse_spark_816b_a42b(seq_len=...) at muse_spark.py:484: unchanged (flex)
Status of the previous review
- Comment at
torchtitan_recipes/models/muse_spark.py:833: fixed. It now namesVarlenInnerAttention's own default (attention.py:375-376). attn_backend: Literal[...]with no default: the author declined. The builder accepts astrand validates it, and the default keeps the Dist-MoE caller unchanged. That reasoning holds, so I'm not raising it again.- 16-GPU loss and step-time run: still open. The author says the PR stays a draft until it is posted. fegin has approved.
Details
sdpa_backendsholdsSDPBackendmember names (Literal["CUDNN_ATTENTION", "FLASH_ATTENTION"],attention.py:372). They are resolved withgetattr(SDPBackend, name)at build time (attention.py:413). The new test's.build()call exercises that resolution and the CP-map lookup. Both would otherwise fail only at launch on 16 GPUs, so the test earns its cost.traverse(VarlenInnerAttention.Config)matches subclasses, so both Ulysses varlen configs are pinned."attention.inner_attention"in_MUSE_SPARK_DIST_MOE_SAVE_REGIONSis matched by FQN, so attention is still saved, not recomputed.- The KV all-gather CP map (
muse_spark.py:111) gets no varlen entries. Its callers stay on flex, which matches the description's scope.
Not verified: the GPU kernel times, the numerics, and the recipe on 16 GPUs.
6c2cb34 to
9510ed8
Compare
d8603fc to
1a5a740
Compare
The CP-16 LoRA SFT recipe now runs varlen attention on FA4 instead of flex on its FA4 backend, and the Muse Ulysses CP transform maps the varlen global and sliding-window layers. The base recipe and the Dist-MoE scale recipes keep flex.
9510ed8 to
64f48fa
Compare
1a5a740 to
86be8b1
Compare
## 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
The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes".
**Example.**
```text
before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention
after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake):
Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1,
32K sequence length, global batch 64, varlen attention with max_num_documents=64,
Adam moments in pinned host memory
```
## What changed
**Recipe helpers**
- `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`.
- It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs.
- The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config.
- The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`.
- Flex-Flash block-mask tuning applies only with FlexAttention.
- The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first.
**New recipes**
- `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions.
**README** (`torchtitan/models/muse_spark/README.md`)
- Context parallelism: varlen attention supports both Ulysses and K/V all-gather.
- CP load balancing: head-tail works with K/V all-gather varlen.
- K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention.
- Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`.
- A table lists the Dist-MoE scale recipes.
**Tests**
- The recipe tokenizer test covers the 64-GPU fake recipe.
- `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4.
## Numerics / performance
- The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs).
- `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs.
- Varlen K/V all-gather also runs with head-tail load balancing on the same layout.
## Testing
- Muse Spark recipe and model CPU unit tests.
- Both 64-GPU recipes build and pass `Trainer.Config` validation.
- `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build.
## Known issues / follow-ups
- `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main.
stack-info: PR: #5882, branch: fegin/stack/11
## 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
The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes".
**Example.**
```text
before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention
after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake):
Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1,
32K sequence length, global batch 64, varlen attention with max_num_documents=64,
Adam moments in pinned host memory
```
## What changed
**Recipe helpers**
- `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`.
- It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs.
- The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config.
- The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`.
- Flex-Flash block-mask tuning applies only with FlexAttention.
- The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first.
**New recipes**
- `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions.
**README** (`torchtitan/models/muse_spark/README.md`)
- Context parallelism: varlen attention supports both Ulysses and K/V all-gather.
- CP load balancing: head-tail works with K/V all-gather varlen.
- K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention.
- Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`.
- A table lists the Dist-MoE scale recipes.
**Tests**
- The recipe tokenizer test covers the 64-GPU fake recipe.
- `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4.
## Numerics / performance
- The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs).
- `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs.
- Varlen K/V all-gather also runs with head-tail load balancing on the same layout.
## Testing
- Muse Spark recipe and model CPU unit tests.
- Both 64-GPU recipes build and pass `Trainer.Config` validation.
- `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build.
## Known issues / follow-ups
- `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main.
stack-info: PR: #5882, branch: fegin/stack/11
## 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
The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes".
**Example.**
```text
before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention
after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake):
Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1,
32K sequence length, global batch 64, varlen attention with max_num_documents=64,
Adam moments in pinned host memory
```
## What changed
**Recipe helpers**
- `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`.
- It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs.
- The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config.
- The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`.
- Flex-Flash block-mask tuning applies only with FlexAttention.
- The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first.
**New recipes**
- `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions.
**README** (`torchtitan/models/muse_spark/README.md`)
- Context parallelism: varlen attention supports both Ulysses and K/V all-gather.
- CP load balancing: head-tail works with K/V all-gather varlen.
- K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention.
- Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`.
- A table lists the Dist-MoE scale recipes.
**Tests**
- The recipe tokenizer test covers the 64-GPU fake recipe.
- `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4.
## Numerics / performance
- The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs).
- `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs.
- Varlen K/V all-gather also runs with head-tail load balancing on the same layout.
## Testing
- Muse Spark recipe and model CPU unit tests.
- Both 64-GPU recipes build and pass `Trainer.Config` validation.
- `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build.
## Known issues / follow-ups
- `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main.
stack-info: PR: #5882, branch: fegin/stack/11
## Summary (human-written) With the CPU-offloading optimizer, we can run Muse Spark with 64 GPUs. This PR adds a recipe to demonstrate. ## Why The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes". **Example.** ```text before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake): Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1, 32K sequence length, global batch 64, varlen attention with max_num_documents=64, Adam moments in pinned host memory ``` ## What changed **Recipe helpers** - `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`. - It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs. - The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config. - The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`. - Flex-Flash block-mask tuning applies only with FlexAttention. - The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first. **New recipes** - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions. **README** (`torchtitan/models/muse_spark/README.md`) - Context parallelism: varlen attention supports both Ulysses and K/V all-gather. - CP load balancing: head-tail works with K/V all-gather varlen. - K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention. - Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`. - A table lists the Dist-MoE scale recipes. **Tests** - The recipe tokenizer test covers the 64-GPU fake recipe. - `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4. ## Numerics / performance - The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs). - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs. - Varlen K/V all-gather also runs with head-tail load balancing on the same layout. ## Testing - Muse Spark recipe and model CPU unit tests. - Both 64-GPU recipes build and pass `Trainer.Config` validation. - `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build. ## Known issues / follow-ups - `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main. stack-info: PR: #5882, branch: fegin/stack/11
## Summary (human-written) With the CPU-offloading optimizer, we can run Muse Spark with 64 GPUs. This PR adds a recipe to demonstrate. ## Why The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes". **Example.** ```text before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake): Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1, 32K sequence length, global batch 64, varlen attention with max_num_documents=64, Adam moments in pinned host memory ``` ## What changed **Recipe helpers** - `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`. - It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs. - The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config. - The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`. - Flex-Flash block-mask tuning applies only with FlexAttention. - The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first. **New recipes** - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions. **README** (`torchtitan/models/muse_spark/README.md`) - Context parallelism: varlen attention supports both Ulysses and K/V all-gather. - CP load balancing: head-tail works with K/V all-gather varlen. - K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention. - Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`. - A table lists the Dist-MoE scale recipes. **Tests** - The recipe tokenizer test covers the 64-GPU fake recipe. - `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4. ## Numerics / performance - The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs). - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs. - Varlen K/V all-gather also runs with head-tail load balancing on the same layout. ## Testing - Muse Spark recipe and model CPU unit tests. - Both 64-GPU recipes build and pass `Trainer.Config` validation. - `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build. ## Known issues / follow-ups - `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main. stack-info: PR: #5882, branch: fegin/stack/11
## Summary (human-written) With the CPU-offloading optimizer, we can run Muse Spark with 64 GPUs. This PR adds a recipe to demonstrate. ## Why The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes". **Example.** ```text before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake): Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1, 32K sequence length, global batch 64, varlen attention with max_num_documents=64, Adam moments in pinned host memory ``` ## What changed **Recipe helpers** - `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`. - It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs. - The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config. - The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`. - Flex-Flash block-mask tuning applies only with FlexAttention. - The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first. **New recipes** - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions. **README** (`torchtitan/models/muse_spark/README.md`) - Context parallelism: varlen attention supports both Ulysses and K/V all-gather. - CP load balancing: head-tail works with K/V all-gather varlen. - K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention. - Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`. - A table lists the Dist-MoE scale recipes. **Tests** - The recipe tokenizer test covers the 64-GPU fake recipe. - `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4. ## Numerics / performance - The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs). - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs. - Varlen K/V all-gather also runs with head-tail load balancing on the same layout. ## Testing - Muse Spark recipe and model CPU unit tests. - Both 64-GPU recipes build and pass `Trainer.Config` validation. - `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build. ## Known issues / follow-ups - `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main. stack-info: PR: #5882, branch: fegin/stack/11
## Summary (human-written) With the CPU-offloading optimizer, we can run Muse Spark with 64 GPUs. This PR adds a recipe to demonstrate. ## Why The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes". **Example.** ```text before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake): Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1, 32K sequence length, global batch 64, varlen attention with max_num_documents=64, Adam moments in pinned host memory ``` ## What changed **Recipe helpers** - `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`. - It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs. - The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config. - The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`. - Flex-Flash block-mask tuning applies only with FlexAttention. - The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first. **New recipes** - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions. **README** (`torchtitan/models/muse_spark/README.md`) - Context parallelism: varlen attention supports both Ulysses and K/V all-gather. - CP load balancing: head-tail works with K/V all-gather varlen. - K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention. - Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`. - A table lists the Dist-MoE scale recipes. **Tests** - The recipe tokenizer test covers the 64-GPU fake recipe. - `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4. ## Numerics / performance - The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs). - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs. - Varlen K/V all-gather also runs with head-tail load balancing on the same layout. ## Testing - Muse Spark recipe and model CPU unit tests. - Both 64-GPU recipes build and pass `Trainer.Config` validation. - `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build. ## Known issues / follow-ups - `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main. stack-info: PR: #5882, branch: fegin/stack/11
## Summary (human-written) With the CPU-offloading optimizer, we can run Muse Spark with 64 GPUs. This PR adds a recipe to demonstrate. ## Why The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes". **Example.** ```text before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake): Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1, 32K sequence length, global batch 64, varlen attention with max_num_documents=64, Adam moments in pinned host memory ``` ## What changed **Recipe helpers** - `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`. - It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs. - The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config. - The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`. - Flex-Flash block-mask tuning applies only with FlexAttention. - The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first. **New recipes** - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions. **README** (`torchtitan/models/muse_spark/README.md`) - Context parallelism: varlen attention supports both Ulysses and K/V all-gather. - CP load balancing: head-tail works with K/V all-gather varlen. - K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention. - Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`. - A table lists the Dist-MoE scale recipes. **Tests** - The recipe tokenizer test covers the 64-GPU fake recipe. - `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4. ## Numerics / performance - The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs). - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs. - Varlen K/V all-gather also runs with head-tail load balancing on the same layout. ## Testing - Muse Spark recipe and model CPU unit tests. - Both 64-GPU recipes build and pass `Trainer.Config` validation. - `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build. ## Known issues / follow-ups - `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main. stack-info: PR: #5882, branch: fegin/stack/11
## Summary (human-written) With the CPU-offloading optimizer, we can run Muse Spark with 64 GPUs. This PR adds a recipe to demonstrate. ## Why The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `_muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `_use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes". **Example.** ```text before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake): Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1, 32K sequence length, global batch 64, varlen attention with max_num_documents=64, Adam moments in pinned host memory ``` ## What changed **Recipe helpers** - `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend` and `max_num_documents`. It passes `attn_backend` to `_muse_spark_816b_a42b`. - It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs. - The FakePG data loader keeps `max_num_documents`. It now replaces only the dataset and shuffle fields of the data loader config. - The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`. - Flex-Flash block-mask tuning applies only with FlexAttention. - The 64-GPU recipe pins its varlen layers to FA4 (`sdpa_backends = ["FLASH_ATTENTION"]`), like the UltraData CP-16 recipe. The default order tries cuDNN first. **New recipes** - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat keeps the default save regions. **README** (`torchtitan/models/muse_spark/README.md`) - Context parallelism: varlen attention supports both Ulysses and K/V all-gather. - CP load balancing: head-tail works with K/V all-gather varlen. - K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention. - Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`. - A table lists the Dist-MoE scale recipes. **Tests** - The recipe tokenizer test covers the 64-GPU fake recipe. - `test_dist_moe_64_recipe_uses_kv_all_gather_varlen_on_fa4` builds the 64-GPU fake recipe. It catches a decoder layer that is not K/V all-gather varlen, or not pinned to FA4. ## Numerics / performance - The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs). - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. The FA4 pin gives no measurable tps change. Only this `_fake` variant was run, not the real recipe on 64 GPUs. - Varlen K/V all-gather also runs with head-tail load balancing on the same layout. ## Testing - Muse Spark recipe and model CPU unit tests. - Both 64-GPU recipes build and pass `Trainer.Config` validation. - `test_debug_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` catches a broken 64-GPU fake recipe build. ## Known issues / follow-ups - `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main. stack-info: PR: #5882, branch: fegin/stack/11
Stacked PRs: * #6252 * #5746 * #6135 * #6134 * #6133 * #6132 * __->__#5882 * #5881 (landed) --- --- --- ### [muse_spark] Add a 64-GPU Dist-MoE recipe with varlen attention ## Summary (human-written) With the CPU-offloading optimizer, we can run Muse Spark with 64 GPUs. This PR adds a recipe to demonstrate it. ## Why The Dist-MoE scale recipes run only on 256 or 512 GPUs, and they use FlexAttention only. #5706 added `attn_backend` to `muse_spark_816b_a42b` and listed three blockers for varlen in these recipes: their loader sets no `max_num_documents`, varlen K/V all-gather is untested on Muse, and `use_flex_flash_attention` raises on non-flex layers. This change removes those blockers and adds a 64-GPU recipe. It covers the #5706 follow-up "Varlen K/V all-gather CP for the Dist-MoE scale recipes". **Example.** ```text before: muse_spark_816b_a42b_dist_moe_bf16_spmd_256 / _512 only, FlexAttention after: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 (and _64_fake): Muse Spark 816B, BF16 Dist-MoE, DP8 / CP8 (K/V all-gather) / EP64, TP1, 32K sequence length, global batch 64, varlen attention with max_num_documents=128, Adam moments in pinned host memory ``` ## What changed **Recipe helpers** - `_muse_spark_816b_dist_moe_bf16_spmd` takes `attn_backend: Literal["flex", "varlen"]` and `max_num_documents`. It passes `attn_backend` to `muse_spark_816b_a42b`. - It sets the data loader's `max_num_documents` before `_with_dist_moe` enables CUDA graphs, because `Trainer.Config` validation checks varlen against CUDA graphs. - The FakePG data loader keeps `max_num_documents`. It replaces only the dataset and shuffle fields of the data loader config. - The K/V all-gather CP transform also maps `VarlenInnerAttention` and `SlidingWindowVarlenInnerAttention`. - Flex-Flash block-mask tuning applies only with FlexAttention. **New recipes** - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64` and `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake`. Remat also saves all attention regions (`attention.*`). - The 64-GPU recipe sets `fsdp_reshard_after_forward = "default"` instead of the helper's `"always"`. With PP off, only the last [norm, lm_head] FSDP unit changes: it stays unsharded after forward, so the loss does not all-gather the 3 GiB lm_head weight again. - `max_num_documents=128` is one slot per 256 tokens. The packer never drops documents: a row that reaches the cap ends early and is padded, and the rest of the document starts the next row. On C4 with the Muse Spark tokenizer (600 rows on each of 8 DP ranks), documents average 460 tokens. 64 slots pad 10.7% of the tokens, and 80% of the rows reach the cap. 128 slots pad none. - The data loader and AdamW configs are updated with `dataclasses.replace`, so their `__post_init__` checks run (`max_num_documents > 0`; `moment_cpu_offload_fraction > 0` needs `fused=True` and rejects accelerators other than CUDA, including ROCm). **README** (`torchtitan/models/muse_spark/README.md`) - Context parallelism: varlen attention supports both Ulysses and K/V all-gather. - CP load balancing: head-tail works with K/V all-gather varlen. - K/V all-gather CP needs tokens per microbatch divisible by the CP degree, or by 2 x the CP degree with head-tail. The query block size rule applies only with FlexAttention. - Varlen attention with CUDA graphs requires `dataloader.max_num_documents`. Without it, set `training.disable_accelerator_graphs`. - A table lists the Dist-MoE scale recipes. ## Numerics The 256- and 512-GPU and UltraData recipe configs are unchanged (0 field diffs). ## Testing - `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake` (NGPU=64, NUMA-bound) runs and fits on one GPU of the fake-PG layout for 10 steps. - Varlen K/V all-gather also runs with head-tail load balancing on the same layout. - Muse Spark recipe and model CPU unit tests. - Both 64-GPU recipes build and pass `Trainer.Config` validation. - `test_fake_scale_recipe_tokenizer[muse_spark_816b_a42b_dist_moe_bf16_spmd_64_fake]` builds the 64-GPU fake recipe. It catches a broken build, including a varlen layer type that the K/V all-gather CP map misses (the build raises "No CP inner attention configured"). ## Known issues / follow-ups - The real recipe ran on 64 GPUs for 20 steps at an earlier rebase of this stack, with the same save regions, real routing, and `max_num_documents=64`. Peak memory was 267.4 GiB (trainer) and 272.7 GiB (NVML) of 276.6 GiB, so only about 4 GiB is free. tps was about 2% higher than with the default save regions (1,716 vs 1,683). - On 64 real GPUs with the same setup, `fsdp_reshard_after_forward = "default"` lowered peak memory by 1.9 GiB (265.5 vs 267.4 GiB trainer, 270.8 vs 272.7 GiB NVML), and tps did not change (1,725 vs 1,716). The 256- and 512-GPU recipes keep `"always"`. - `max_num_documents=128` was run on 64 real GPUs only with the whole recipe stack, which also shards the vocab over CP and frees memory. There, peak allocated memory was the same as with 64 slots. It is not run at this commit alone, where only about 4 GiB is free. - tps counts padding tokens, and padding rows skip the routed experts. So 128 slots lower the reported tps but raise the real tokens trained per second. - `test_debug_recipe_tokenizer[muse_spark_debugmodel_mm]` also fails on main.
Summary (human-written)
Agent details
Written with Claude Code: the analysis, measurements and test plan below.
TLDR: The CP-16 LoRA SFT recipe moves from Ulysses flex on FA4 (256-token blocks) to Ulysses
varlen, pinned to FA4. The Muse Ulysses CP transform now maps the varlen global and sliding-window layers. Attention kernel time per 128k step drops by 16% on one document and by 25-30% when the 128k tokens hold 4-8 documents (the recipe packs up to 8). Step time was not measured. The shared 816B builder still defaults to flex, so the Dist-MoE scale recipes keep it.Independent: based on main. It touches only the Muse Spark recipe and its test.
Problem
_muse_spark_816b_a42b, hard-codesattn_backend="flex". The CP-16 LoRA SFT recipe then puts every flex layer on its FA4 backend with 256-token blocks.Solution
_muse_spark_816b_a42btakesattn_backend(default"flex", so other callers don't change). The CP-16 LoRA recipe passes"varlen".VarlenInnerAttentionandSlidingWindowVarlenInnerAttentionto their Ulysses versions. The transform matches exact types (config/transform/context_parallel.py:60-64), so both entries are needed.dataset_modalitiesis empty).Results
Decode and prefill: not touched (training recipe only).
You may ask: why not keep flex on FA4 for every Muse recipe? It's one backend, but the window layers, 46 of 62, take 1.7x longer on it.
You may ask: why not varlen in the Dist-MoE scale recipes too? Three things block it today:
max_num_documents. Under CUDA graphs, validation raises for any varlen layer without it (config/validation.py:100-107)._use_flex_flash_attentionraises on any non-flex layer (torchtitan_recipes/models/muse_spark.py:223).NOTE: kernel times only. Not run: the CP-16 LoRA recipe itself (16 GPUs), its step time and its loss curve.
Follow up
Test plan
test_cp16_lora_recipe_uses_ulysses_varlenbuilds the CP-16 recipe, checks that every decoder layer is Ulysses varlen, and builds each attention module (main'ssdpa_backendstakes backend names). It fails on main.validate_model_training_config(it runsvalidate_context_parallel): all pass, except the MXFP8 debug recipe, which needs a torchao nightly to build (an import error, same on main). Only the CP-16 LoRA recipe changes: 16 global + 46 window layers move from Ulysses flex to Ulysses varlen.max_num_documents8, deterministic, 6 steps, CUDA graphs on vs off. Loss and grad norm are bitwise equal at every step, including the 3 replays on new microbatches; the graphs run logs "Recorded CUDA graph forward_backward" on each rank.tests/unit_tests/cpu/recipes49 passed. pre-commit passes, pyrefly included.