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
4 changes: 2 additions & 2 deletions packages/test/src/test/ai-provider-hft/HFT_Device.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions providers/huggingface-transformers/src/ai/common/HFT_Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}
Loading