Prefer WASM on firefox cause WebGPU is incredibly slow there.
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, test, expect } from "bun:test";
|
||||
import {
|
||||
applyLoadProgress,
|
||||
deviceAttempts,
|
||||
dtypeRequiresF16,
|
||||
initialLoadProgress,
|
||||
isUiToWorkerMessage,
|
||||
isWorkerToUiMessage,
|
||||
@@ -83,7 +84,9 @@ describe("isWorkerToUiMessage", () => {
|
||||
},
|
||||
{ type: "load-progress", status: "done", file: "model.onnx" },
|
||||
{ type: "load-progress", status: "ready", device: "wasm" },
|
||||
{ type: "load-progress", status: "ready", device: "wasm", threads: 11 },
|
||||
{ type: "load-progress", status: "ready", device: "webgpu" },
|
||||
{ type: "load-progress", status: "ready", device: "webgpu", threads: 1 },
|
||||
{ type: "partial", text: " hello" },
|
||||
{ type: "partial", text: " hello", requestId: "live-1" },
|
||||
{ type: "transcribe-progress", processedSeconds: 0, totalSeconds: 90 },
|
||||
@@ -92,6 +95,18 @@ describe("isWorkerToUiMessage", () => {
|
||||
{ type: "result", text: "hello world", chunks: [], requestId: "live-1" },
|
||||
{ type: "error", stage: "load", message: "boom" },
|
||||
{ type: "error", stage: "transcribe", message: "boom", requestId: "live-2" },
|
||||
{
|
||||
type: "load-restart",
|
||||
modelId: "onnx-community/whisper-medium-ONNX",
|
||||
preference: "auto",
|
||||
device: "wasm",
|
||||
},
|
||||
{
|
||||
type: "load-restart",
|
||||
modelId: "onnx-community/whisper-tiny.en",
|
||||
preference: "webgpu",
|
||||
device: "wasm",
|
||||
},
|
||||
];
|
||||
for (const message of messages) {
|
||||
expect(isWorkerToUiMessage(message)).toBe(true);
|
||||
@@ -104,6 +119,9 @@ describe("isWorkerToUiMessage", () => {
|
||||
expect(isWorkerToUiMessage({ type: "load-progress", status: "progress", file: "f" })).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "load-progress", status: "ready" })).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "load-progress", status: "ready", device: "cuda" })).toBe(false);
|
||||
expect(
|
||||
isWorkerToUiMessage({ type: "load-progress", status: "ready", device: "wasm", threads: "12" }),
|
||||
).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "partial" })).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "partial", text: "x", requestId: 1 })).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "transcribe-progress", processedSeconds: 1 })).toBe(false);
|
||||
@@ -121,6 +139,37 @@ describe("isWorkerToUiMessage", () => {
|
||||
expect(isWorkerToUiMessage({ type: "result", text: "x", chunks: "nope" })).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "error", stage: "decode", message: "m" })).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "load", modelId: "x", device: "wasm" })).toBe(false);
|
||||
expect(isWorkerToUiMessage({ type: "load-restart", modelId: "x" })).toBe(false);
|
||||
expect(
|
||||
isWorkerToUiMessage({ type: "load-restart", modelId: "x", preference: "auto", device: "auto" }),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isWorkerToUiMessage({ type: "load-restart", preference: "auto", device: "wasm" }),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dtypeRequiresF16 (D-025)", () => {
|
||||
test("plain dtypes: only fp16 needs the shader-f16 feature", () => {
|
||||
expect(dtypeRequiresF16("fp16")).toBe(true);
|
||||
expect(dtypeRequiresF16("fp32")).toBe(false);
|
||||
expect(dtypeRequiresF16("q8")).toBe(false);
|
||||
expect(dtypeRequiresF16("q4")).toBe(false);
|
||||
});
|
||||
|
||||
test("per-part dtypes: fp16 in either part needs it", () => {
|
||||
expect(
|
||||
dtypeRequiresF16({ encoder_model: "fp16", decoder_model_merged: "q4" }),
|
||||
).toBe(true);
|
||||
expect(
|
||||
dtypeRequiresF16({ encoder_model: "fp32", decoder_model_merged: "fp16" }),
|
||||
).toBe(true);
|
||||
expect(
|
||||
dtypeRequiresF16({ encoder_model: "fp32", decoder_model_merged: "fp32" }),
|
||||
).toBe(false);
|
||||
expect(
|
||||
dtypeRequiresF16({ encoder_model: "fp32", decoder_model_merged: "q4" }),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user