Skip to content

[spmd_types] helion rope & fused_swiglu rules - #3741

Merged
pianpwk merged 47 commits into
mainfrom
gh/pianpwk/50/head
Jun 26, 2026
Merged

[spmd_types] helion rope & fused_swiglu rules#3741
pianpwk merged 47 commits into
mainfrom
gh/pianpwk/50/head

Conversation

@pianpwk

@pianpwk pianpwk commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Wrap Helion RoPE and fused SwiGLU with explicit spmd.local_map calls

Test Plan:

  • NGPU=8 LOG_RANK=0 MODULE=qwen3 CONFIG=qwen3_debugmodel_fused_qkv ./run_train.sh --parallelism.spmd_backend spmd_types --debug.spmd_typechecking --parallelism.data_parallel_shard_degree 2 --parallelism.context_parallel_degree 2 --parallelism.tensor_parallel_degree 2 --training.steps 1 --override.imports torchtitan.overrides.helion_rope activation-checkpoint:none

  • NGPU=8 LOG_RANK=0 MODULE=deepseek_v3 CONFIG=deepseek_v3_debugmodel ./run_train.sh --parallelism.spmd_backend spmd_types --debug.spmd_typechecking --parallelism.data_parallel_shard_degree 2 --parallelism.context_parallel_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2 --training.steps 1 --override.imports torchtitan.overrides.fused_swiglu activation-checkpoint:none

pianpwk added 2 commits June 22, 2026 16:06
[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added 6 commits June 22, 2026 18:01
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Comment thread torchtitan/overrides/fused_swiglu.py Outdated
Comment on lines +418 to +422
if get_spmd_backend() == "spmd_types" and spmd.is_type_checking():
spmd.assert_type(
out,
{"dp": spmd.S(0), "cp": spmd.S(1), "tp": spmd.S(2)},
)

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.

Since with spmd.no_typecheck() and with spmd.local() don't provide an "official" closure to annotate exiting tensors, I wonder if we could in torchtitan always put these back-to-global assert_type inside the with context instead of outside.

Main reason is for readability.

xq_out, xk_out = _helion_rope_fwd(xq, xk, cache, pos)
# TODO(pianpwk): Migrate this local_map workaround to a custom op SPMD
# propagation rule registration system.
xq_out, xk_out = spmd.local_map(

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.

a bit confused -- why the swiglu ops use no_typechecking but here we use spmd.local_map?

The only difference may be whether we are checking against in_types? Or are you saying we are actually checking something local in _helion_rope_fwd?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will switch , I thought we needed no_typecheck but maybe not . with spmd.local we just check the custom op has valid local type interaction (no I mixing non-I, etc.)

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.

@pianpwk -- I think PR description / commit message needs to be updated

pianpwk added 2 commits June 23, 2026 15:20
[ghstack-poisoned]
[ghstack-poisoned]
Comment thread torchtitan/overrides/fused_swiglu.py Outdated

# TODO(pianpwk): Migrate this local workaround to a custom op SPMD
# propagation rule registration system.
with spmd.local():

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.

change to local_map

pianpwk added 2 commits June 23, 2026 17:20
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk
pianpwk requested a review from tianyu-l June 24, 2026 00:21
pianpwk added 22 commits June 25, 2026 10:16
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Jun 26, 2026
pianpwk added 2 commits June 25, 2026 18:38
[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Jun 26, 2026
`set_current_spmd_mesh(sparse_mesh)` transitions for MoE region, spmd.all_to_all switch, plus
mesh reinterprets, assert_type, mutate_type

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0)
(oldest at bottom):
* #3740
* #3690
* #3673
* #3655
* #3741
* #3664
* __->__ #3654
pianpwk added a commit that referenced this pull request Jun 26, 2026
Fix spmd_types SP-padding support, by requiring evenly sharded seq-dim
for MoE input activations, calculating post-combine output size based on
local tensor shapes.

Raises in trainer for MoE + uneven seq-dim sharding.

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0)
(oldest at bottom):
* #3740
* #3690
* #3673
* #3655
* #3741
* __->__ #3664
@pianpwk
pianpwk changed the base branch from gh/pianpwk/50/base to main June 26, 2026 02:15
@pianpwk
pianpwk merged commit fbf79bc into main Jun 26, 2026
8 of 11 checks passed
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Jun 26, 2026
Wrap Helion RoPE and dense fused SwiGLU calls with explicit spmd.local_map contracts so the custom ops can run under spmd_types typechecking. Grouped fused SwiGLU runs directly in the existing local SPMD expert region.

These workarounds should be migrated to a custom op SPMD propagation rule registration system once that API is available.

Test Plan:

- python -m py_compile torchtitan/overrides/helion_rope.py torchtitan/overrides/fused_swiglu.py

- git diff --check -- torchtitan/overrides/helion_rope.py torchtitan/overrides/fused_swiglu.py

- NGPU=8 LOG_RANK=0 MODULE=qwen3 CONFIG=qwen3_debugmodel_fused_qkv ./run_train.sh --parallelism.spmd_backend spmd_types --debug.spmd_typechecking --parallelism.data_parallel_shard_degree 2 --parallelism.context_parallel_degree 2 --parallelism.tensor_parallel_degree 2 --training.steps 1 --override.imports torchtitan.overrides.helion_rope activation-checkpoint:none

- NGPU=8 LOG_RANK=0 MODULE=deepseek_v3 CONFIG=deepseek_v3_debugmodel ./run_train.sh --parallelism.spmd_backend spmd_types --debug.spmd_typechecking --parallelism.data_parallel_shard_degree 2 --parallelism.context_parallel_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2 --training.steps 1 --override.imports torchtitan.overrides.fused_swiglu activation-checkpoint:none

ghstack-source-id: a1ae35a
Pull Request resolved: pytorch/torchtitan#3741
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu 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