Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/187784
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (2 Unrelated Failures)As of commit 4e5d065 with merge base a3af108 ( CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| const at::Tensor& topk_idx, | ||
| const std::optional<at::Tensor>& recv_expert_counter); | ||
| const std::optional<at::Tensor>& recv_expert_counter, | ||
| int64_t layout); // ncclEpLayout_t: expert_major=1, rank_major=2, flat=3 |
There was a problem hiding this comment.
This should be properly typed as an enum!
There was a problem hiding this comment.
Done — now `NcclEpLayout`.
| NcclEpHandle(void* handle, at::Tensor topk_idx, at::Tensor recv_total_counter) | ||
| NcclEpHandle( | ||
| void* handle, | ||
| int64_t layout, |
There was a problem hiding this comment.
Same here, type is as an enum!
There was a problem hiding this comment.
Done — now `NcclEpLayout`.
|
|
||
| struct NcclEpHandle : c10::intrusive_ptr_target { | ||
| void* handle{nullptr}; // ncclEpHandle_t, opaque | ||
| int64_t layout{0}; // ncclEpLayout_t, for callers to query dispatch output shapes |
There was a problem hiding this comment.
Why don't we use ncclEpLayout_t enum?
There was a problem hiding this comment.
Added a standalone `NcclEpLayout` enum mirroring `ncclEpLayout_t` — kept separate so this header stays free of `<nccl_ep.h>`; the `.cu` maps it via `to_nccl_layout()`. Done.
| #endif | ||
|
|
||
| // Layout constants matching ncclEpLayout_t. | ||
| m.attr("LAYOUT_EXPERT_MAJOR") = static_cast<int64_t>(NCCL_EP_LAYOUT_EXPERT_MAJOR); |
There was a problem hiding this comment.
No, just bind this to a real enum object!
There was a problem hiding this comment.
Done — now bound as a real enum: `py::enum_(m, "Layout")`.
| num_local_experts, dtype=torch.int32, device=self.device | ||
| ) | ||
| ts.create_routing(topk_idx, per_expert_counts) | ||
| ts.create_routing(topk_idx, per_expert_counts, layout="flat") |
There was a problem hiding this comment.
could we just expand existing tests with parameterization on layout?
There was a problem hiding this comment.
That's possible for create_routing. For dispatch, the output may be different for the two modes (tensor shapes, etc). But let me try to consolidate as much as possible.
| static ncclEpLayout_t to_nccl_layout(NcclEpLayout layout) { | ||
| switch (layout) { | ||
| case NcclEpLayout::ExpertMajor: | ||
| return NCCL_EP_LAYOUT_EXPERT_MAJOR; | ||
| case NcclEpLayout::RankMajor: | ||
| return NCCL_EP_LAYOUT_RANK_MAJOR; | ||
| case NcclEpLayout::Flat: | ||
| return NCCL_EP_LAYOUT_FLAT; | ||
| case NcclEpLayout::Unset: | ||
| break; // not a valid dispatch layout | ||
| } | ||
| TORCH_CHECK( | ||
| false, "nccl_ep: layout must be set; got ", static_cast<int64_t>(layout)); | ||
| } |
There was a problem hiding this comment.
let's just default to flat? and not have Unset at all?
There was a problem hiding this comment.
I thought about that. But I felt that user may want either one of them 50:50. Thus giving the ball back to the user.
There was a problem hiding this comment.
I feel it is reasonable to have a default as a good user experience - ideally pre-dominant use case as default.
|
sorry - dropped of the queue. LGTM! only lingering comment was default layout - let's just set it to FLAT? I feel passing the responsibility to user doesnt make sense to me - i lean towards having a default layout as a good user experience. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
[ghstack-poisoned]
|
Successfully rebased |
|
@kapilsh Thank you! |
Expose the receive-buffer layout through the token-switch API so callers can select it (the NCCL EP algorithm stays high_throughput). Expert-major orders the dispatched tokens so that all tokens routed to the same local expert are contiguous, which is the layout a grouped GEMM over experts consumes directly -- no regrouping pass between dispatch and the expert matmul. - Add a `NcclEpLayout` enum (`Unset` / `ExpertMajor` / `RankMajor` / `Flat`) in the header, values mirroring `ncclEpLayout_t` (ep_enums.h); kept standalone so the header stays free of `<nccl_ep.h>` (the `.cu` maps it via `to_nccl_layout`). - `nccl_ep_create_handle` takes a `NcclEpLayout` arg instead of hardcoding `NCCL_EP_LAYOUT_FLAT`; the layout is stashed on the handle. - `nccl_ep_dispatch`'s `out_topk_idx` is now optional, since expert-major layouts leave it unpopulated; `out_topk_weights` also becomes optional for API symmetry (it stays populated -- 1-D for expert-major, 2-D for flat). - Python: `create_routing` gains a required keyword-only `layout` arg, with the output-buffer shapes chosen per layout. - pybind binds `NcclEpLayout` as a `Layout` enum object. 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 expert_major -v ``` - ✅ `test_dispatch_expert_major` - ✅ `test_dispatch_combine_roundtrip_expert_major` (8xH100) ghstack-source-id: 81ceaf0 Pull-Request: #187784
|
@pytorchbot merge |
Merge startedYour 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 |
|
Starting merge as part of PR stack under #187785 |
Expose the receive-buffer layout through the token-switch API so callers can select it (the NCCL EP algorithm stays high_throughput). Expert-major orders the dispatched tokens so that all tokens routed to the same local expert are contiguous, which is the layout a grouped GEMM over experts consumes directly -- no regrouping pass between dispatch and the expert matmul. - Add a `NcclEpLayout` enum (`Unset` / `ExpertMajor` / `RankMajor` / `Flat`) in the header, values mirroring `ncclEpLayout_t` (ep_enums.h); kept standalone so the header stays free of `<nccl_ep.h>` (the `.cu` maps it via `to_nccl_layout`). - `nccl_ep_create_handle` takes a `NcclEpLayout` arg instead of hardcoding `NCCL_EP_LAYOUT_FLAT`; the layout is stashed on the handle. - `nccl_ep_dispatch`'s `out_topk_idx` is now optional, since expert-major layouts leave it unpopulated; `out_topk_weights` also becomes optional for API symmetry (it stays populated -- 1-D for expert-major, 2-D for flat). - Python: `create_routing` gains a required keyword-only `layout` arg, with the output-buffer shapes chosen per layout. - pybind binds `NcclEpLayout` as a `Layout` enum object. 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 expert_major -v ``` - ✅ `test_dispatch_expert_major` - ✅ `test_dispatch_combine_roundtrip_expert_major` (8xH100) Pull Request resolved: pytorch#187784 Approved by: https://github.com/kapilsh
Expose the receive-buffer layout through the token-switch API so callers can select it (the NCCL EP algorithm stays high_throughput). Expert-major orders the dispatched tokens so that all tokens routed to the same local expert are contiguous, which is the layout a grouped GEMM over experts consumes directly -- no regrouping pass between dispatch and the expert matmul. - Add a `NcclEpLayout` enum (`Unset` / `ExpertMajor` / `RankMajor` / `Flat`) in the header, values mirroring `ncclEpLayout_t` (ep_enums.h); kept standalone so the header stays free of `<nccl_ep.h>` (the `.cu` maps it via `to_nccl_layout`). - `nccl_ep_create_handle` takes a `NcclEpLayout` arg instead of hardcoding `NCCL_EP_LAYOUT_FLAT`; the layout is stashed on the handle. - `nccl_ep_dispatch`'s `out_topk_idx` is now optional, since expert-major layouts leave it unpopulated; `out_topk_weights` also becomes optional for API symmetry (it stays populated -- 1-D for expert-major, 2-D for flat). - Python: `create_routing` gains a required keyword-only `layout` arg, with the output-buffer shapes chosen per layout. - pybind binds `NcclEpLayout` as a `Layout` enum object. 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 expert_major -v ``` - ✅ `test_dispatch_expert_major` - ✅ `test_dispatch_combine_roundtrip_expert_major` (8xH100) Pull Request resolved: pytorch#187784 Approved by: https://github.com/kapilsh
Stack from ghstack (oldest at bottom):
Expose the receive-buffer layout through the token-switch API so callers can
select it (the NCCL EP algorithm stays high_throughput).
Expert-major orders the dispatched tokens so that all tokens routed to the same
local expert are contiguous, which is the layout a grouped GEMM over experts
consumes directly -- no regrouping pass between dispatch and the expert matmul.
NcclEpLayoutenum (Unset/ExpertMajor/RankMajor/Flat) inthe header, values mirroring
ncclEpLayout_t(ep_enums.h); kept standalone sothe header stays free of
<nccl_ep.h>(the.cumaps it viato_nccl_layout).nccl_ep_create_handletakes aNcclEpLayoutarg instead of hardcodingNCCL_EP_LAYOUT_FLAT; the layout is stashed on the handle.nccl_ep_dispatch'sout_topk_idxis now optional, since expert-majorlayouts leave it unpopulated;
out_topk_weightsalso becomes optional for APIsymmetry (it stays populated -- 1-D for expert-major, 2-D for flat).
create_routinggains a required keyword-onlylayoutarg, with theoutput-buffer shapes chosen per layout.
NcclEpLayoutas aLayoutenum object.Test Plan:
On a node with 2+ GPUs and a
USE_NCCL_EP=1build:test_dispatch_expert_majortest_dispatch_combine_roundtrip_expert_major(8xH100)