Repository navigation
[spmd_types] embedding vocab parallel - #3468
Merged
Merged
Conversation
[ghstack-poisoned]
This was referenced May 31, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
This was referenced Jun 1, 2026
[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 11, 2026
Main infra PR for spmd_types + titan. `spmd_types.py`: - Adds a thread-local DeviceMesh stack, and current_mesh(), set_current_mesh() helpers, to be set and accessed at model init (weight parallelize) and runtime (PG access for collectives) - Various helpers for spmd_types : module-boundary redistributions, spmd -> DTensor placement translation (for full_dtensor backend), `mesh_size(axis_name)` helper that returns > 1 when mesh is set & axis is active. Some of this will be moved to spmd_types in near-term, see comments. `parallel_dims.py`: - For spmd backend, we need 2 views over the world mesh: [pp, dp, cp, tp] for typechecking, and [pp, dp_replicate, dp_shard, cp, tp] to pass the unfolded fsdp axes to fully_shard, via DataParallelMeshDims. So we hold both the full-DTensor-style dense mesh, as well as the "typechecking" mesh. `module.py`: module.parallelize() paths for spmd backend: weight init, local SPMD drop in, input/output redistribution. `trainer.py/utils.py`: typechecking context, input annotation, spmd set_current_spmd_mesh, PP + typechecking raises a hard error. Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * #3278 * #3472 * #3632 * #3631 * #3468 * #3471 * __->__ #3253
pianpwk
added a commit
that referenced
this pull request
Jun 11, 2026
[ghstack-poisoned]
Contributor
Author
|
switched to use local region for all DTensor / legacy / spmd_types |
[ghstack-poisoned]
tianyu-l
approved these changes
Jun 12, 2026
| loss_tp = spmd.S(-1) if loss_parallel else spmd.I | ||
|
|
||
| embed_out_src = dense_activation_placement(tp=spmd.P) | ||
| embed_input = SpmdLayout( |
Contributor
There was a problem hiding this comment.
curious why not reuse dense_activation_placement?
| from torchtitan.protocols.module import Module | ||
|
|
||
|
|
||
| class Embedding(nn.Embedding, Module): |
Contributor
There was a problem hiding this comment.
please add a TODO if you don't want to do renaming in this PR.
| super().__init__(config.num_embeddings, config.embedding_dim) | ||
| self.tp_group: dist.ProcessGroup | None = None | ||
|
|
||
| def parallelize(self, parallel_dims: "ParallelDims") -> None: |
Contributor
There was a problem hiding this comment.
add a TODO to delete this?
|
|
||
| def __init__(self, config: Config): | ||
| super().__init__(config.num_embeddings, config.embedding_dim) | ||
| self.tp_group: dist.ProcessGroup | None = None |
Contributor
There was a problem hiding this comment.
I think this might be a case where you might want global spmd on outer axes (DP, CP) and local spmd on inner axis (TP)? Not a strong motivation though.
| ) | ||
|
|
||
|
|
||
| class Embedding(nn.Embedding, Module): |
Contributor
There was a problem hiding this comment.
This means all torchtitan models are using the new VocabParallelEmbedding regardless of parallelism config, right?
pianpwk
added a commit
that referenced
this pull request
Jun 12, 2026
switches decoder_sharding.py and llama3/sharding.py to spmd.* types. - Fill in src placements to be explicit, where previously we implicitly relied on DTensor - `LocalMapConfig(in_grad_placements=...)` carries info only used by default/full_dtensor backends; spmd_types backend just checks for presence of config, to switch to local SPMD - PartitionSpec used once for SP activation: CP/TP shard seq-dim - SP=off activations are I@TP - unsharded weights (e.g. norm) are R@TP when SP on, FSDP handles the gradient AR in DTensor: pytorch/pytorch#181519 Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * #3278 * #3472 * #3632 * #3631 * #3468 * __->__ #3471
pianpwk
added a commit
that referenced
this pull request
Jun 12, 2026
[ghstack-poisoned]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a custom vocab-parallel Embedding module, to be wired for spmd_types and DTensor backend. Uses a local SPMD / local_map region, avoiding DTensor dependence on MaskPartial.
Stack from ghstack (oldest at bottom):