Enable RL spmd backend selection#3803
Merged
Merged
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
tianyu-l
reviewed
Jun 26, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
mostly look good, some suggestions
|
|
||
|
|
||
| def get_train_context( | ||
| def get_spmd_context( |
Contributor
There was a problem hiding this comment.
sounds reasonable, maybe move to spmd_types.py when DTensor fwd/bwd is gone
| model.to_empty(device=device_type) | ||
| with torch.no_grad(): | ||
| model.init_weights(buffer_device=None) | ||
| with self.train_context(): |
Contributor
Author
There was a problem hiding this comment.
this is to set the current spmd mesh, so spmd_types.py can access it for collectives & PGs. not for typechecking currently.
Contributor
There was a problem hiding this comment.
why trainer doesn't need it?
Contributor
Author
There was a problem hiding this comment.
my bad, was not needed
| spmd_backend=training_parallelism.spmd_backend, | ||
| ) | ||
| dist_utils.set_spmd_backend(training_parallelism.spmd_backend) | ||
| self.spmd_context = dist_utils.get_spmd_context( |
Contributor
There was a problem hiding this comment.
I don't think we need to type check inference code at all
- the correctness is verified
- the backward is not an issue
- only attention is a bit different than training code, but that's ... fine?
Comment on lines
369
to
370
| if isinstance(h, DTensor): | ||
| h = h.full_tensor() |
Contributor
There was a problem hiding this comment.
This sounds no-op if in inference we are only using TP, not SP.
I think that's guarded, so can turn this to h = h._local_tensor
Comment on lines
+426
to
+427
| if isinstance(logits, DTensor): | ||
| placements = tuple( | ||
| Replicate() | ||
| if isinstance(p, Shard) and p.dim in (-1, logits.ndim - 1) | ||
| else p | ||
| for p in logits.placements | ||
| ) | ||
| logits = logits.redistribute(placements=placements).to_local() | ||
| logits = logits.to_local() |
tianyu-l
approved these changes
Jun 26, 2026
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.
Stack from ghstack (oldest at bottom):