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
2 changes: 1 addition & 1 deletion ci/test-file-size-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"defaultMaxLines": 1500,
"legacyMaxLines": {
"nemoclaw/src/commands/migration-state.test.ts": 1301,
"src/lib/inference/nim.test.ts": 2068,
"src/lib/inference/nim.test.ts": 2067,
"src/lib/onboard/preflight.test.ts": 1875,
"test/generate-openclaw-config.test.ts": 1915,
"test/install-preflight.test.ts": 3356,
Expand Down
35 changes: 34 additions & 1 deletion src/lib/inference/gpu-trust.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// SPDX-License-Identifier: Apache-2.0

import fs from "node:fs";
import { afterEach, describe, expect, it } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";

import {
captureNvidiaSmi,
isDenylistedNvidiaGpuName,
isPlausibleNvidiaGpuName,
nvidiaHostLooksGenuine,
resolveNvidiaSmiCommand,
WSL_NVIDIA_SMI_PATH,
} from "./gpu-trust";

const originalDescriptors = new Map<"arch" | "platform", PropertyDescriptor | undefined>();
Expand Down Expand Up @@ -67,6 +70,36 @@ afterEach(() => {
});

describe("GPU trust helpers", () => {
it("keeps PATH nvidia-smi authoritative and skips the WSL fallback", () => {
const runCaptureImpl = vi.fn<
(command: readonly string[], options?: { ignoreError?: boolean }) => string
>(() => "NVIDIA RTX 5090");

expect(captureNvidiaSmi(["--query-gpu=name"], { isWsl: true, runCaptureImpl })).toBe(
"NVIDIA RTX 5090",
);
expect(runCaptureImpl).toHaveBeenCalledTimes(1);
expect(runCaptureImpl.mock.calls[0][0][0]).toBe("nvidia-smi");
});

it("resolves the stock WSL driver command for managed vLLM prerequisites (#8794)", () => {
const runCaptureImpl = vi.fn((command: readonly string[]) =>
command[4] === WSL_NVIDIA_SMI_PATH ? WSL_NVIDIA_SMI_PATH : "",
);

expect(resolveNvidiaSmiCommand({ isWsl: true, runCaptureImpl })).toBe(WSL_NVIDIA_SMI_PATH);
});

it("does not probe the WSL driver path outside WSL", () => {
const runCaptureImpl = vi.fn<
(command: readonly string[], options?: { ignoreError?: boolean }) => string
>(() => "");

expect(captureNvidiaSmi(["--query-gpu=name"], { isWsl: false, runCaptureImpl })).toBe("");
expect(runCaptureImpl).toHaveBeenCalledTimes(1);
expect(runCaptureImpl.mock.calls[0][0][0]).toBe("nvidia-smi");
});

it("deny-lists JMJWOA generic placeholder GPU names even with NVIDIA prefix", () => {
expect(isDenylistedNvidiaGpuName("NVIDIA JMJWOA-Generic-GPU")).toBe(true);
expect(isDenylistedNvidiaGpuName("JMJWOA-Generic-NPU")).toBe(true);
Expand Down
35 changes: 35 additions & 0 deletions src/lib/inference/gpu-trust.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { isWsl as detectWsl } from "../platform";

const fs = require("fs");

export const WSL_NVIDIA_SMI_PATH = "/usr/lib/wsl/lib/nvidia-smi";

export interface NvidiaSmiOptions {
isWsl?: boolean;
runCaptureImpl: (command: readonly string[], options: { ignoreError: boolean }) => string;
}

function nvidiaSmiCandidates(isWsl: boolean): string[] {
return isWsl ? ["nvidia-smi", WSL_NVIDIA_SMI_PATH] : ["nvidia-smi"];
}

/** Run nvidia-smi from PATH, with the stock WSL driver path as a WSL-only fallback. */
export function captureNvidiaSmi(args: readonly string[], options: NvidiaSmiOptions): string {
const runningInWsl = options.isWsl ?? detectWsl();
for (const command of nvidiaSmiCandidates(runningInWsl)) {
const output = options.runCaptureImpl([command, ...args], { ignoreError: true });
if (output.trim()) return output;
}
return "";
}

/** Resolve an executable nvidia-smi command without accepting an arbitrary path. */
export function resolveNvidiaSmiCommand(options: NvidiaSmiOptions): string | null {
const runningInWsl = options.isWsl ?? detectWsl();
for (const command of nvidiaSmiCandidates(runningInWsl)) {
const resolved = options.runCaptureImpl(["sh", "-c", 'command -v "$1"', "--", command], {
ignoreError: true,
});
if (resolved.trim()) return command;
}
return null;
}

// Accept a name as NVIDIA when it advertises the vendor explicitly or matches
// a known NVIDIA product family. The caller must still cross-check against
// `detectNvidiaPlatform()` and the trust-tier gate before trusting the
Expand Down
26 changes: 26 additions & 0 deletions src/lib/inference/nim-igpu-compute-constrained.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

// Import source directly so tests cannot pass against a stale build.
import "./nim";
import { WSL_NVIDIA_SMI_PATH } from "./gpu-trust";
import { fittableOllamaModelTags, largestFittableOllamaModelTag } from "./ollama-model-registry";

const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -111,6 +112,31 @@ describe("detectGpu computeConstrained tagging (#3707)", () => {
fs.existsSync = savedExistsSync;
});

it("detects a WSL GPU when nvidia-smi is only in the stock driver path (#8794)", () => {
const runCapture = vi.fn((cmd: readonly string[]) =>
cmd[0] === WSL_NVIDIA_SMI_PATH && cmd.some((arg) => arg.includes("name,memory.total"))
? "NVIDIA RTX 5090, 32607, 32000"
: "",
);
const { nimModule, restore } = loadNimWithMockedRunner(runCapture);

try {
withFirmwareModel("Generic Linux Workstation", () => {
expect(nimModule.detectGpu({ isWsl: true })).toMatchObject({
type: "nvidia",
name: "NVIDIA RTX 5090",
count: 1,
totalMemoryMB: 32607,
availableMemoryMB: 32000,
});
});
expect(runCapture.mock.calls[0][0][0]).toBe("nvidia-smi");
expect(runCapture.mock.calls[1][0][0]).toBe(WSL_NVIDIA_SMI_PATH);
} finally {
restore();
}
});

it("marks the proof-passed N1X iGPU computeConstrained", () => {
const { nimModule, restore } = loadNimWithMockedRunner(
nvidiaSmiRunner("JMJWOA-Generic-GPU, 65471, 65000\n"),
Expand Down
1 change: 0 additions & 1 deletion src/lib/inference/nim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { createRequire } from "module";
import type { Mock } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

// Import source directly so tests cannot pass against a stale build.
import * as nim from "./nim";

Expand Down
34 changes: 18 additions & 16 deletions src/lib/inference/nim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { isSafeModelId } from "../validation";
import { isDgxStationGb300Product } from "./dgx-station-identity";
import {
type Arm64WslDockerDesktopGpuProver,
captureNvidiaSmi,
escapeGpuNameForTerminal,
isDenylistedNvidiaGpuName,
isPlausibleNvidiaGpuName,
Expand Down Expand Up @@ -103,6 +104,8 @@ export interface DetectGpuDeps {
proveArm64WslDockerDesktopGpu?: Arm64WslDockerDesktopGpuProver | null;
/** Read-only command transport used by observation-only readiness callers. */
runCaptureImpl?: typeof runCapture;
/** Override WSL detection for deterministic tests. */
isWsl?: boolean;
}

// Lazily construct the default ARM64 Linux GPU prover. Keep it behind a require
Expand Down Expand Up @@ -314,10 +317,9 @@ export function detectNvidiaPlatform(): NvidiaPlatform {
// container to a specific GPU on hosts with mixed configurations (e.g.
// DGX Station's GB300 alongside other GPUs).
export function getGpuIndicesByName(pattern: RegExp): number[] {
const out = runCapture(
["nvidia-smi", "--query-gpu=index,name", "--format=csv,noheader,nounits"],
{ ignoreError: true },
);
const out = captureNvidiaSmi(["--query-gpu=index,name", "--format=csv,noheader,nounits"], {
runCaptureImpl: runCapture,
});
if (!out) return [];
const indices: number[] = [];
for (const line of out.split("\n")) {
Expand Down Expand Up @@ -419,9 +421,9 @@ export function detectGpu(deps: DetectGpuDeps = {}): GpuDetection | null {
// the bootstrap-model selector can pick a model that fits currently
// available memory, not just the headline total.
try {
const output = runCaptureImpl(
["nvidia-smi", "--query-gpu=name,memory.total,memory.free", "--format=csv,noheader,nounits"],
{ ignoreError: true },
const output = captureNvidiaSmi(
["--query-gpu=name,memory.total,memory.free", "--format=csv,noheader,nounits"],
{ isWsl: deps.isWsl, runCaptureImpl },
);
if (output) {
type ParsedGpu = { name: string; memoryMB: number; freeMemoryMB: number };
Expand Down Expand Up @@ -532,10 +534,10 @@ export function detectGpu(deps: DetectGpuDeps = {}): GpuDetection | null {

// Fallback: unified-memory NVIDIA devices
try {
const nameOutput = runCaptureImpl(
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader,nounits"],
{ ignoreError: true },
);
const nameOutput = captureNvidiaSmi(["--query-gpu=name", "--format=csv,noheader,nounits"], {
isWsl: deps.isWsl,
runCaptureImpl,
});
const gpuNames = nameOutput
.split("\n")
.map((line: string) => line.trim())
Expand Down Expand Up @@ -692,12 +694,12 @@ export function detectGpu(deps: DetectGpuDeps = {}): GpuDetection | null {

/** Return one consistent NVIDIA driver version from the read-only host GPU inventory. */
export function detectNvidiaDriverVersion(
deps: { runCaptureImpl?: typeof runCapture } = {},
deps: { isWsl?: boolean; runCaptureImpl?: typeof runCapture } = {},
): string | undefined {
const output = (deps.runCaptureImpl ?? runCapture)(
["nvidia-smi", "--query-gpu=driver_version", "--format=csv,noheader,nounits"],
{ ignoreError: true },
);
const output = captureNvidiaSmi(["--query-gpu=driver_version", "--format=csv,noheader,nounits"], {
isWsl: deps.isWsl,
runCaptureImpl: deps.runCaptureImpl ?? runCapture,
});
if (!output) return undefined;
const versions = output
.split("\n")
Expand Down
1 change: 1 addition & 0 deletions src/lib/inference/serving/vllm-managed-support.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export { captureNvidiaSmi, resolveNvidiaSmiCommand } from "../gpu-trust.js";
export { ensureDualStationVllmApiKey, loadDualStationVllmApiKey } from "../vllm-api-key.js";
export {
buildLocalDualStationDockerEnv,
Expand Down
11 changes: 6 additions & 5 deletions src/lib/inference/vllm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
buildLocalManagedVllmDockerEnv,
buildRemoteVllmDockerEnv,
buildVllmDockerEnv,
captureNvidiaSmi,
ensureDualStationVllmApiKey,
loadDualStationVllmApiKey,
type MaterializedHostLocalVllmSelection,
Expand All @@ -47,6 +48,7 @@ import {
recoverInstalledManagedClusterVllmEndpoint,
resolveHostLocalVllmSelection,
resolveManagedVllmBridgeHost,
resolveNvidiaSmiCommand,
resolveVllmInstallModel,
runtimeAuthFingerprint,
tryInstallManagedClusterManagedVllm,
Expand Down Expand Up @@ -391,7 +393,7 @@ function dockerPrereqsOk(): { ok: boolean; reason?: string } {
if (!runCapture(["sh", "-c", "command -v docker"], { ignoreError: true }).trim()) {
return { ok: false, reason: "docker not found on PATH" };
}
if (!runCapture(["sh", "-c", "command -v nvidia-smi"], { ignoreError: true }).trim()) {
if (!resolveNvidiaSmiCommand({ runCaptureImpl: runCapture })) {
return { ok: false, reason: "nvidia-smi not found — vLLM requires NVIDIA drivers" };
}
if (!runCapture(["sh", "-c", "command -v curl"], { ignoreError: true }).trim()) {
Expand All @@ -401,10 +403,9 @@ function dockerPrereqsOk(): { ok: boolean; reason?: string } {
}

export function readGpuComputeCapabilities(): number[] {
const out = runCapture(
["nvidia-smi", "--query-gpu=compute_cap", "--format=csv,noheader,nounits"],
{ ignoreError: true },
);
const out = captureNvidiaSmi(["--query-gpu=compute_cap", "--format=csv,noheader,nounits"], {
runCaptureImpl: runCapture,
});
if (!out) return [];
const capabilities: number[] = [];
for (const line of out.split("\n")) {
Expand Down
Loading