Repository navigation
[spmd_types] state sharding and redistribution infra - #3587
Conversation
[ghstack-poisoned]
Adding this to allow both spmd types specs, and DTensor-style placements. We're adding something like D107576760 in spmd_types, but in the meantime, because non-llama3 models are still in DTensor placement form, I think we have 2 options: 1) keep this as a hybrid spmd/DTensor container (e.g. moe_sharding.py calls `dense_activation_placement(tp=Replicate())`, and migrate to SpmdLayout once all models are off full_dtensor. 2) since we're adding a spmd->DTensor translation shim anyways, migrate all models from `Replicate/Shard/Partial` to `spmd.R/S/P` immediately, use SpmdLayout, and go deal with I/R distinctions later. This should be ok because non-llama3 models won't support spmd backend yet. Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * #3278 * #3472 * #3468 * #3471 * #3253 * #3587 * #3586 * __->__ #3501
[ghstack-poisoned]
[ghstack-poisoned]
| return x | ||
|
|
||
|
|
||
| def _shard_spmd_state( |
There was a problem hiding this comment.
| def _shard_spmd_state( | |
| def spmd_distribute_tensor( |
- it's a public util function
- "shard" may confuse with spmd.S
- not necessarily for model state
distribute_tensor"matching" DTensor api name
| _validate_redistribute_spmd_pair(out_src, out_dst, name="output") | ||
|
|
||
|
|
||
| def redistribute_spmd_per_axis( |
There was a problem hiding this comment.
| def redistribute_spmd_per_axis( | |
| def spmd_redistribute_per_axis( |
for consistency
| or we should write collective-based (not placement-based) redistributions | ||
| after full_dtensor backend is removed. |
There was a problem hiding this comment.
- What's the motivation for this?
- How do you map (in_src, in_dist) config to collectives?
There was a problem hiding this comment.
This isn't a clear-cut or strong proposal, but src/dst is more of a full-DTensor-first thing, and once that's done ShardingConfig design should be less constrained
And if we had thoughts to enhance redistribution info to be fine-grained (e.g. per-collective dtype: {"src": NamedPlacement, "dst": NamedPlacement, "op_dtype": ..., "out_dtype": ..., "backward_options": ...})
it doesn't seem too far-fetched to me to replace src/dst with the actual collective
There was a problem hiding this comment.
Sounds reasonable. I feel having both static metadata (types) and collectives is also appealing. E.g. one could even swap the collective backend while keeping the same metadata.
| entries[dim] = (axis_name,) | ||
| return tuple(entries) | ||
|
|
||
| def _validate_redistribute_spmd_pair( |
There was a problem hiding this comment.
didn't check internal, assuming it's correct
Adding this to allow both spmd types specs, and DTensor-style placements. We're adding something like D107576760 in spmd_types, but in the meantime, because non-llama3 models are still in DTensor placement form, I think we have 2 options: 1) keep this as a hybrid spmd/DTensor container (e.g. moe_sharding.py calls `dense_activation_placement(tp=Replicate())`, and migrate to SpmdLayout once all models are off full_dtensor. 2) since we're adding a spmd->DTensor translation shim anyways, migrate all models from `Replicate/Shard/Partial` to `spmd.R/S/P` immediately, use SpmdLayout, and go deal with I/R distinctions later. This should be ok because non-llama3 models won't support spmd backend yet. Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * #3278 * #3472 * #3468 * #3471 * #3253 * #3587 * #3586 * __->__ #3501
Splitting up infra PR. This adds: - _shard_spmd_state: util for distributing param/buffer onto mesh in SpmdLayout format, supporting PartitionSpec shard order - redistribute_spmd_per_axis: module boundary, SpmdLayout-based redistribution handler - _validate_spmd_redistributions: helper for validating it resolves to just one spmd.redistribute call - that's all titan will support Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * #3278 * #3472 * #3468 * #3471 * #3253 * __->__ #3587
Splitting up infra PR. This adds: - _shard_spmd_state: util for distributing param/buffer onto mesh in SpmdLayout format, supporting PartitionSpec shard order - redistribute_spmd_per_axis: module boundary, SpmdLayout-based redistribution handler - _validate_spmd_redistributions: helper for validating it resolves to just one spmd.redistribute call - that's all titan will support Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * pytorch#3278 * pytorch#3472 * pytorch#3468 * pytorch#3471 * pytorch#3253 * __->__ pytorch#3587
Splitting up infra PR. This adds:
Stack from ghstack (oldest at bottom):