diff --git a/packages/test/src/test/ai-provider-hft/HFT_Device.test.ts b/packages/test/src/test/ai-provider-hft/HFT_Device.test.ts index ccbbf16f8..0a9c209a5 100644 --- a/packages/test/src/test/ai-provider-hft/HFT_Device.test.ts +++ b/packages/test/src/test/ai-provider-hft/HFT_Device.test.ts @@ -18,8 +18,8 @@ describe("resolveHftPipelineDevice", () => { } }); - it("passes auto through on the server", () => { - expect(resolveHftPipelineDevice("auto")).toBe("auto"); + it("resolves auto to undefined on the server", () => { + expect(resolveHftPipelineDevice("auto")).toBeUndefined(); expect(resolveHftPipelineDevice("cpu")).toBe("cpu"); expect(resolveHftPipelineDevice("gpu")).toBe("gpu"); expect(resolveHftPipelineDevice(undefined)).toBeUndefined(); diff --git a/providers/huggingface-transformers/src/ai/common/HFT_Device.ts b/providers/huggingface-transformers/src/ai/common/HFT_Device.ts index 31f1f87f3..06994a181 100644 --- a/providers/huggingface-transformers/src/ai/common/HFT_Device.ts +++ b/providers/huggingface-transformers/src/ai/common/HFT_Device.ts @@ -18,7 +18,7 @@ export function isHftBrowserEnv(): boolean { * Browser builds only accept `wasm` or `webgpu`; `auto` is our cross-platform * stored default, and should prefer WebGPU in the browser. */ -export function resolveHftPipelineDevice(raw: string | undefined): string { +export function resolveHftPipelineDevice(raw: string | undefined): string | undefined { if (isHftBrowserEnv()) { if (raw === "gpu") return "webgpu"; if (raw === "cpu") return "wasm"; @@ -27,7 +27,10 @@ export function resolveHftPipelineDevice(raw: string | undefined): string { return raw; } - // On the server, let transformers.js/onnxruntime-node choose the best EP. - if (raw === "wasm" || raw === "webgpu") return "auto"; - return raw || "auto"; + // On the server, resolve to undefined so onnxruntime-node defaults to the CPU + // execution provider instead of probing CUDA (which throws when the CUDA + // shared libraries are absent, e.g. CPU-only CI runners). "wasm"/"webgpu" are + // browser-only and stripped here as well. + if (!raw || raw === "auto" || raw === "wasm" || raw === "webgpu") return undefined; + return raw; }