Files
oh-my-pi/packages/coding-agent/test/tiny-device.test.ts
T
can1357 5d3adfab7f feat(tiny): added GPU-first device selection with CPU fallback for local models
- Added `PI_TINY_DEVICE` env var to control ONNX execution provider (`gpu` default, `cpu`, `metal`, `cuda`, `dml`, `coreml`).
- Local tiny-model inference now tries accelerated GPU provider first and retries on CPU if initialization fails.
- Added `device.ts` module with normalization, preference resolution, and load-order helpers.
- Updated docs and model descriptions to drop CPU-specific language.
2026-05-31 01:57:59 +02:00

43 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import {
normalizeTinyModelDevice,
resolveTinyModelDevicePreference,
tinyModelDeviceLoadOrder,
type TinyModelDevice,
} from "../src/tiny/device";
function expectedDefaultDevice(): TinyModelDevice {
if (process.platform === "win32") return "dml";
if (process.platform === "linux" && process.arch === "x64") return "cuda";
return "cpu";
}
describe("tiny model device selection", () => {
it("defaults to the worker-safe accelerated provider for the platform", () => {
const preference = resolveTinyModelDevicePreference(undefined);
const expected = expectedDefaultDevice();
const expectedOrder: readonly TinyModelDevice[] = expected === "cpu" ? ["cpu"] : [expected, "cpu"];
expect(preference.device).toBe(expected);
expect(tinyModelDeviceLoadOrder(preference)).toEqual(expectedOrder);
});
it("accepts metal as a WebGPU alias without enabling unsafe macOS worker teardown", () => {
const expectedOrder: readonly TinyModelDevice[] = process.platform === "darwin" ? ["cpu"] : ["webgpu", "cpu"];
expect(normalizeTinyModelDevice("metal")).toBe("webgpu");
expect(tinyModelDeviceLoadOrder(resolveTinyModelDevicePreference("metal"))).toEqual(expectedOrder);
});
it("keeps explicit CPU runs CPU-only", () => {
const preference = resolveTinyModelDevicePreference(" cpu ");
expect(preference.device).toBe("cpu");
expect(tinyModelDeviceLoadOrder(preference)).toEqual(["cpu"]);
});
it("rejects unknown ONNX execution providers", () => {
expect(() => resolveTinyModelDevicePreference("neural-magic")).toThrow("Unsupported PI_TINY_DEVICE");
});
});