Skip to content

rename ParallelDims to ParallelismContext - #4905

Merged
tianyu-l merged 1 commit into
mainfrom
parallel_dims
Sep 28, 2026
Merged

tianyu-l merged 1 commit into
mainfrom
parallel_dims

Conversation

@tianyu-l

@tianyu-l tianyu-l commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • rename ParallelDims to ParallelismContext across TorchTitan
  • rename the expert data-parallel shard axis from efsdp to edp_shard
  • move SPMD mesh activation to ParallelismContext.activate_spmd()

Testing

  • pre-commit run --all-files
  • focused pipeline, parallelism-context, and SPMD tests (90 passed)
  • focused FSDP, DistMuon, optimizer-consumer, and RL tests

@tianyu-l
tianyu-l added this pull request to stack #4906 September 26, 2026 23:09
@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Sep 26, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 26, 2026
@tianyu-l
tianyu-l force-pushed the parallel_dims branch 5 times, most recently from ac34f56 to b1ee52e Compare September 27, 2026 03:33
@tianyu-l
tianyu-l removed this pull request from stack #4906 September 27, 2026 04:41
@tianyu-l
tianyu-l added this pull request to stack #4910 September 27, 2026 04:41

@wwwjn wwwjn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside what Sanket founded (pls fix before merge), the rename should be safe

Base automatically changed from optimizer to main September 28, 2026 08:46
@tianyu-l
tianyu-l merged commit 5dc97a3 into main Sep 28, 2026
30 checks passed
@tianyu-l
tianyu-l deleted the parallel_dims branch September 28, 2026 08:47
meta-codesync Bot pushed a commit to meta-pytorch/flex_shard that referenced this pull request Oct 8, 2026
…anges

Summary:
Recent TorchTitan syncs changed several APIs that `experiments/fb/flex_shard` depends on, so `flex_shard_tests` now fails at import time (`unittest` `loadTestsFromName` ImportError). This diff moves the fb FlexShard code to the new APIs, fixes the EP>1 DistMuon break from #4419, and ports the Qwen3 recipe.

- pytorch/torchtitan#4904 (optimizer config refactor): `build_dist_muon(...)` is replaced by the `DistMuon(...)` class, which takes the same arguments. `comm_free_adapter.build_local_dist_muon` now constructs `DistMuon` directly.
- pytorch/torchtitan#4660 (`components.optimizer` -> `components.optim`, `Trainer.Config.optim`):
  - Imports now come from `torchtitan.components.optim`.
  - DSV3 Muon configs set `config.optim.optimizer`.
  - `FlexShardDistMuonOptimizers` accepts the new `enable_cuda_graph` kwarg. It raises if the flag is set, the same way upstream `OptimizersContainer` rejects optimizers that can't be captured.
  - `_log_optimizer` now takes a pattern string.
- pytorch/torchtitan#4617: `ParallelismConfig` now lives in `torchtitan.config.parallelism`.
- pytorch/torchtitan#4905:
  - `ParallelDims` is now `ParallelismContext`, and the `parallel_dims=` kwarg is now `parallelism_context=`.
  - `get_spmd_context(...)` is replaced by `parallelism_context.activate_spmd()`.
  - The `efsdp` mesh axis is now `edp_shard`. This also covers the `partition_rank_axis_name` passed to the DistMuon bucket planner.
  - Tests build the context with `ParallelismContext.from_config(config, DistributedTopology(world_size=...))`.
- pytorch/torchtitan#4840: `BlockShard(block_size=R)` is now `BlockShard(block_sizes=(R,))`.
- pytorch/torchtitan#4878: the DSV3 `model_registry` now requires `enable_sp`. The FlexShard wrapper passes `enable_sp=False`. FlexShard rejects TP, and `False` keeps the shared-expert `w2` as a plain `Linear`, as it was before #4878.
- pytorch/torchtitan#4419 (EP without DTensor): `Module._parallelize` now leaves EP-sharded routed experts as plain local `nn.Parameter` shards. It records their layouts in each module's `_sharding_config` instead of returning DTensors. With EP>1, DistMuon failed with "Partitioned block parameters must be DTensors", and `dtensor_to_global_layout` no longer found anything to declare.
  - flex_shard `dist_muon/placement.py` and `storage_layout.py` now read the FlexShard `GlobalLayout` contract (`get_global_layout`) instead of DTensor placements. `get_dim0_block_partitions` no longer takes `partition_axis_name`.
  - The new `experiments/fb/flex_shard/spmd_layouts.py` `declare_spmd_global_layouts(model, mesh)` collects `_sharding_config.state_shardings` and declares them through `spmd_types_to_global_layout`. The DSV3 recipes and tests call it where they used to call `dtensor_to_global_layout`.
- EP>1 configs now need `training.disable_cuda_graphs`: upstream config validation rejects CUDA graphs with the all-to-all token dispatcher. `flex_shard_deepseek_v3_debug_muon` sets EP=2 after construction, so it skipped that check and would fail when launched from the CLI. It now disables CUDA graphs, as upstream EP configs do.
- Qwen3 recipe port. It was broken before these syncs, by `protocols.model_spec`, `FusedQKVLinear`, `components.metrics`, `tools.logging`, `default_adamw` and `set_spmd_backend`.
  - It follows the DSV3 pattern: `FlexShardQwen3Model(Qwen3Model)` with `Config.muon_pattern`, and `parallelize()` runs `parallelize_qwen3_muon` under `activate_spmd()`.
  - Configs are rebuilt on the current `Trainer.Config` fields with the same hyperparameters.
  - Q/K/V BlockShard plans use the fused `QKVLinear.wqkv`: one `head_dim`-row matrix per Q/K/V head.
  - `parallelize_qwen3_muon` uses `dp_shard`, always calls `_parallelize` (as DSV3 does), and declares the EP layouts.
- DSV3 `test_debug_muon_train_step` now disables autograd multithreading, as upstream `init_distributed` does. The SPMD mesh is thread-local, and FSDPTest skips `init_distributed`. So selective-AC recompute ran on an autograd device thread with no mesh set, the MoE token dispatch skipped EP there, and backward failed in `torch._grouped_mm` with "matrix batch sizes have to match". The upstream Trainer is not affected: the DSV3 debug model with EP=2 + SAC trains normally.

The `comm_free_adapter` change is the same as the one in D122391176, the auto-generated Test Blame fix. This diff also covers the other breakages in fb/flex_shard.

The DistMuon tests (DSV3 `test_shard0_owned_mixed` and `test_debug_muon_train_step`, and Qwen3 `test_debug_muon_train_step`) now get past every API break. They still fail on the fused `w13` weights, which the next diff (D122443668) fixes.

Reviewed By: weifengpy

Differential Revision: D122692766

Pull Request resolved: #50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants