From 90462154e4e898c122c1a569f663a60d449b268b Mon Sep 17 00:00:00 2001 From: Kevin loo <28720907+lookevink@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:34:08 -0800 Subject: [PATCH 1/2] Port the two-HCA switchless cycle patch to NCCL 2.31.2 --- THIRD_PARTY_NOTICES.md | 4 + spark_transport/nccl/README.md | 16 ++++ .../nccl/nccl-2.31.2-switchless-cycle.patch | 73 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 spark_transport/nccl/nccl-2.31.2-switchless-cycle.patch diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 9defd02f..641d4f1a 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -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` ports SparkRing's 2.30.7 two-GID cycle patch to + `src/transport/generic.cc` and `src/transport/net_ib/connect.cc` at + [NCCL revision `7b83616`](https://github.com/NVIDIA/nccl/tree/7b83616df3ae082a1f32bb74c27458bfe8153a13). + Labski contributed the port under Apache-2.0. The context and removed lines in these unified diffs are verbatim NVIDIA NCCL source code: diff --git a/spark_transport/nccl/README.md b/spark_transport/nccl/README.md index 95fa63c0..4be23d54 100644 --- a/spark_transport/nccl/README.md +++ b/spark_transport/nccl/README.md @@ -28,6 +28,22 @@ selected cycle devices for both to be advertised. Despite the Profiles selecting four functions across two PCIe domains instead use the [four-GID routing contract](DUAL_PCI_DOMAIN.md). +### NCCL 2.31.2 on a two-HCA cycle with SGLang + +For a four-Spark cycle with one HCA facing each neighbor, apply the [2.31.2 patch](nccl-2.31.2-switchless-cycle.patch) +to [NCCL 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). + +Set `NCCL_IB_HCA` to the two neighbor devices, `NCCL_ALGO=Ring` and `NCCL_SWITCHLESS_RING_ONLY=1`. +For SGLang, point both `SGLANG_NCCL_SO_PATH` and `LD_PRELOAD` at the resulting library on every rank. +The tested fleet used one /30 subnet per cable and host-staged RoCE. The build and launch commands include +the remaining transport settings. [Build and launch instructions](https://github.com/looskis/labski/tree/b4874b107855f9e56e41df923ccd9f3466aaa2e4/inference-recipes/transport/nccl-switchless/) + +On that fleet, the Inkling SGLang image timed out during its first all-reduce with stock NCCL 2.30.7 and stock +2.31.2. With the patched library and ring-only initialization, all four ranks returned the expected sum on +eight calls each at 1 KiB, 64 KiB and 1 MiB. The same configuration served six chat requests with the native +Inkling 2 Small checkpoint. [Controls, per-port counters and serving results](https://github.com/looskis/labski/tree/b4874b107855f9e56e41df923ccd9f3466aaa2e4/inference-recipes/results/inkling2-gb10-runtime-2026-11-19/) + ## Runtime contract Use the patched NCCL library selected by the profile, either embedded in its diff --git a/spark_transport/nccl/nccl-2.31.2-switchless-cycle.patch b/spark_transport/nccl/nccl-2.31.2-switchless-cycle.patch new file mode 100644 index 00000000..0c687fff --- /dev/null +++ b/spark_transport/nccl/nccl-2.31.2-switchless-cycle.patch @@ -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++; ++ } + } + } From d00bed2e82dcfeddb5a49dcd52d453b09e6da6e3 Mon Sep 17 00:00:00 2001 From: FujitsuPolycom <87842395+FujitsuPolycom@users.noreply.github.com> Date: Mon, 30 Nov 2026 10:02:10 -0600 Subject: [PATCH 2/2] docs(nccl): polish 2.31.2 cycle env vars, section placement, and notices --- THIRD_PARTY_NOTICES.md | 8 +++--- spark_transport/nccl/README.md | 49 +++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 29660c1e..c7e44df2 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -37,10 +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` ports SparkRing's 2.30.7 two-GID cycle patch to - `src/transport/generic.cc` and `src/transport/net_ib/connect.cc` at - [NCCL revision `7b83616`](https://github.com/NVIDIA/nccl/tree/7b83616df3ae082a1f32bb74c27458bfe8153a13). - Labski contributed the port under Apache-2.0. +- `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: diff --git a/spark_transport/nccl/README.md b/spark_transport/nccl/README.md index 4be23d54..fedca86d 100644 --- a/spark_transport/nccl/README.md +++ b/spark_transport/nccl/README.md @@ -28,22 +28,6 @@ selected cycle devices for both to be advertised. Despite the Profiles selecting four functions across two PCIe domains instead use the [four-GID routing contract](DUAL_PCI_DOMAIN.md). -### NCCL 2.31.2 on a two-HCA cycle with SGLang - -For a four-Spark cycle with one HCA facing each neighbor, apply the [2.31.2 patch](nccl-2.31.2-switchless-cycle.patch) -to [NCCL 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). - -Set `NCCL_IB_HCA` to the two neighbor devices, `NCCL_ALGO=Ring` and `NCCL_SWITCHLESS_RING_ONLY=1`. -For SGLang, point both `SGLANG_NCCL_SO_PATH` and `LD_PRELOAD` at the resulting library on every rank. -The tested fleet used one /30 subnet per cable and host-staged RoCE. The build and launch commands include -the remaining transport settings. [Build and launch instructions](https://github.com/looskis/labski/tree/b4874b107855f9e56e41df923ccd9f3466aaa2e4/inference-recipes/transport/nccl-switchless/) - -On that fleet, the Inkling SGLang image timed out during its first all-reduce with stock NCCL 2.30.7 and stock -2.31.2. With the patched library and ring-only initialization, all four ranks returned the expected sum on -eight calls each at 1 KiB, 64 KiB and 1 MiB. The same configuration served six chat requests with the native -Inkling 2 Small checkpoint. [Controls, per-port counters and serving results](https://github.com/looskis/labski/tree/b4874b107855f9e56e41df923ccd9f3466aaa2e4/inference-recipes/results/inkling2-gb10-runtime-2026-11-19/) - ## Runtime contract Use the patched NCCL library selected by the profile, either embedded in its @@ -109,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= +SGLANG_NCCL_SO_PATH= +NCCL_IB_HCA= +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,