From cffc6b79e75063f139ce1eccefb9d4bdfb3550fb Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Jun 2026 08:22:46 +0000 Subject: [PATCH] fix(huggingface-transformers): align HFT_Device tests with auto-resolve semantics The HFT_Device unit tests asserted that resolveHftPipelineDevice returns undefined on the server for missing/browser-only inputs, but the source deliberately normalizes those inputs to "auto" so transformers.js delegates EP selection to onnxruntime-node. The tests were carried over from the deleted HFT_Pipeline.ts and never updated; downstream builder/main (commit dd2acdc, "webgpu" -> "auto") confirms the auto-resolve path is the intended runtime behavior. - Update HFT_Device.test.ts to expect "auto" for undefined / wasm / webgpu on the server, matching source. - Rename the second case to "normalizes browser-only devices to auto on the server" to reflect the new assertions. - Add a JSDoc note on resolveHftPipelineDevice explaining the server normalization to "auto" and the onnxruntime-node EP delegation. Co-Authored-By: Claude --- packages/test/src/test/ai-provider-hft/HFT_Device.test.ts | 8 ++++---- .../huggingface-transformers/src/ai/common/HFT_Device.ts | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) 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..19525c474 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 @@ -22,12 +22,12 @@ describe("resolveHftPipelineDevice", () => { expect(resolveHftPipelineDevice("auto")).toBe("auto"); expect(resolveHftPipelineDevice("cpu")).toBe("cpu"); expect(resolveHftPipelineDevice("gpu")).toBe("gpu"); - expect(resolveHftPipelineDevice(undefined)).toBeUndefined(); + expect(resolveHftPipelineDevice(undefined)).toBe("auto"); }); - it("strips browser-only devices on the server", () => { - expect(resolveHftPipelineDevice("webgpu")).toBeUndefined(); - expect(resolveHftPipelineDevice("wasm")).toBeUndefined(); + it("normalizes browser-only devices to auto on the server", () => { + expect(resolveHftPipelineDevice("webgpu")).toBe("auto"); + expect(resolveHftPipelineDevice("wasm")).toBe("auto"); }); it("defaults auto to WebGPU in the browser", () => { diff --git a/providers/huggingface-transformers/src/ai/common/HFT_Device.ts b/providers/huggingface-transformers/src/ai/common/HFT_Device.ts index 31f1f87f3..a13385d6c 100644 --- a/providers/huggingface-transformers/src/ai/common/HFT_Device.ts +++ b/providers/huggingface-transformers/src/ai/common/HFT_Device.ts @@ -16,7 +16,9 @@ export function isHftBrowserEnv(): boolean { * Resolve the stored high-level HFT device into the concrete value passed to transformers.js. * * Browser builds only accept `wasm` or `webgpu`; `auto` is our cross-platform - * stored default, and should prefer WebGPU in the browser. + * stored default, and should prefer WebGPU in the browser. On the server, + * missing/browser-only inputs normalize to `"auto"`, which transformers.js + * delegates to onnxruntime-node for EP auto-selection. */ export function resolveHftPipelineDevice(raw: string | undefined): string { if (isHftBrowserEnv()) {