Repository navigation
spmd_types docs - #3853
spmd_types docs#3853pianpwk wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
put under distributed/ or distributed/spmd_types/
in general I'd like to remove this centralized doc folder to keep related things sitting together.
5ec3323 to
5bc70f0
Compare
175801d to
f2e74ab
Compare
| activation or parameter may be sharded, replicated, pending an all-reduce over a mesh dimension, | ||
| or in some other weird form. DTensor is the familiar PyTorch-native example of global SPMD: | ||
| APIs like `redistribute` express placement-based collectives, while DTensor's sharding propagator | ||
| and redistribution engine decide which operations comply with global SPMD. |
There was a problem hiding this comment.
not sure how much to talk about DTensor, or why it's bad
There was a problem hiding this comment.
I think expanding a little on DTensor's drawbacks will help motivate the next section introducing spmd_types
f2e74ab to
74c4176
Compare
| custom autograd functions. | ||
|
|
||
| For more background, see the [`spmd_types` repository](https://github.com/meta-pytorch/spmd_types) | ||
| and its reference docs. |
There was a problem hiding this comment.
not sure how much more to talk about this, or link to other stuff
| invoking the ShardingConfig, and wire AC, compile, FSDP, and other features, using existing implementations as reference. | ||
| 4. Define a trainer/dataloader-side function that annotates SPMD types for model inputs, if not covered by existing trainers. | ||
| Note that any input shardings or splits should be implemented on the dataloader side. | ||
| 5. Wire the parallelization function into `parallelize_fn`, in model registries. |
There was a problem hiding this comment.
is this too detailed, maybe it's likely to change
| `default` and `full_dtensor` backends use DTensor for parallelism, and the same declarative sharding | ||
| config system works for them; TorchTitan translates `spmd_types` placements into DTensor ones. | ||
|
|
||
| For a new model or module, the preferred flow is: |
There was a problem hiding this comment.
actually don't have experience contributing a new model from scratch, so this might differ
There was a problem hiding this comment.
I would (rephrase this) and put into https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/README.md
| During development, the `--debug.spmd_typechecking` should invoke the global SPMD typechecker over trainer FWD steps, catching | ||
| any incorrect or unannotated distributed computation. Real usage should avoid this flag, as it adds significant overhead. | ||
|
|
||
| The expectation when a new model, module, or override is contributed is that ...... |
There was a problem hiding this comment.
Some open questions I wasn't sure
- If someone's adding a new model, it probably should typecheck under 1D / all combinations of parallelisms?
- Same thing for one-off fixes, or adding new module?
- For overrides: currently we typecheck helion rope & fused swiglu, but maybe we could refer back to the original impl it's overriding, maybe via
register_decompositionor similar? - Bitwise guarantees: for backend migration bitwise was relatively easy to define (minus DTensor doing weird BWD stuff. Not sure what this is for a totally new model
There was a problem hiding this comment.
Pointers to relevant examples for the different escape hatches, disabling type checking, reinterpeting meshes, etc. will be helpful apart from the pseudocode examples.
There was a problem hiding this comment.
If type check fails, what are next remedial steps? Illustrating with a small example could be useful for agents to fix errors.
There was a problem hiding this comment.
Bitwise guarantees: for backend migration bitwise was relatively easy to define (minus DTensor doing weird BWD stuff. Not sure what this is for a totally new model
covered in
- https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/README.md#testing-and-benchmarking
- https://github.com/pytorch/torchtitan/blob/main/scripts/checkpoint_conversion/README.md#comprehensive-check-kl-divergence
There was a problem hiding this comment.
For overrides: currently we typecheck helion rope & fused swiglu, but maybe we could refer back to the original impl it's overriding, maybe via register_decomposition or similar?
If it's module boundary sharding, then the override author should include proper sharding_config if it changes, like in https://github.com/pytorch/torchtitan/blob/main/torchtitan/overrides/fused_swiglu.py#L498-L502
There was a problem hiding this comment.
If someone's adding a new model, it probably should typecheck under 1D / all combinations of parallelisms?
On all parallelisms that are supported, which is not different from DTensor-based model
There was a problem hiding this comment.
Same thing for one-off fixes, or adding new module?
Don't have to worry in this .md
| - Custom ops/overrides/external library calls | ||
| - Wrap with `spmd.local_map()`, | ||
| or `spmd.no_typecheck` in some cases, and correctly assert input & output | ||
| SPMD types. |
There was a problem hiding this comment.
better system for custom ops later
|
|
||
| ## Compatibility expectations | ||
|
|
||
| ...... typechecks? bitwise? compared to? |
There was a problem hiding this comment.
or any other sections, anything to make this more agent-friendly, in case of adding new models. don't think it's much of the latter right now.
There was a problem hiding this comment.
maybe mention current incompatibilities, including PP / flex+sac
|
|
||
| The `with set_current_spmd_mesh(...)` context pushes a new DeviceMesh onto TorchTitan's | ||
| SPMD mesh stack, and updates the typechecker's active mesh context. | ||
| `spmd.reinterpret_mesh(tensor, type_or_mesh)` switches tensors onto the new current mesh, |
There was a problem hiding this comment.
not clear why spmd.reinterpret_mesh is also required, and with set_current_spmd_mesh alone is not sufficient
There was a problem hiding this comment.
I asked a similar question in google doc
| APIs like `redistribute` express placement-based collectives, while DTensor's sharding propagator | ||
| and redistribution engine decide which operations comply with global SPMD. | ||
|
|
||
| `spmd_types` combines this placement-based programming model with added benefits: |
There was a problem hiding this comment.
I wouldn't characterize this as added benefits. The old DTensor style guaranteed you could write single device code at the cost of implicit redistributes. Global spmd types checks you have written single device code but you have to write all the redistributes. Which is better is a value judgment.
There was a problem hiding this comment.
(repeating myself) having an illustration for the (potentially confusing) norm region (FSDP involved) would be helpful
There was a problem hiding this comment.
not sure if it should be SPMD_TYPES.md according to github convention.
| `default` and `full_dtensor` backends use DTensor for parallelism, and the same declarative sharding | ||
| config system works for them; TorchTitan translates `spmd_types` placements into DTensor ones. | ||
|
|
||
| For a new model or module, the preferred flow is: |
There was a problem hiding this comment.
I would (rephrase this) and put into https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/README.md
| During development, the `--debug.spmd_typechecking` should invoke the global SPMD typechecker over trainer FWD steps, catching | ||
| any incorrect or unannotated distributed computation. Real usage should avoid this flag, as it adds significant overhead. | ||
|
|
||
| The expectation when a new model, module, or override is contributed is that ...... |
There was a problem hiding this comment.
Bitwise guarantees: for backend migration bitwise was relatively easy to define (minus DTensor doing weird BWD stuff. Not sure what this is for a totally new model
covered in
- https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/README.md#testing-and-benchmarking
- https://github.com/pytorch/torchtitan/blob/main/scripts/checkpoint_conversion/README.md#comprehensive-check-kl-divergence
| During development, the `--debug.spmd_typechecking` should invoke the global SPMD typechecker over trainer FWD steps, catching | ||
| any incorrect or unannotated distributed computation. Real usage should avoid this flag, as it adds significant overhead. | ||
|
|
||
| The expectation when a new model, module, or override is contributed is that ...... |
There was a problem hiding this comment.
For overrides: currently we typecheck helion rope & fused swiglu, but maybe we could refer back to the original impl it's overriding, maybe via register_decomposition or similar?
If it's module boundary sharding, then the override author should include proper sharding_config if it changes, like in https://github.com/pytorch/torchtitan/blob/main/torchtitan/overrides/fused_swiglu.py#L498-L502
| During development, the `--debug.spmd_typechecking` should invoke the global SPMD typechecker over trainer FWD steps, catching | ||
| any incorrect or unannotated distributed computation. Real usage should avoid this flag, as it adds significant overhead. | ||
|
|
||
| The expectation when a new model, module, or override is contributed is that ...... |
There was a problem hiding this comment.
If someone's adding a new model, it probably should typecheck under 1D / all combinations of parallelisms?
On all parallelisms that are supported, which is not different from DTensor-based model
| During development, the `--debug.spmd_typechecking` should invoke the global SPMD typechecker over trainer FWD steps, catching | ||
| any incorrect or unannotated distributed computation. Real usage should avoid this flag, as it adds significant overhead. | ||
|
|
||
| The expectation when a new model, module, or override is contributed is that ...... |
There was a problem hiding this comment.
Same thing for one-off fixes, or adding new module?
Don't have to worry in this .md
|
|
||
| The `with set_current_spmd_mesh(...)` context pushes a new DeviceMesh onto TorchTitan's | ||
| SPMD mesh stack, and updates the typechecker's active mesh context. | ||
| `spmd.reinterpret_mesh(tensor, type_or_mesh)` switches tensors onto the new current mesh, |
There was a problem hiding this comment.
I asked a similar question in google doc
|
|
||
| ## Compatibility expectations | ||
|
|
||
| ...... typechecks? bitwise? compared to? |
There was a problem hiding this comment.
maybe mention current incompatibilities, including PP / flex+sac
| ## Mesh transitions | ||
|
|
||
| MoE models in TorchTitan operate on 2 different meshes: the dense `[dp, cp, tp]` mesh | ||
| for the main transformer backbone, and the sparse `[dp_replicate, efsdp, ep]` mesh |
There was a problem hiding this comment.
wait, this should be [edp, ep] to be consistent
There was a problem hiding this comment.
hm good point.. I guess we never encountered issues because it's local, and spmd.V on both axes? Never had to deal with shard ordering.
also titan not having a efsdp flag means we coincidentally hit when ep * dp_replicate < NGPUs.
There was a problem hiding this comment.
also titan not having a efsdp flag means we coincidentally hit when ep * dp_replicate < NGPUs.
sorry I didn't understand "titan not having a efsdp flag" and "means we coincidentally hit (what?)"
Anyway we should resolve this and make it symmetric to the dense mesh.
74c4176 to
75f687c
Compare
75f687c to
379cc8a
Compare
No description provided.