can1357/oh-my-pi · error · Error

Unsupported PI_TINY_DEVICE=${JSON.stringify(value)}. Use cpu

Error message

Unsupported PI_TINY_DEVICE=${JSON.stringify(value)}. Use cpu, gpu, metal, webgpu, auto, cuda, dml, coreml, wasm, webnn, webnn-gpu, webnn-cpu, or webnn-npu.

What it means

normalizeTinyModelDevice validates the PI_TINY_DEVICE environment variable against the known device-value set (mapping `metal` -> `webgpu` as an alias). Any non-empty value not in the set throws immediately rather than silently falling back, since a wrong device choice would silently degrade tiny-model inference.

Source

Thrown at packages/coding-agent/src/tiny/device.ts:39

	cuda: true,
	dml: true,
	coreml: true,
	webnn: true,
	"webnn-npu": true,
	"webnn-gpu": true,
	"webnn-cpu": true,
};

function usesDarwinWorkerWebGpu(device: TinyModelDevice): boolean {
	return process.platform === "darwin" && (device === "gpu" || device === "webgpu" || device === "auto");
}

export function normalizeTinyModelDevice(value: string | undefined): TinyModelDevice | undefined {
	const raw = value?.trim().toLowerCase();
	if (!raw) return undefined;
	if (raw === "metal") return "webgpu";
	if (raw in DEVICE_VALUES) return raw as TinyModelDevice;
	throw new Error(
		`Unsupported PI_TINY_DEVICE=${JSON.stringify(value)}. Use cpu, gpu, metal, webgpu, auto, cuda, dml, coreml, wasm, webnn, webnn-gpu, webnn-cpu, or webnn-npu.`,
	);
}

export function resolveTinyModelDevicePreference(
	value: string | undefined = $env.PI_TINY_DEVICE,
): TinyModelDevicePreference {
	return {
		device: normalizeTinyModelDevice(value) ?? CPU_DEVICE,
		raw: value,
	};
}

export function tinyModelDeviceLoadOrder(preference: TinyModelDevicePreference): readonly TinyModelDevice[] {
	if (preference.device === CPU_DEVICE) return CPU_ONLY_ORDER;
	if (usesDarwinWorkerWebGpu(preference.device)) return DARWIN_WEBGPU_UNSAFE_ORDER;
	return [preference.device, CPU_DEVICE];
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Set PI_TINY_DEVICE to one of: cpu, gpu, metal, webgpu, auto, cuda, dml, coreml, wasm, webnn, webnn-gpu, webnn-cpu, webnn-npu
  2. Use `auto` to let the runtime pick the best device
  3. Unset PI_TINY_DEVICE entirely to use the per-model default

Example fix

// before
export PI_TINY_DEVICE=vulkan
// after
export PI_TINY_DEVICE=cuda
Defensive patterns

Strategy: validation

Validate before calling

const DEVICES = ["cpu","gpu","metal","webgpu","auto","cuda","dml","coreml","wasm","webnn","webnn-gpu","webnn-cpu","webnn-npu"];
const v = process.env.PI_TINY_DEVICE?.trim().toLowerCase();
if (v && !DEVICES.includes(v)) throw new Error(`PI_TINY_DEVICE must be one of ${DEVICES.join(", ")}`);

Try / catch

try {
	const device = normalizeTinyModelDevice(process.env.PI_TINY_DEVICE);
} catch (err) {
	logger.warn("Invalid PI_TINY_DEVICE, falling back to auto", { value: process.env.PI_TINY_DEVICE });
	return "auto";
}

Prevention

When it happens

Trigger: Setting PI_TINY_DEVICE to a typo'd or unsupported value (e.g. `GPU0`, `vulkan`, `Metal ` with trailing chars handled, `cpu,gpu`) and then resolving the tiny model device preference.

Common situations: Copying device names from ONNX Runtime docs that omp doesn't expose (vulkan, coreml variants); casing/typo mistakes like `CUDA` vs `cuda` (case is normalized, but spelling must match); stale values from another tool's env.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/71089937ae0e09cc. Report an issue: GitHub.