Repository navigation
Studio: gate GGML_CUDA_P2P on a confirmed NVLink fabric, not a product name - #10646
Conversation
_apply_datacenter_env inferred a working peer-to-peer fabric from the GPU name. The datacenter allowlist includes RTX 6000 Ada, RTX PRO 6000, L40, L40S and L4, none of which have an NVLink connector, so on a multi-GPU box built from those parts the only peer path is PCIe. On bare-metal Linux behind a translating IOMMU CUDA does not support PCIe peer copies at all: the write is discarded, the copy still returns cudaSuccess, and every model emits garbage with nothing logged (#10613). Split the gate. GGML_CUDA_FORCE_CUBLAS_COMPUTE_32F is about FP32 accumulation, is safe on every part in the list and keeps the existing allowlist. GGML_CUDA_P2P and CUDA_SCALE_LAUNCH_QUEUES now need both a narrower NVLink-capable name gate and positive NV# evidence for every selected pair from nvidia-smi topo -m, cached once per process. Name membership is necessary, never sufficient: cudaDeviceCanAccessPeer and nvidia-smi topo -p2p both answered OK on the failing host. Everything unknown now fails closed. No nvidia-smi, a non-zero exit, a timeout, a truncated table or an index space we cannot join all withhold P2P rather than assume it. Where CUDA_DEVICE_ORDER is not PCI_BUS_ID, physical ids and nvidia-smi indices need not agree, so the whole matrix must be uniformly NVLinked for the conclusion to hold under any permutation; the veto says so and names the variable to set. ggml tests GGML_CUDA_P2P for presence rather than value, so the documented GGML_CUDA_P2P=0 opt-out was enabling what it looked like it disabled. A falsy user value is now removed from the child environment and suppresses the default, matching the GGML_CUDA_ENABLE_UNIFIED_MEMORY handling (#8651). CUDA_SCALE_LAUNCH_QUEUES is unrelated to peer copies and still applies. The log now names every variable and value it sets, and on withholding P2P names the signal that vetoed it. The old message named none of them. Tests: 72 in test_datacenter_gpu_tuning.py (was 37), including the reported 2x RTX 6000 Ada host, L40S/L40/L4/RTX PRO 6000, a real 8x B200 topo table with its ANSI header, NIC rows and legend, PCIe-wired A100s, unknown topology, exact and inexact index mappings, IOMMU group states and the falsy opt-out.
A data-center product name does not imply a working peer fabric. RTX 6000 Ada, RTX PRO 6000, L40, L40S and L4 are on the allowlist and have no NVLink connector at all, so their only peer path is PCIe, and a PCIe peer copy on bare-metal Linux behind a translating IOMMU is unsupported by CUDA: the write is discarded, the copy still returns cudaSuccess, and every model emits garbage with nothing logged. GGML_CUDA_FORCE_CUBLAS_COMPUTE_32F is a property of the silicon, not the interconnect, and keeps the existing allowlist. GGML_CUDA_P2P now additionally requires positive NV# evidence for the selection from nvidia-smi topo -m, failing closed on every unknown. The driver is not consulted: can_device_access_peer and topo -p2p w both answer OK on the affected hosts. CUDA_SCALE_LAUNCH_QUEUES sizes a command buffer and moves no data, so it is not gated with P2P. llama.cpp tests GGML_CUDA_P2P for presence, not value, so a user-supplied 0 ENABLED what they were turning off. Falsy values are now removed from the child env on every launch path, consumer and Vulkan included, since those boxes never reach the data-center gate. UNSLOTH_DISABLE_DC_P2P=1 drops the peer flag while keeping FP32 accum; UNSLOTH_FORCE_DC_P2P=1 opts back in. The log now names every variable set and the signal that withheld P2P. Adds scripts/p2p_integrity_probe.py, a sentinel-buffer peer-copy check to hand to anyone reporting garbled multi-GPU output, and studio/NVLINK_P2P.md.
Three strict xfails, so each passes while the gap is open and fails the moment it is closed: - UNSLOTH_DISABLE_DC_P2P=1 vetoes the default but leaves an inherited GGML_CUDA_P2P in place, so peer copies stay on despite the user disabling them. - _apply_datacenter_env setdefault()s over a falsy value when called without the call site's _sanitize_p2p_env, leaving GGML_CUDA_P2P=0 present (ON upstream). - The sanitizer runs only in load_model; the STT sidecar and RAG embedding server build their child env from dict(os.environ) and spawn llama-server on the GPU without it.
_scratch_{routes,topo_probe,veto}.py were my throwaway review harnesses and
test_zz_scratch.py was another reviewer's; none belongs on the branch.
Review of the first commit, plus a platform/hardware simulation matrix, found six gaps. All are fixed here. - The falsy-value strip ran only in load_model. The STT sidecar and the RAG embedding server build their own child env and spawn llama-server on the GPU, so an inherited GGML_CUDA_P2P=0 still enabled peer copies there. Stripping now happens in _llama_server_env_for_binary, which chat, STT and the embedding probe all build from, and in the embedding server's own builder. A corrupt embedding degrades retrieval silently, with no garbled text to notice. - UNSLOTH_DISABLE_DC_P2P=1 suppressed our default but did not remove an inherited GGML_CUDA_P2P, so a knob named DISABLE left peer copies enabled. - _apply_datacenter_env trusted the call site to have sanitized first. Called directly with a falsy value it kept GGML_CUDA_P2P=0 and logged it as "(user)", which reads as off to a human and ON to ggml. - The index spaces are now joined on GPU uuid, which torch and nvidia-smi both report, instead of trusting CUDA_DEVICE_ORDER. The old fallback demanded the whole matrix be NV#, which vetoed a genuinely NVLinked pair on a partially bridged 4x or 8x box. FASTEST_FIRST is the CUDA default, so that fallback was the normal path, not the exotic one. A partial join is refused rather than half-trusted. - The IOMMU diagnosis was unreachable for the host that needs it: a 2x RTX 6000 Ada fails the NAME gate first and returned before the IOMMU clause. It now hangs off every veto that implies a PCIe peer path. - A raising probe propagated out of _p2p_veto_reason and failed the whole model load. It is now total and fail-closed. The IOMMU scan is also cached, since it is a boot-time property and the reporter's host has 175 groups to walk. Warn on a consumer multi-GPU box carrying its own truthy GGML_CUDA_P2P: that path never reaches the datacenter block, so it warned nowhere before. scripts/p2p_integrity_probe.py compared against the sentinel only, so a copy that wrote the wrong data scored a PASS. It now compares against the source. Non-positive --repeats or --sizes-mib printed PASS without testing anything. Tests: 88 in test_datacenter_gpu_tuning.py, up from 37 on main.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… warning Two review findings on the previous commit. The selection was being remapped as if it held CUDA ordinals. It does not: _get_gpu_memory sources gpu_indices from `nvidia-smi --query-gpu=index`, the same tool and the same enumeration as `topo -m`, so they index the matrix directly. With CUDA_DEVICE_ORDER left at its FASTEST_FIRST default on a partially bridged host, the remap could turn a PCIe-crossing selection into an NVLinked-looking one and set GGML_CUDA_P2P on exactly the configuration this gate exists to refuse. Reading the selection verbatim also removes the whole-matrix fallback and the uuid join it needed, so a bridged pair now keeps P2P under any device order. The 'no confirmed NVLink' warning ran before the topology check, so someone who had deliberately set GGML_CUDA_P2P=1 on a verified NV# pair, the configuration PR #6098 benchmarked, was told to turn it off. It is now gated on an actual veto. Tests: 89, including every pair of a bridged 4x fixture under unset, PCI_BUS_ID and FASTEST_FIRST orderings, and both directions of the warning.
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Three review findings. nvidia-smi ignores CUDA_VISIBLE_DEVICES (verified here: it lists all 8 cards on a host masked to one), so the interconnect matrix covers devices the llama-server child will never touch. With no explicit selection, a mask exposing a clean NVLinked pair on a partially bridged box was vetoed by a PCIe edge to a hidden device, losing the speedup for no reason. The no-selection path now filters the matrix through the resolved mask. UNSLOTH_DISABLE_DC_P2P=1 returns before the topology is ever inspected, so the follow-on branch reported the box as having no confirmed NVLink fabric and suggested forcing P2P back on. That is a corruption warning about a possibly healthy machine, aimed at someone who had already decided. It now logs at info. p2p_integrity_probe.py told every passing host to set UNSLOTH_FORCE_DC_P2P=1, but that override sits behind the data-center name gate and does nothing on a consumer card. It now gives the right knob for each case and repeats that 0 does not disable GGML_CUDA_P2P upstream. Tests: 91.
|
Tested this on two boxes: one that has the bug (RTX 6000 Ada + RTX 3090, no NVLink, translating IOMMU) and an 8x B200 NVSwitch box that must not regress. The problem. Studio set Does the PR fix it? Yes. Same binary, same argv, only the env differs. Counting
The flag no longer reaches llama.cpp on that box, which is the whole fix. gitcleft already measured his host clean with the variable absent, so this is the state he tested as working. Also confirmed the presence-not-value trap directly on b10840. Peer probes with the variable unset, Does it break NVLink boxes? No. On the 8x B200:
The index bug is fixed. On the previous commit I ran Two small things:
|
Three more review findings, one of them a bug in the previous commit. The mask filter added last round treated CUDA_VISIBLE_DEVICES entries as nvidia-smi indices. They are CUDA ordinals, and CUDA reorders under the default FASTEST_FIRST, so mask 0,1 can expose physical 0,2. Filtering the matrix with them could confirm NV# for a pair that is not the one in use and enable P2P across a real PCIe link, which is the corruption this gate exists to prevent. _cuda_compute_caps already declines the same mapping on the same grounds. The filter now applies only under CUDA_DEVICE_ORDER=PCI_BUS_ID and otherwise falls back to requiring the whole box, which costs the optimisation rather than correctness. A deliberate zero-offload load is masked to CUDA_VISIBLE_DEVICES=-1 and moves no tensors between GPUs, but the tuning and the peer-copy warning both ran before that state was known. _cpu_only_zero_offload is computed earlier and gates both. p2p_integrity_probe.py counted an allocation failure, typically a resident model holding the VRAM, as a lost peer copy: it reported data loss and told the user P2P was unsafe without having tested a single transfer. Allocation failures are now reported separately and exit 2, the documented inconclusive code, leaving exit 1 for copies that were tested and did lose data. Tests: 91.
The gate verifies nvidia-smi physical ids, so the child's mask has to select the same devices. CUDA_DEVICE_ORDER=PCI_BUS_ID was pinned only for an explicit user pick, while the mask itself is emitted from gpu_indices in both cases, so an auto-fit selection verified as physical [0,1] could launch on [0,2] under the default FASTEST_FIRST: NVLink confirmed for one pair, peer traffic on another. The ids come from the same nvidia-smi enumeration on both arms, and the existing comment already describes aligning CUDA with the picker's PCI-bus order, so the pin now applies whenever that mask is built. The call-site warning is for hosts that never reach _apply_datacenter_env. A datacenter box does reach it and is warned there too, so both fired on the first load. It is now scoped to non-datacenter, non-Vulkan selections. p2p_integrity_probe.py ran happily under a ROCm torch, since HIP reuses the torch.cuda namespace, then told the user to set GGML_CUDA_P2P, which only the CUDA backend reads. It now declines with exit 2 rather than passing and giving an instruction that does nothing. Tests: 93, and 2099 across the launch-path suites for the ordering change.
nvidia-smi topo -m output cut at a ROW boundary still exits 0 and parses cleanly, just short: the header names 8 GPUs and only 4 rows arrive. Reproduced against this host, 28 of the 56 directed pairs, every surviving value NV18. That is enough to look uniformly NVLinked, which is exactly the condition the unpinned-order escape added two commits ago trusts, so P2P could be enabled for cards whose links were never read. The parser now requires every directed pair the header promised and returns None otherwise, which callers already treat as unreadable and therefore fail closed on. The real 8x B200 matrix is unaffected: 56 pairs, all four selections still allowed. Tests: 100.
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
_get_gpu_memory returns nvidia-smi PCI indices from its primary branch and torch CUDA ordinals from the fallback it takes when the nvidia-smi memory query fails. The unmasked-auto-fit pin added last commit assumed the former, so on a host where that query fails and PCI and CUDA order differ, pinning PCI_BUS_ID re-emitted ordinals as a different set of cards: Auto could run on GPUs other than the ones whose free memory it measured, and the topology check could verify the wrong pair. The two branches now record which index space they returned, and the pin requires PCI indices. An explicit user pick is unaffected, since those ids come from the UI's own PCI-ordered picker. The probe's ROCm guard only tested torch.version.hip. AMD SDK wheels leave that unset and encode rocm in __version__ instead, which is why the backend's _torch_is_rocm checks both, so a multi-GPU AMD host could still run the CUDA-only probe and be told to set GGML_CUDA_P2P. It now checks both. Tests: 102, plus 2027 across the launch-path suites.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
… shell-out (#10720) * Studio: read the NVLink fabric from NVML, not a 1.2s nvidia-smi shell-out The P2P gate added in #10646 verifies NVLink between every selected GPU pair before setting GGML_CUDA_P2P. It reads nvidia-smi topo -m, which costs ~1200ms on an 8x B200, paid once per process on the model-load path. Ask the driver instead. NVML ships with the driver, so it is present exactly when nvidia-smi is, and ctypes against libnvidia-ml.so.1 needs no new dependency: nvidia-ml-py is not installed in a Studio env. The same 8x B200 answers in ~230ms with no subprocess at all, and the verdict is identical: 56 of 56 ordered pairs, both directions. Evidence stays per pair. nvmlDeviceGetP2PStatus with the NVLink capability index asks about one pair; an active link to an NVSwitch proves only that the GPU is attached to a switch, and switch fabrics can be partitioned, so switch attachment is never read as all-pairs reachability. Everything short of a complete answer falls back to topo -m and then to no P2P: missing library or symbol, any non-zero return, fewer than two devices, a partial walk, or a positive contradicted by zero live NVLinks on an endpoint. A usable topo -m proved nvidia-smi had enumerated the selection; NVML does not carry that implication, so an NVML matrix is only matched against ids known to come from nvidia-smi. Also prime the cache on the existing startup warm thread so the first load reads it warm, validate the topo key set rather than its length, and add UNSLOTH_P2P_TOPO_CROSSCHECK=1 plus probe reporting to qualify the fast path on PCIe-only and partially bridged hosts, which were not available to test here. * Prime the NVLink matrix on the inference_backend stage, not a new one A separate warm stage broke two startup guards, correctly. Every importing stage needs an entry in _STAGE_PACKAGE so a failed import is purged rather than left half-cached, and inference_backend is exempt only because it imports first-party code. The topology prime imports that same module, so it belongs on that stage instead of asking for an exemption of its own. The prime is wrapped so it can never fail the stage it rides: a warm miss costs latency, and the gate re-probes on demand and fails closed by itself. * Do not let an unknown NVML status or an early prime deny P2P Three fixes from review. An NVML P2P status that is not OK is not automatically a denial. Statuses 1 to 5 say not supported and give a reason; 6 is UNKNOWN, and a newer driver could return something past the end of the enum. Recording either as NO-NVLINK made the matrix look conclusive and denied topo -m the chance to confirm a fabric that is really there, so both now fall through. The startup prime runs early, possibly mid driver initialisation. It went through the same cache as the load path, so a miss there kept P2P off for the life of the process even once the topology became readable. It now primes with cache_failure=False: a failed prime leaves the cache cold and the load path probes as it would have. A successful prime still caches, and the load path still caches its own miss exactly as before. A driver install can leave nvml.dll in the NVSMI directory rather than a DLL search path, the same way it does nvidia-smi.exe. Include that location, and System32, among the Windows candidates, mirroring _nvidia_smi_executable. * Tighten the comments on the NVML P2P path * Keep an explicit GPU pick's PCI provenance out of the memory probe's hands _GPU_IDS_ARE_PCI_INDICES records where _get_gpu_memory last got its ids, which is not the same question as whether THIS selection is nvidia-smi indexed. An explicit pick comes from the UI's PCI-ordered picker and is PCI-ordered by construction, but a transiently missing or off-PATH nvidia-smi sends the unrelated memory query down the torch fallback and flips that flag process wide. The NVML provenance gate then read the explicit ids as CUDA ordinals and vetoed a verified fabric. The two veto entry points and _apply_datacenter_env now take the caller's provenance, and load_model passes it, keeping the process-wide flag only as the default for callers that do not know. Same reasoning as the existing launch_order_pinned comment two lines up. Also state the probe's mismatch message precisely: NVML answers first by default, so a topo-only pair is not enabled, and UNSLOTH_P2P_TOPO_CROSSCHECK=1 is what makes topo -m win instead. * Bound the NVML probe, protect a published matrix, and skip primed work nobody wants Three from review. ctypes has no timeout. The shell-out this replaced ran under one, so a wedged driver that blocks rather than returning an error could hang nvmlInit_v2 and with it the model load, and never reach the fallback that has a timeout of its own. The walk now runs on a daemon thread with a wall-clock bound; a stalled call is abandoned and the caller falls through to topo -m. Publication was unconditional, and the generation counter only guards against a refresh. A load whose own probe failed transiently could therefore overwrite a matrix the startup prime had already published, turning P2P off for every later load. A miss no longer replaces a cached success. The prime also ignored the opt-outs. UNSLOTH_DISABLE_DC_TUNING=1, UNSLOTH_DISABLE_DC_P2P=1 and a falsy GGML_CUDA_P2P all mean the answer can never be used, and the load path already skips the probe for exactly that reason. * Run the topology prime off the warm sequence, not inside it Bisected from CI. test_idle_loop_resets_timer_for_same_repo_different_variant failed on this branch in 3 of 3 runs and on none of 14 other branches, and a branch identical to this one except with the prime removed did not fail it. The prime sat inline in the inference_backend stage, so it could spend its NVML bound plus the shell-out timeout before the transformers and datasets stages even started. That is reachable in the test suite, where a fake torch reporting datacenter GPUs is installed process-wide for the worker: the warm thread then walks past every guard into the real probe and stalls its worker long enough to tip a 0.05s idle threshold in an unrelated async test. It now runs on a daemon thread of its own and returns immediately, so it cannot delay a stage or anything sharing the process. Nothing waits on it: the gate re-probes on demand, so a prime that never finishes costs one load its head start and nothing else. This is the half of the earlier delaying-later-stages report I did not fix; I addressed the opt-out skip and left the blocking. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Let a uniform NVLink fabric stand without PCI provenance The ordering check above already permits an unknown device order when every pair in the matrix is NVLinked, because the mapping cannot change the verdict there. The provenance gate is the same class of concern and was not given the same escape, so an auto-fit selection whose ids came from the torch fallback lost P2P on a fully connected box where no mapping could have changed the answer. It now carries the same exception. Ids the matrix does not cover still veto on the per-pair lookup, so this does not become a blanket pass, and a partially bridged box still requires provenance because there the mapping decides the outcome. Two existing provenance tests moved to a partially bridged fixture: they were asserting a veto on a uniform fabric, which is the case now deliberately allowed. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Do not read explicitness as proof of PCI indexing The picker lists whatever the hardware inventory enumerated, and with nvidia-smi unavailable that is torch. An explicit pick is PCI-indexed only because hardware.py setdefaults CUDA_DEVICE_ORDER=PCI_BUS_ID, and setdefault means a user can override it. Under FASTEST_FIRST on a mixed-performance host the same numbers name different cards, so trusting bool(gpu_ids) could match a partially bridged matrix against the wrong pair and enable GGML_CUDA_P2P on a PCIe path, which is the exact failure this gate exists to prevent (#10613). It now asks the two questions that actually answer it: did nvidia-smi produce the ids, or does this process pin PCI order so torch's ordinals coincide with it. The common case is unchanged because PCI_BUS_ID is the default the backend sets, so the explicit-pick case fixed earlier still keeps its P2P. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Let the prime pay the cheap path only, never the shell-out Third time this prime has perturbed CI. Making it non-blocking to the warm sequence was not enough: the thread still ran the full probe, including a nvidia-smi subprocess that can run for its whole timeout, and on a worker where a fake torch reports datacenter GPUs that lands next to tests whose entire assertion is that the event loop was not blocked. Two more of them failed on this branch and on none of 5 recent main runs. A prime is an optimisation, so it should only take the cheap path. It is now NVML-only: if NVML cannot answer, the cache stays cold and the load path does the slow probe inline exactly as it would have without a prime. The production benefit is unchanged on the hosts that have NVML, which is every host with a driver, since nvidia-smi is itself an NVML client. It also publishes only a success, so the earlier cache_failure argument now falls out of the shape rather than needing a flag at this call site. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Do not let the startup prime retire the topology cross-check UNSLOTH_P2P_TOPO_CROSSCHECK=1 is the mechanism this PR offers for qualifying the NVML fast path on the fabrics it could not test. It did not work in a Studio process. The cross-check lives in _probe_interconnect_matrix, which only the load path reaches. prime_nvlink_topology calls _probe_nvml_nvlink_topology directly and publishes to the cache, and the warm stage always primes before any load, so the cache was warm by the time the gate asked and the two tiers were never compared. That is the shipping configuration, not a corner case. Measured on the 8x B200 before this commit: with the variable set, a prime followed by a gate call spawned zero nvidia-smi and returned the NVML verdict unchallenged. The consequence is not only a missing log line. On a host where the tiers disagree, topo -m is supposed to win and veto; instead _p2p_veto_reason returned None and P2P was enabled, which is the #10613 failure the gate exists to prevent, reached through the flag meant to guard against it. The prime now stands down while the variable is set and leaves the cache cold, so the load path runs both tiers inline. That is what the variable already advertises ("costs the slow probe on every process"), and it keeps the prime's rule that it may pay the cheap path and nothing else: no shell-out is added to a background thread, so the CI timing coupling fixed earlier in this branch stays fixed. Default behaviour is untouched. Without the variable the prime still publishes an NVML success, the fast path still spawns no nvidia-smi, and the warm read is still ~0.0001 ms. Two tests, both of which fail without the change: one on prime_nvlink_topology directly, one end to end in the order Studio runs it (warm stage primes on its own thread, then the gate is asked) asserting that the slow tier really ran and won the disagreement. * Patch the probe the warm prime actually calls test_the_prime_never_blocks_the_warm_sequence patched _nvlink_topology, but _prime_nvlink_topology goes through prime_nvlink_topology, which calls _probe_nvml_nvlink_topology directly. The patch therefore never ran: the probe stayed on the autouse fixture's NVML-absent default and returned immediately, so the worker was already dead by the time `assert worker.is_alive()` looked at it. Measured on this tree before the change: the patched function was called 0 times and the worker was not alive 0.5s in, so that assertion was passing on timing rather than on behaviour and could fail on a loaded runner. The elapsed-time assertion was still doing real work, so only the patch target changes. 30 consecutive runs of the test, 0 failures. * Tighten the comments added by this branch Comments and docstrings only, AST-verified against 8b6c067. The load-bearing facts stay: the #10613 contradiction guard, the NVSwitch partition argument, why the prime must not shell out, and why torch ordinals cannot index an NVML matrix. What went is the restatement around them. Comment lines added by this branch in the two source files: 59 to 29. --------- Co-authored-by: danielhanchen <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Fixes #10613.
The bug
_apply_datacenter_envsetsGGML_CUDA_P2P=1on any multi-GPU host whose cards match_DATACENTER_GPU_RE. That allowlist includes four families with no NVLink connector at all: RTX 6000 Ada, RTX PRO 6000, L40/L40S and L4. PR #6098 added the flag after benchmarking a 6x B200 NVLink box, so the gate has been measuring the wrong property since then: it asks what the card is called, not whether a peer copy between these two cards actually works.On bare-metal Linux with a translating IOMMU, a PCIe peer copy is not slow, it is unsupported. The write faults, the IOMMU discards it as an Unsupported Request, and
cudaMemcpyPeerAsyncstill returnscudaSuccessbecause it has no return code for "the platform ate your DMA". Inside llama.cpp that means tensors that never arrive, so every model emits!!!!!,/////, a repeated Cyrillic token or fluent word salad, with nothing logged. It looks exactly like a broken quant or a wrong chat template, which is why the reporter spent a day on it.llama.cpp documents both halves of this itself. From docs/multi-gpu.md:
"Any value" is the second bug.
GGML_CUDA_P2P=0turns peer access on, so the opt-out documented in #6098 ("all three usesetdefault, so a user-supplied value always wins") was never real for this flag.Before and after
GGML_CUDA_P2P=0No host that was producing correct output starts producing incorrect output. Hosts that lose
GGML_CUDA_P2Plose throughput, not correctness.That second group is not empty, and an earlier version of this sentence wrongly implied it was. An NVLink host whose
nvidia-smi topo -mcannot be read, realistically some containers and WSL, loses P2P until someone setsUNSLOTH_FORCE_DC_P2P=1. So does a partially bridged box under an unpinnedCUDA_DEVICE_ORDER. That is the deliberate trade: the gate fails closed, because losing an optimisation is recoverable and shipping wrong tokens is not.What changed
The gate is split in two.
GGML_CUDA_FORCE_CUBLAS_COMPUTE_32Fis a property of the silicon rather than the interconnect, and the reporter's own isolation table shows it clean on the affected host, so it keeps the existing allowlist.GGML_CUDA_P2Pnow needs a narrower name list (parts that actually ship with NVLink) and positiveNV#evidence for the selected pairs fromnvidia-smi topo -m.The driver is never asked.
torch.cuda.can_device_access_peer()returnsTrueandnvidia-smi topo -p2p wreportsOKon exactly the hosts where every copy drops. The driver's answer is the thing that is wrong. vLLM reached the same conclusion incan_actually_p2p()after vllm#2728.CUDA_SCALE_LAUNCH_QUEUESis deliberately not gated with P2P. It sizes a CUDA command buffer, moves no data between devices, and #10613 measured it clean in isolation. The set of hosts receiving it is byte for byte identical before and after this PR.The index spaces are joined on GPU UUID. The topology matrix is keyed by nvidia-smi index while the selection is in CUDA order, and CUDA defaults to
FASTEST_FIRST. Both torch and nvidia-smi report the UUID, so the join is exact under any ordering. Where it cannot be completed, Studio requires the whole matrix to beNV#so the conclusion holds under any permutation, and a partial join is refused rather than half-trusted.The opt-out works, on every launch path. Falsy values are removed rather than passed through, in
_llama_server_env_for_binary(chat, the STT sidecar and the embedding probe all build from it) and in the RAG embedding server's own builder. A consumer 2x 3090 box never reaches the datacenter gate, so it is covered here too, and now warns if it is carrying its own truthyGGML_CUDA_P2P.UNSLOTH_DISABLE_DC_P2P=1drops the peer flag while keeping FP32 accum, which the all-or-nothingUNSLOTH_DISABLE_DC_TUNINGcould not do, andUNSLOTH_FORCE_DC_P2P=1opts back in.The log names what it did. The old message was
Data-center GPU detected: applied DC llama.cpp env tuning (multi_gpu=True), so grepping forGGML_CUDA_P2Pafter suspecting it found nothing. It now names every variable set and the signal that withheld P2P.Also adds
scripts/p2p_integrity_probe.py, a sentinel-buffer peer copy check to hand to anyone reporting garbled multi-GPU output, andstudio/NVLINK_P2P.mdrecording why this cannot be a product-name allowlist.Testing
studio/backend/tests/test_datacenter_gpu_tuning.pygoes from 37 tests to 88. The parser runs against realnvidia-smi topo -moutput from an 8x B200 NVSwitch box and against the reporter's PCIe matrix, not toy strings.A separate simulation matrix runs the real gate functions over the cartesian product of [Linux, Windows, WSL, macOS] x [NVIDIA NVLink, NVIDIA PCIe datacenter, NVIDIA consumer, AMD/ROCm, CPU-only], plus nvidia-smi missing, timing out, exiting non-zero, and returning garbage, truncated, HTML or null-byte output; 16-GPU matrices, MIG rows, NIC rows and columns, future extra columns, reversed nvidia-smi enumeration, partial UUID joins, UUID-form
CUDA_VISIBLE_DEVICES(#8873), and older torch with no.uuid. 72 checks, all passing.It found two real bugs, both fixed and pinned with regression tests:
_p2p_veto_reasonand failed the entire model load. It is now total and fail-closed.Verified on hardware where possible: this box is an 8x B200 NVSwitch host, its real topology parses to 56 pairs of
NV18, and the veto returnsNoneunder the defaultCUDA_DEVICE_ORDER, so the configuration #6098 benchmarked keeps all three flags.Validated on affected hardware
@oobabooga tested both directions on real boxes (comment), which is the confirmation I could not produce here.
On an affected host (RTX 6000 Ada + RTX 3090, no NVLink, translating IOMMU), counting
cudaDeviceEnablePeerAccesscalls in the llama-server child, same binary and argv:GGML_CUDA_P2P=1+ the other two flagsThe presence-not-value trap was confirmed directly on b10840: peer probes with the variable unset,
=0and=1give 0, 2, 2.=0runs the peer path.On an 8x B200 NVSwitch box: the gate allows P2P for every selection tried, the topology parses to 56 pairs of
NV18,scripts/p2p_integrity_probe.pyreports 112 of 112 peer copies intact, and model output is identical with and without the flag.Detection cost
Only a multi-GPU host whose cards are NVLink-capable by name reaches
nvidia-smi topo -m. First model load in a fresh process, measured on an 8x B200:The topology result is cached per process, so later loads cost 0.071 ms. The one shell-out is about 1.2 s on this 8-GPU box, against a llama-server start measured in seconds. The name gate itself is 0.006 ms.
What this cannot verify: I do not have a non-NVLink multi-GPU box with a translating IOMMU, so the dropped-copy path itself is covered by simulation rather than by reproduction. @gitcleft, if you are willing to run
python scripts/p2p_integrity_probe.pyand a model load on this branch, that would close the loop.