Skip to content

glm: resolve TF_NCCL_LIB in the shared NCCL library loader - #3106

Merged
ashhart merged 4 commits into
ashhart:mainfrom
vdalesandro:fix/glm-native-nccl-library
Nov 19, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
vdalesandro:fix/glm-native-nccl-library

Conversation

@vdalesandro

Copy link
Copy Markdown
Contributor

Requested separately in #2993 (review by @ashhart).

Change

Native GLM called the shared cuda.nccl.Library.open(), which always opened libnccl.so.2, while fabric/tp already selected TF_NCCL_LIB. Resolve the override in the shared loader so GLM and its sibling callers use the same explicit selection.

Callers of nccl.Library.open() (zig/src/cuda/nccl.zig:80), all verified at these lines in this checkout:

  • GLM: zig/src/families/glm/cuda_native.zig:264
  • Flash Next's --tp 2 collective: zig/src/families/flashnext/cuda_collective.zig:25
  • MiniMax M3: zig/src/families/minimax_m3/cuda_native.zig:159
  • Shared TP group: zig/src/cuda/tp_group.zig:35

Reuse the native environment path validator: unset, empty and whitespace-only values keep libnccl.so.2; nonblank paths retain their exact bytes; control characters are refused before loading. openPath, required-symbol resolution, cleanup, minimum-version checks and communicator behavior are unchanged.

Three existing files change: the loader and its inline CPU regression; one environment rule; one entry in the existing environment valid-case table. No new dependencies or GPU work.

Verification

With the repository's exact Zig 0.17.0, CPU-only:

  • Focused regression: RED on the unchanged default, GREEN after the fix.
  • Invalid-path refusal: RED without validation, GREEN through the existing path validator.
  • Direct native loader boundary: 8/8 tests passed.
  • zig build test-runtime-host: 328/328 tests passed.
  • zig build test-environment-host: 23/23 tests passed.
  • zig build native: 8/8 build steps succeeded; the built executable reports tensorfold-native 1.2.7.
  • zig fmt --check and git diff --check: passed.
  • Same lean checker against the pinned base: 345 inherited findings, 345 on the candidate, zero new.

The successful native executable build contains the final production changes. A later rebuild after adding only the environment test's valid-case row exceeded the local 180-second time limit; final runtime/environment tests and formatting/lean replay passed after that row was added. Initial missing sparse-checkout inputs and the test-table coverage failure were corrected; their failing receipts are retained locally.

No GPU, actual NCCL runtime, checkpoint inference, performance, complete no-GPU CI or release qualification is claimed. Native host checks prove path selection and validation, not device execution.

Once this lands, the switchless-ring recipe in #2993 can point at TF_NCCL_LIB in place of LD_LIBRARY_PATH.

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @vdalesandro, this is a clean fix. Routing TF_NCCL_LIB through the shared loader means GLM, Flash Next's collective, MiniMax M3 and the shared TP group all honour the same override. Unset, empty and blank values keep libnccl.so.2, so nothing changes for anyone who doesn't set it, and the test covers each case.

One thing before it can land:

  1. The serving pin for nccl.zig needs updating. zig/src/cuda/nccl.zig is a pinned serving file, so zig build -Dfixed-cpu test-gradient-serving fails on this branch with "serving source changed: zig/src/cuda/nccl.zig". The pins run on every pull request now, so CI will show the same. The fix is one line: in zig/tests/fixtures/gradient-serving.tsv (the zig/src/cuda/nccl.zig row), set the hash to 0e36d9d84d3194d0cb63a73c3f66533e60b4da0ef08fa81bc2851e384b28b7b3 and add this PR's number to that row's commits column, as the other re-pinned rows do.

Optional: zig/src/fabric/tp/config.zig:119 still reads the variable raw, so a set-but-blank TF_NCCL_LIB= opens "" there rather than the default. Routing it through configuredPath() would make the two paths agree.

  • Synthena (Ash's Agent)

vdalesandro added a commit to vdalesandro/TensorFold that referenced this pull request Nov 14, 2026
… re-pinned

Review follow-up for ashhart#3106.

- zig/tests/fixtures/gradient-serving.tsv: the zig/src/cuda/nccl.zig row carries
  the new hash and this PR's number, so test-gradient-serving passes again.
- Library.pathFrom(raw) holds the one rule (a path is kept as written; unset,
  empty and blank keep libnccl.so.2; a control byte is refused). Library.open
  applies it to the process environment as before, and fabric/tp/config.zig
  applies it to its own getter, so a set-but-blank TF_NCCL_LIB no longer opens
  a blank path there. A malformed value is error.BadSetting, like the other
  TP settings.

Checked on a CPU-only host with Zig 0.17.0: test-gradient-serving (fails before
the re-pin with "serving source changed: zig/src/cuda/nccl.zig", passes after),
test-tp (the new config test fails on the old line and passes on the new one),
test-runtime-host, test-environment-host, the nccl.zig tests, zig fmt --check
and the lean check (0 new). No device run.
@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks for the follow-up. The override now runs through one shared rule, so the native callers and the tensor-parallel session resolve the library the same way: a set path is kept exactly as written, an unset or blank value keeps the standard default, and a value with control characters is refused before anything is loaded. The serving pin now names the final bytes of the loader, and the blank-value gap on the tensor-parallel side is closed through that same rule, with a malformed value refused like the other settings.

Nothing here changes the default or touches tokens, prompts, sampling or any timing path; the only behaviour that moves is an override someone sets on purpose. The check suite has not reported green at this head, so that is the remaining gate.

  • Synthena

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @vdalesandro. We re-read this head against current main and it is ready from our side.

  • nccl.Library.open() now takes TF_NCCL_LIB through the shared path rule, so GLM, Flash Next's --tp 2 collective, MiniMax M3 and the shared TP group all open the same library. Unset, empty and blank values still open libnccl.so.2, so nothing changes by default.
  • The tensor-parallel config now uses the same rule (fabric/tp/config.zig), as the review suggested, so a blank TF_NCCL_LIB= keeps the default there too, and a control character is refused in both places.
  • The nccl.zig serving pin matches the changed file, and every other pinned row still matches.
  • Both new tests would fail on main: the loader test calls the new path rule, and the config test expects a blank value to keep the default.

Nothing here reaches tokens, so no device run is needed. It goes to the landing train with CI green at this head.

  • Synthena

@ashhart
ashhart force-pushed the fix/glm-native-nccl-library branch from f20d0af to 7158a8c Compare November 19, 2026 05:21
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @vdalesandro. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

ashhart pushed a commit to vdalesandro/TensorFold that referenced this pull request Nov 19, 2026
… re-pinned

Review follow-up for ashhart#3106.

- zig/tests/fixtures/gradient-serving.tsv: the zig/src/cuda/nccl.zig row carries
  the new hash and this PR's number, so test-gradient-serving passes again.
- Library.pathFrom(raw) holds the one rule (a path is kept as written; unset,
  empty and blank keep libnccl.so.2; a control byte is refused). Library.open
  applies it to the process environment as before, and fabric/tp/config.zig
  applies it to its own getter, so a set-but-blank TF_NCCL_LIB no longer opens
  a blank path there. A malformed value is error.BadSetting, like the other
  TP settings.

Checked on a CPU-only host with Zig 0.17.0: test-gradient-serving (fails before
the re-pin with "serving source changed: zig/src/cuda/nccl.zig", passes after),
test-tp (the new config test fails on the old line and passes on the new one),
test-runtime-host, test-environment-host, the nccl.zig tests, zig fmt --check
and the lean check (0 new). No device run.
ashhart and others added 4 commits November 19, 2026 14:40
… re-pinned

Review follow-up for ashhart#3106.

- zig/tests/fixtures/gradient-serving.tsv: the zig/src/cuda/nccl.zig row carries
  the new hash and this PR's number, so test-gradient-serving passes again.
- Library.pathFrom(raw) holds the one rule (a path is kept as written; unset,
  empty and blank keep libnccl.so.2; a control byte is refused). Library.open
  applies it to the process environment as before, and fabric/tp/config.zig
  applies it to its own getter, so a set-but-blank TF_NCCL_LIB no longer opens
  a blank path there. A malformed value is error.BadSetting, like the other
  TP settings.

Checked on a CPU-only host with Zig 0.17.0: test-gradient-serving (fails before
the re-pin with "serving source changed: zig/src/cuda/nccl.zig", passes after),
test-tp (the new config test fails on the old line and passes on the new one),
test-runtime-host, test-environment-host, the nccl.zig tests, zig fmt --check
and the lean check (0 new). No device run.
@ashhart
ashhart force-pushed the fix/glm-native-nccl-library branch from 7158a8c to 778cd79 Compare November 19, 2026 14:40
@ashhart
ashhart merged commit 905ce9b into ashhart:main Nov 19, 2026
1 of 10 checks passed
ashhart pushed a commit that referenced this pull request Nov 19, 2026
… re-pinned

Review follow-up for #3106.

- zig/tests/fixtures/gradient-serving.tsv: the zig/src/cuda/nccl.zig row carries
  the new hash and this PR's number, so test-gradient-serving passes again.
- Library.pathFrom(raw) holds the one rule (a path is kept as written; unset,
  empty and blank keep libnccl.so.2; a control byte is refused). Library.open
  applies it to the process environment as before, and fabric/tp/config.zig
  applies it to its own getter, so a set-but-blank TF_NCCL_LIB no longer opens
  a blank path there. A malformed value is error.BadSetting, like the other
  TP settings.

Checked on a CPU-only host with Zig 0.17.0: test-gradient-serving (fails before
the re-pin with "serving source changed: zig/src/cuda/nccl.zig", passes after),
test-tp (the new config test fails on the old line and passes on the new one),
test-runtime-host, test-environment-host, the nccl.zig tests, zig fmt --check
and the lean check (0 new). No device run.
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @vdalesandro. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants