Skip to content

[TokenSwitch] Add symmetric-memory zero-copy dispatch/combine - #187785

Closed
kwen2501 wants to merge 6 commits into
gh/kwen2501/351/basefrom
gh/kwen2501/351/head
Closed

kwen2501 wants to merge 6 commits into
gh/kwen2501/351/basefrom
gh/kwen2501/351/head

Conversation

@kwen2501

@kwen2501 kwen2501 commented Jun 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

When a dispatch/combine tensor is backed by NCCLSymmetricMemory registered
under the process group's name, address it via the registered ncclWindow +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer. Applies to dispatch inputs/outputs
and combine inputs.

  • EpTensor gains a window-backed constructor (win_hdl + win_offset).
  • make_ep_tensor() looks up the symm_mem rendezvous for a tensor (by
    std::string_view) and uses the window path when available, falling back to
    the device-pointer path. rendezvous is established implicitly on first use, so
    callers need not rendezvous explicitly.
  • NcclEpGroup / NcclEpHandle carry the group_name needed for that lookup.
  • torch/CMakeLists.txt: add USE_NCCL to the _nccl_ep compile definitions
    so NCCL_HAS_SYMMEM_SUPPORT is defined and NCCLSymmetricMemory is a
    complete type.

Test Plan:
On a node with 2+ GPUs and a USE_NCCL_EP=1 build:

python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
  • ✅ test_dispatch_symm_mem_tokens (symm_mem input + output; explicit & implicit rendezvous)
  • ✅ test_combine_symm_mem_tokens (explicit & implicit rendezvous)
  • ✅ test_dispatch_group_gemm_combine_symm_mem (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/187785

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 175 Pending

As of commit 907cfd7 with merge base 9f46548 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

// falls back to the plain device-pointer path.
static EpTensor make_ep_tensor(
const at::Tensor& t,
const std::string& group_name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should really refactor this group_name API to either take value by ownership via std::move or std::string_view

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unless rendezvous needs null termination of course

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switched to `std::string_view`. `rendezvous` takes `const std::optionalstd::string&` (no null-termination needed), so the view is just materialized into a `std::string` at that call. Thanks!

[ghstack-poisoned]
kwen2501 added a commit that referenced this pull request Jun 21, 2026
When a dispatch/combine tensor is backed by `NCCLSymmetricMemory` registered
under the process group's name, address it via the registered `ncclWindow` +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer.

- `EpTensor` gains a window-backed constructor (`win_hdl` + `win_offset`).
- `make_ep_tensor()` looks up the symm_mem rendezvous for a tensor and uses the
  window path when available, falling back to the device-pointer path.
- `NcclEpGroup` / `NcclEpHandle` carry the `group_name` needed for that lookup.
- `torch/CMakeLists.txt`: add `USE_NCCL` to the `_nccl_ep` compile definitions
  so `NCCL_HAS_SYMMEM_SUPPORT` is defined and `NCCLSymmetricMemory` is a
  complete type.

Test Plan:
On a node with 2+ GPUs and a `USE_NCCL_EP=1` build:

```
python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
```

- ✅ `test_dispatch_symm_mem_tokens`
- ✅ `test_combine_symm_mem_tokens`
- ✅ `test_dispatch_group_gemm_combine_symm_mem` (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)

ghstack-source-id: 55da7f5
Pull-Request: #187785
[ghstack-poisoned]
kwen2501 added a commit that referenced this pull request Jun 21, 2026
When a dispatch/combine tensor is backed by `NCCLSymmetricMemory` registered
under the process group's name, address it via the registered `ncclWindow` +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer.

- `EpTensor` gains a window-backed constructor (`win_hdl` + `win_offset`).
- `make_ep_tensor()` looks up the symm_mem rendezvous for a tensor and uses the
  window path when available, falling back to the device-pointer path.
- `NcclEpGroup` / `NcclEpHandle` carry the `group_name` needed for that lookup.
- `torch/CMakeLists.txt`: add `USE_NCCL` to the `_nccl_ep` compile definitions
  so `NCCL_HAS_SYMMEM_SUPPORT` is defined and `NCCLSymmetricMemory` is a
  complete type.

Test Plan:
On a node with 2+ GPUs and a `USE_NCCL_EP=1` build:

```
python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
```

- ✅ `test_dispatch_symm_mem_tokens`
- ✅ `test_combine_symm_mem_tokens`
- ✅ `test_dispatch_group_gemm_combine_symm_mem` (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)

ghstack-source-id: 9b9b322
Pull-Request: #187785
[ghstack-poisoned]
kwen2501 added a commit that referenced this pull request Jun 21, 2026
When a dispatch/combine tensor is backed by `NCCLSymmetricMemory` registered
under the process group's name, address it via the registered `ncclWindow` +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer.

- `EpTensor` gains a window-backed constructor (`win_hdl` + `win_offset`).
- `make_ep_tensor()` looks up the symm_mem rendezvous for a tensor and uses the
  window path when available, falling back to the device-pointer path.
- `NcclEpGroup` / `NcclEpHandle` carry the `group_name` needed for that lookup.
- `torch/CMakeLists.txt`: add `USE_NCCL` to the `_nccl_ep` compile definitions
  so `NCCL_HAS_SYMMEM_SUPPORT` is defined and `NCCLSymmetricMemory` is a
  complete type.

Test Plan:
On a node with 2+ GPUs and a `USE_NCCL_EP=1` build:

```
python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
```

- ✅ `test_dispatch_symm_mem_tokens`
- ✅ `test_combine_symm_mem_tokens`
- ✅ `test_dispatch_group_gemm_combine_symm_mem` (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)

ghstack-source-id: d5f485b
Pull-Request: #187785
@kwen2501
kwen2501 requested a review from syed-ahmed June 21, 2026 23:12
@kwen2501 kwen2501 added the module: symm_mem Issues and PRs of Symmetric Memory label Jun 21, 2026
[ghstack-poisoned]
kwen2501 added a commit that referenced this pull request Jun 22, 2026
When a dispatch/combine tensor is backed by `NCCLSymmetricMemory` registered
under the process group's name, address it via the registered `ncclWindow` +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer. Applies to dispatch inputs/outputs
and combine inputs.

- `EpTensor` gains a window-backed constructor (`win_hdl` + `win_offset`).
- `make_ep_tensor()` looks up the symm_mem rendezvous for a tensor (by
  `std::string_view`) and uses the window path when available, falling back to
  the device-pointer path. rendezvous is established implicitly on first use, so
  callers need not rendezvous explicitly.
- `NcclEpGroup` / `NcclEpHandle` carry the `group_name` needed for that lookup.
- `torch/CMakeLists.txt`: add `USE_NCCL` to the `_nccl_ep` compile definitions
  so `NCCL_HAS_SYMMEM_SUPPORT` is defined and `NCCLSymmetricMemory` is a
  complete type.

Test Plan:
On a node with 2+ GPUs and a `USE_NCCL_EP=1` build:

```
python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
```

- ✅ `test_dispatch_symm_mem_tokens` (symm_mem input + output; explicit & implicit rendezvous)
- ✅ `test_combine_symm_mem_tokens` (explicit & implicit rendezvous)
- ✅ `test_dispatch_group_gemm_combine_symm_mem` (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)

ghstack-source-id: 4804455
Pull-Request: #187785
@ngimel

ngimel commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

@kwen2501 anything blocking the landing here, or did you change your mind?

@kwen2501

Copy link
Copy Markdown
Collaborator Author

@ngimel I didn't change my mind :) But I would need an approval of the base PR. I will work with @kapilsh to see if there is any outstanding comments.

@kwen2501

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Aug 28, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / macos-py3-arm64 / test (default, 1, 3, macos-m1-stable)

Details for Dev Infra team Raised by workflow job

@kwen2501

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -f "failure is unrelated "

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Command git -C /home/runner/work/pytorch/pytorch cherry-pick -x 020c2345b0f452171bc9506c737abd0604d03584 returned non-zero exit code 1

Auto-merging test/distributed/test_token_switch.py
Auto-merging torch/CMakeLists.txt
Auto-merging torch/csrc/distributed/c10d/symm_mem/nccl_ep.cu
CONFLICT (content): Merge conflict in torch/csrc/distributed/c10d/symm_mem/nccl_ep.cu
error: could not apply 020c2345b0f... [TokenSwitch] Add symmetric-memory zero-copy dispatch/combine
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Details for Dev Infra team Raised by workflow job

[ghstack-poisoned]
kwen2501 added a commit that referenced this pull request Aug 30, 2026
When a dispatch/combine tensor is backed by `NCCLSymmetricMemory` registered
under the process group's name, address it via the registered `ncclWindow` +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer. Applies to dispatch inputs/outputs
and combine inputs.

- `EpTensor` gains a window-backed constructor (`win_hdl` + `win_offset`).
- `make_ep_tensor()` looks up the symm_mem rendezvous for a tensor (by
  `std::string_view`) and uses the window path when available, falling back to
  the device-pointer path. rendezvous is established implicitly on first use, so
  callers need not rendezvous explicitly.
- `NcclEpGroup` / `NcclEpHandle` carry the `group_name` needed for that lookup.
- `torch/CMakeLists.txt`: add `USE_NCCL` to the `_nccl_ep` compile definitions
  so `NCCL_HAS_SYMMEM_SUPPORT` is defined and `NCCLSymmetricMemory` is a
  complete type.

Test Plan:
On a node with 2+ GPUs and a `USE_NCCL_EP=1` build:

```
python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
```

- ✅ `test_dispatch_symm_mem_tokens` (symm_mem input + output; explicit & implicit rendezvous)
- ✅ `test_combine_symm_mem_tokens` (explicit & implicit rendezvous)
- ✅ `test_dispatch_group_gemm_combine_symm_mem` (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)

ghstack-source-id: 594d3b6
Pull-Request: #187785
@kwen2501

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -f "Minor rebase; no functional change"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…h#187785)

When a dispatch/combine tensor is backed by `NCCLSymmetricMemory` registered
under the process group's name, address it via the registered `ncclWindow` +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer. Applies to dispatch inputs/outputs
and combine inputs.

- `EpTensor` gains a window-backed constructor (`win_hdl` + `win_offset`).
- `make_ep_tensor()` looks up the symm_mem rendezvous for a tensor (by
  `std::string_view`) and uses the window path when available, falling back to
  the device-pointer path. rendezvous is established implicitly on first use, so
  callers need not rendezvous explicitly.
- `NcclEpGroup` / `NcclEpHandle` carry the `group_name` needed for that lookup.
- `torch/CMakeLists.txt`: add `USE_NCCL` to the `_nccl_ep` compile definitions
  so `NCCL_HAS_SYMMEM_SUPPORT` is defined and `NCCLSymmetricMemory` is a
  complete type.

Test Plan:
On a node with 2+ GPUs and a `USE_NCCL_EP=1` build:

```
python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
```

- ✅ `test_dispatch_symm_mem_tokens` (symm_mem input + output; explicit & implicit rendezvous)
- ✅ `test_combine_symm_mem_tokens` (explicit & implicit rendezvous)
- ✅ `test_dispatch_group_gemm_combine_symm_mem` (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)
Pull Request resolved: pytorch#187785
Approved by: https://github.com/Skylion007, https://github.com/kapilsh
Sanskaaar1 pushed a commit to Sanskaaar1/pytorch that referenced this pull request Sep 8, 2026
…h#187785)

When a dispatch/combine tensor is backed by `NCCLSymmetricMemory` registered
under the process group's name, address it via the registered `ncclWindow` +
offset (RDMA zero-copy path) instead of a plain device pointer, avoiding a
staging copy into a regular device buffer. Applies to dispatch inputs/outputs
and combine inputs.

- `EpTensor` gains a window-backed constructor (`win_hdl` + `win_offset`).
- `make_ep_tensor()` looks up the symm_mem rendezvous for a tensor (by
  `std::string_view`) and uses the window path when available, falling back to
  the device-pointer path. rendezvous is established implicitly on first use, so
  callers need not rendezvous explicitly.
- `NcclEpGroup` / `NcclEpHandle` carry the `group_name` needed for that lookup.
- `torch/CMakeLists.txt`: add `USE_NCCL` to the `_nccl_ep` compile definitions
  so `NCCL_HAS_SYMMEM_SUPPORT` is defined and `NCCLSymmetricMemory` is a
  complete type.

Test Plan:
On a node with 2+ GPUs and a `USE_NCCL_EP=1` build:

```
python -m pytest test/distributed/test_token_switch.py -k symm_mem -v
```

- ✅ `test_dispatch_symm_mem_tokens` (symm_mem input + output; explicit & implicit rendezvous)
- ✅ `test_combine_symm_mem_tokens` (explicit & implicit rendezvous)
- ✅ `test_dispatch_group_gemm_combine_symm_mem` (dispatch -> group_gemm -> weight-mul -> combine, symm_mem on both ends)

(8xH100)
Pull Request resolved: pytorch#187785
Approved by: https://github.com/Skylion007, https://github.com/kapilsh
@github-actions
github-actions Bot deleted the gh/kwen2501/351/head branch November 12, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100-symm-mem ciflow/trunk Trigger trunk jobs on your pull request Merged module: symm_mem Issues and PRs of Symmetric Memory open source release notes: distributed (c10d) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants