Skip to content

Enable RL spmd backend selection#3803

Merged
pianpwk merged 7 commits into
mainfrom
gh/pianpwk/55/head
Jun 27, 2026
Merged

Enable RL spmd backend selection#3803
pianpwk merged 7 commits into
mainfrom
gh/pianpwk/55/head

Conversation

@pianpwk

@pianpwk pianpwk commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

pianpwk added 2 commits June 26, 2026 15:32
[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added 2 commits June 26, 2026 15:38
[ghstack-poisoned]
[ghstack-poisoned]

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly look good, some suggestions



def get_train_context(
def get_spmd_context(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to set the current spmd mesh, so spmd_types.py can access it for collectives & PGs. not for typechecking currently.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why trainer doesn't need it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

covered by above?

pianpwk added 3 commits June 26, 2026 16:15
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk pianpwk changed the base branch from gh/pianpwk/55/base to main June 27, 2026 01:10
@pianpwk pianpwk merged commit fcbcb6d into main Jun 27, 2026
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants