Optimize max peak memory usage and add warnings on mobile for higher models
This commit is contained in:
1 parent
f6019b3a42
commit
a0ef5548af
10 files changed
+428
-7
No files matched your search
@@ -5,6 +5,7 @@ import {
|
||||
WHISPER_LANGUAGES,
|
||||
estimateDefaultDownloadBytes,
|
||||
estimateDownloadBytes,
|
||||
estimatePeakLoadBytes,
|
||||
formatModelSize,
|
||||
getFasterWhisperModel,
|
||||
getModel,
|
||||
@@ -163,6 +164,38 @@ describe("size estimates", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("estimatePeakLoadBytes (D-027)", () => {
|
||||
const medium = getModel("onnx-community/whisper-medium-ONNX")!;
|
||||
const turbo = getModel("onnx-community/whisper-large-v3-turbo")!;
|
||||
|
||||
test("is ~2x the larger of the two weight files, not their sum", () => {
|
||||
const dtype = resolveDefaultDtype(medium.id, "wasm"); // q4
|
||||
const peak = estimatePeakLoadBytes(medium, dtype);
|
||||
const download = estimateDownloadBytes(medium, dtype);
|
||||
// The combined download sums both files; the peak only doubles the
|
||||
// larger one — smaller than 2x the sum, but bigger than the sum alone
|
||||
// once the sequential-load patch keeps only one file resident at a time.
|
||||
expect(peak).toBeLessThan(2 * download);
|
||||
expect(peak).toBeGreaterThan(download);
|
||||
});
|
||||
|
||||
test("mixed per-part dtypes (fp16 encoder + q4 decoder) peak on the larger encoder", () => {
|
||||
const dtype = resolveDefaultDtype(turbo.id, "webgpu"); // fp16 encoder, q4 decoder
|
||||
const peak = estimatePeakLoadBytes(turbo, dtype);
|
||||
// large-v3-turbo's encoder (635M) dwarfs its decoder (174M) even before
|
||||
// fp16 vs q4 is factored in, so the encoder alone should set the peak.
|
||||
const encoderOnlyPeak = 2 * turbo.encoderParamsM * 1e6 * 2; // fp16 = 2 bytes/param
|
||||
expect(peak).toBeCloseTo(encoderOnlyPeak, -5);
|
||||
});
|
||||
|
||||
test("scales up with a larger model at the same dtype", () => {
|
||||
const tiny = getModel("onnx-community/whisper-tiny.en")!;
|
||||
expect(estimatePeakLoadBytes(medium, "q4")).toBeGreaterThan(
|
||||
estimatePeakLoadBytes(tiny, "q4"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("WHISPER_LANGUAGES", () => {
|
||||
test("codes are unique, lowercase, and include common languages", () => {
|
||||
const codes = WHISPER_LANGUAGES.map((entry) => entry.code);
|
||||
|
||||
Reference in new issue
Block a user