Fixed for decoder dl speed and mobile warnings on low memory devices.

This commit is contained in:
Lucas Winther
2026-07-29 07:47:42 +02:00
parent 2643a446d0
commit 78e99fc415
7 changed files with 208 additions and 32 deletions
+32 -8
View File
@@ -1,8 +1,11 @@
diff --git a/node_modules/@huggingface/transformers/.bun-tag-8719566ebeed846f b/.bun-tag-8719566ebeed846f
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/dist/transformers.web.js b/dist/transformers.web.js
index bb7b32717a42475a5f66411a33d5e5964dfda3e2..799cb402e98d8d0d58bf59629c4c2992407477e0 100644
index bb7b32717a42475a5f66411a33d5e5964dfda3e2..03de63967e99f8f3c847858621d72577ef037391 100644
--- a/dist/transformers.web.js
+++ b/dist/transformers.web.js
@@ -18558,22 +18558,28 @@ async function getSession(pretrained_model_name_or_path, fileName, options, cach
@@ -18558,22 +18558,49 @@ async function getSession(pretrained_model_name_or_path, fileName, options, cach
return { buffer_or_path, session_options, session_config };
}
async function constructSessions(pretrained_model_name_or_path, names, options, cache_sessions = void 0) {
@@ -22,14 +25,35 @@ index bb7b32717a42475a5f66411a33d5e5964dfda3e2..799cb402e98d8d0d58bf59629c4c2992
- })
- )
- );
+ // Patched (au_whisper_web): load sub-model sessions one at a time instead of
+ // Promise.all-ing them. Each entry briefly holds a full-size decoded model
+ // buffer in JS-heap memory (on top of onnxruntime-web's own WASM-heap copy
+ // during session creation); loading Whisper's encoder and decoder
+ // Patched (au_whisper_web): each entry briefly holds a full-size decoded
+ // model buffer in JS-heap memory (on top of onnxruntime-web's own WASM-heap
+ // copy during session creation); loading Whisper's encoder and decoder
+ // concurrently keeps both buffers alive at once and roughly doubles the
+ // load-time memory peak, which is enough to OOM-crash mobile browsers on
+ // larger models (e.g. medium, ~460 MB combined). Sequential loading lets the
+ // previous entry's buffer become garbage before the next one is fetched.
+ // larger models (e.g. medium, ~460 MB combined). `options.sequentialSessionLoad`
+ // (set by the caller only when that risk is real, D-027/D-029) loads
+ // sub-model sessions one at a time instead of Promise.all-ing them, so the
+ // previous entry's buffer becomes garbage before the next one is fetched —
+ // at the cost of losing the download concurrency a fast connection could
+ // otherwise use, which is the default (and always was, pre-D-027).
+ if (!options?.sequentialSessionLoad) {
+ return Object.fromEntries(
+ await Promise.all(
+ Object.keys(names).map(async (name) => {
+ const cache_config = cache_sessions?.[name] ?? false;
+ const { buffer_or_path, session_options, session_config } = await getSession(
+ pretrained_model_name_or_path,
+ names[name],
+ options,
+ cache_config,
+ name
+ );
+ const session = await createInferenceSession(buffer_or_path, session_options, session_config);
+ return [name, session];
+ })
+ )
+ );
+ }
+ const entries = [];
+ for (const name of Object.keys(names)) {
+ const cache_config = cache_sessions?.[name] ?? false;