[spmd_types] helion rope & fused_swiglu rules - #3741
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
| 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)}, | ||
| ) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
@pianpwk -- I think PR description / commit message needs to be updated
[ghstack-poisoned]
|
|
||
| # TODO(pianpwk): Migrate this local workaround to a custom op SPMD | ||
| # propagation rule registration system. | ||
| with spmd.local(): |
[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]
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
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
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