Skip to content

[comm][RFC] Implement a custom comm framework#3883

Open
fegin wants to merge 3 commits into
gh/fegin/150/basefrom
gh/fegin/150/head
Open

[comm][RFC] Implement a custom comm framework#3883
fegin wants to merge 3 commits into
gh/fegin/150/basefrom
gh/fegin/150/head

Conversation

@fegin

@fegin fegin commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Only custom allreduce is supported at this moment.

  1. Use torch.library to install the custom comm.
  2. Use fixed size-based algorithm to decide which collective to use.
  3. Cache one symmetric memory buffer per PG.

While this implementation may be torch.compile-able, the current use case is RL only. For torch.compile is enabled, Inductor actually has a path to do a similar replacement.

TODO
Fixed size algorithm is not accurate. Run-time profiling is a better approach but this requires the local PG during initialization, which may not be always created (e.g., if we don't do TP at all).

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 7, 2026
[ghstack-poisoned]
fegin added a commit that referenced this pull request Jul 7, 2026
Only custom allreduce is supported at this moment.

1. Use torch.library to install the custom comm.
2. Use fixed size-based algorithm to decide which collective to use.
3. Cache one symmetric memory buffer per PG.

While this implementation may be torch.compile-able, the current use case is RL only.
For torch.compile is enabled, Inductor actually has a path to do a similar replacement.

ghstack-source-id: 094f9db
Pull-Request: #3883
[ghstack-poisoned]
fegin added a commit that referenced this pull request Jul 7, 2026
Only custom allreduce is supported at this moment.

1. Use torch.library to install the custom comm.
2. Use fixed size-based algorithm to decide which collective to use.
3. Cache one symmetric memory buffer per PG.

While this implementation may be torch.compile-able, the current use case is RL only.
For torch.compile is enabled, Inductor actually has a path to do a similar replacement.

ghstack-source-id: dfbb9ee
Pull-Request: #3883
@fegin fegin marked this pull request as ready for review July 7, 2026 23:53
@fegin fegin requested review from tianyu-l, wconstab and wwwjn as code owners July 7, 2026 23:53

@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.

shall we run some benchmarking against vllm AR following
https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/rl/.claude/skills/inference_perf_hillclimb/SKILL.md#example-ladder--results

If it's on par we should remove the vllm patch. cc @wwwjn

view = symm_buffer[: input.numel()].view_as(input)
out = torch.empty_like(input)

match algo:

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.

What's the consideration of

  • putting this dispatcher in torchtitan vs.
  • directly modifying pytorch default?

For pytorch side change, is numerics change the main worry?

cc @ngimel

@pianpwk pianpwk Jul 9, 2026

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.

maybe a weird comment, but would this be a good candidate for an override? I know that only applies to Configurable, but with spmd_types we were planning to make those more configurable anyways, with fwd/bwd dtype control, etc.,

It also already makes sense, to make the src/dst configs collective-type-first (e.g. say "allreduce" instead of placement-based src/dst), and make placements just type assertions, as we won't actually support arbitrary src -> dst redistributes as DTensor does. This could pave the way for easier configurability/overriding

Looking at the overrides doc:

These are valuable for performance but are (a) hardware-specific, (b) harder to maintain, and (c) reasonably held to a lower code-quality bar than core. We want to offer vendors a clean extension point rather than either lowering the core bar or saying "no".

this sounds applicable?

@tianyu-l tianyu-l Jul 9, 2026

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.

@pianpwk
Makes sense. My only worry was that creating a config just for patching sounds even hackier than override itself.

But I think it makes sense because people do want to experiment with collectives.

Happy to discuss / review if you could provide a more concrete proposal.

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.

pretty WIP, but it'd look something like #3905

@wwwjn wwwjn 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.

It fallback to NCCL comms, so I would assume RL Policytrainer / pretrain will not regression.

So for benchmarking we can focus on generator now (vllm AR patch only patched generator), you can start from

to benchmarking inference only?

@d4l3k

d4l3k commented Jul 8, 2026

Copy link
Copy Markdown
Member

@fegin do we have benchmarks on the performance here for the different algorithms and data sizes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants