Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ NCCL:
bounded handle encoding, PCI-root selection, and CPU compatibility tests
- `nccl-2.30.7-switchless-cycle.patch` — against NCCL v2.30.7-1,
`src/transport/generic.cc` and `src/transport/net_ib/connect.cc`
- `nccl-2.31.2-switchless-cycle.patch` — against NCCL v2.31.2-1
([commit `7b83616`](https://github.com/NVIDIA/nccl/tree/7b83616df3ae082a1f32bb74c27458bfe8153a13)),
`src/transport/generic.cc` and `src/transport/net_ib/connect.cc`; contributed
by Labski under Apache-2.0

The context and removed lines in these unified diffs are verbatim NVIDIA NCCL
source code:
Expand Down
33 changes: 33 additions & 0 deletions spark_transport/nccl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,39 @@ DeepSeek and Qwen pair/cycle profiles bind `LL,LL128,Simple`; that setting is
not a default for other serving objects. Collective payloads use the selected
direct RoCE interfaces regardless of the bootstrap interface.

### NCCL 2.31.2 on a two-HCA cycle with SGLang

For a four-Spark cycle with one HCA facing each neighbor on `/30` point-to-point
link subnets, apply the [2.31.2 patch](nccl-2.31.2-switchless-cycle.patch) to
NCCL `v2.31.2-1`
([commit `7b83616`](https://github.com/NVIDIA/nccl/tree/7b83616df3ae082a1f32bb74c27458bfe8153a13)).
It ports the two-listener-GID and ring-only initialization changes from the
[2.30.7 cycle patch](nccl-2.30.7-switchless-cycle.patch).

For SGLang, point both `SGLANG_NCCL_SO_PATH` and `LD_PRELOAD` at the patched
library on every rank and set the explicit `/30` cycle environment rather than
the `/24` or `NCCL_SKIP_TREE_CONNECT` values above:

```text
LD_PRELOAD=<patched-nccl-2.31.2-library>
SGLANG_NCCL_SO_PATH=<patched-nccl-2.31.2-library>
NCCL_IB_HCA=<two-direct-roce-devices>
NCCL_IB_MERGE_NICS=0
NCCL_IB_SUBNET_AWARE_ROUTING=1
NCCL_IB_SUBNET_PREFIX_LEN=30
NCCL_CROSS_NIC=1
NCCL_ALGO=Ring
NCCL_SWITCHLESS_RING_ONLY=1
```

On a four-Spark direct-cable fleet with `/30` link subnets and host-staged RoCE,
stock NCCL 2.30.7 and stock 2.31.2 both timed out on the first all-reduce under
SGLang, whereas the patched 2.31.2 library with `NCCL_SWITCHLESS_RING_ONLY=1`
returned exact sums across all four ranks (8 calls each at 1 KiB, 64 KiB, and
1 MiB) and served chat completions cleanly
([build and launch instructions](https://github.com/looskis/labski/tree/b4874b107855f9e56e41df923ccd9f3466aaa2e4/inference-recipes/transport/nccl-switchless/) ·
[controls, counters, and serving results](https://github.com/looskis/labski/tree/b4874b107855f9e56e41df923ccd9f3466aaa2e4/inference-recipes/results/inkling2-gb10-runtime-2026-11-19/)).

## Fail-closed requirements

Before serving, validate the patched library identity and its image or mount,
Expand Down
73 changes: 73 additions & 0 deletions spark_transport/nccl/nccl-2.31.2-switchless-cycle.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
diff --git a/src/transport/generic.cc b/src/transport/generic.cc
index 4a6222e..feca245 100644
--- a/src/transport/generic.cc
+++ b/src/transport/generic.cc
@@ -10,6 +10,7 @@
#include "bootstrap.h"

NCCL_PARAM(MultiSegmentRegister, "MULTI_SEGMENT_REGISTER", 1);
+NCCL_PARAM(SwitchlessRingOnly, "SWITCHLESS_RING_ONLY", 0);

ncclResult_t ncclTransportRingConnect(struct ncclComm* comm) {
struct ringConnInfo {
@@ -48,6 +49,10 @@ fail:

ncclResult_t ncclTransportTreeConnect(struct ncclComm* comm) {
ncclResult_t ret = ncclSuccess;
+ if (ncclParamSwitchlessRingOnly()) {
+ INFO(NCCL_INIT, "Tree transport setup disabled by NCCL_SWITCHLESS_RING_ONLY");
+ return ncclSuccess;
+ }
if (comm && comm->nRanks > 1) {
// Connect Trees
for (int c = 0; c < comm->nChannels; c++) {
@@ -103,6 +108,10 @@ exit:

ncclResult_t ncclTransportPatConnect(struct ncclComm* comm) {
ncclResult_t ret = ncclSuccess;
+ if (ncclParamSwitchlessRingOnly()) {
+ INFO(NCCL_INIT, "PAT transport setup disabled by NCCL_SWITCHLESS_RING_ONLY");
+ return ncclSuccess;
+ }
if (comm && comm->nRanks > 1) {
int denseLocalRank = 0;
// Connect corresponding NVLS-dense rails across nodes.
diff --git a/src/transport/net_ib/connect.cc b/src/transport/net_ib/connect.cc
index 2a0096a..8e7d32b 100644
--- a/src/transport/net_ib/connect.cc
+++ b/src/transport/net_ib/connect.cc
@@ -639,19 +639,22 @@ ncclResult_t ncclIbListen(void* ctx, int dev, void* opaqueHandle, void** listenC
NCCLCHECKGOTO(ncclSocketListen(&comm->sock), ret, fail);
NCCLCHECKGOTO(ncclSocketGetAddr(&comm->sock, &handle->connectAddr), ret, fail);

- // Embed GIDs of all PFs in the handle so the connector can find a local NIC
- // on the same subnet as any of our ports.
+ // Advertise every eligible local RoCE device. A switchless cycle selects the
+ // physical cable shared with each peer after receiving this handle; limiting
+ // the handle to the topology-selected device can advertise the other cable.
if (ncclParamIbSubnetAwareRouting() && dev < ncclNMergedIbDevs) {
- struct ncclIbMergedDev* mDev = ncclIbMergedDevs + dev;
int gidSlot = 0;
- for (int i = 0; i < mDev->vProps.ndevs && gidSlot < 2; i++) {
- int ibDevN = mDev->vProps.devs[i];
- ncclIbDev* ibDev = ncclIbDevs + ibDevN;
- if (ibDev->portAttr.link_layer != IBV_LINK_LAYER_ETHERNET) continue;
- int gidIndex;
- NCCLCHECKGOTO(ncclIbGetGidIndex(ibDev->context, ibDev->portNum, &ibDev->portAttr, &gidIndex), ret, fail);
- NCCLCHECKGOTO(wrap_ibv_query_gid(ibDev->context, ibDev->portNum, gidIndex, &handle->listenGids[gidSlot]), ret,
- fail);
- gidSlot++;
+ for (int devIdx = 0; devIdx < ncclNMergedIbDevs && gidSlot < 2; devIdx++) {
+ struct ncclIbMergedDev* mDev = ncclIbMergedDevs + devIdx;
+ for (int i = 0; i < mDev->vProps.ndevs && gidSlot < 2; i++) {
+ int ibDevN = mDev->vProps.devs[i];
+ ncclIbDev* ibDev = ncclIbDevs + ibDevN;
+ if (ibDev->portAttr.link_layer != IBV_LINK_LAYER_ETHERNET) continue;
+ int gidIndex;
+ NCCLCHECKGOTO(ncclIbGetGidIndex(ibDev->context, ibDev->portNum, &ibDev->portAttr, &gidIndex), ret, fail);
+ NCCLCHECKGOTO(wrap_ibv_query_gid(ibDev->context, ibDev->portNum, gidIndex, &handle->listenGids[gidSlot]), ret,
+ fail);
+ gidSlot++;
+ }
}
}
Loading