Skip to content

fix(onnx): recover the backend when a model fails to load on GPU - #4

Merged
isixe merged 1 commit into
mainfrom
fix/onnx-backend-fallback
Nov 11, 2026
Merged

isixe merged 1 commit into
mainfrom
fix/onnx-backend-fallback

Conversation

@isixe

@isixe isixe commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes cases where loading / first-running a model could leave the ONNX backend stuck or permanently dropped on GPU.

Root causes

  • runInferenceWithFallback only fell back to WASM on a narrow 'device lost' error pattern. Other WebGPU failures (shader compile, GPU OOM, validation) left the broken GPU session cached, so every later task reused it and never degraded to WASM.
  • gpuFailed latched for the worker's whole lifetime: one transient GPU failure during model load disabled GPU until the user toggled the setting off/on.

Changes

  • Rebuild and fall back to WASM on any GPU inference failure, and remember the failing model so a different model retries GPU instead of staying latched.
  • Mark GPU as failed on fatal GPU errors in handleTask.
  • Aggregate GPU status per worker slot to avoid last-writer-wins flapping between workers.
  • Dispose the worker pool on unmount (previously only cancelAll) and unload idle sessions on model switch, releasing workers and their GPU devices.
  • Await the shared model buffer before preloading/dispatching so workers do not fall back to a redundant per-worker fetch.
  • Reset the per-model memory budget when the active model changes.

Verification

  • pnpm type-check: clean
  • pnpm build: succeeds
  • prettier check + eslint on changed files: clean

- rebuild and fall back to WASM on any GPU inference failure, not only device-lost errors, so a broken GPU session is no longer reused for every later task

- remember which model failed so switching models retries GPU instead of latching it off for the whole worker session

- aggregate GPU status per worker slot to stop last-writer-wins flapping across workers

- dispose the worker pool on unmount and unload idle sessions on model switch so workers and their GPU devices are released

- await the shared model buffer before preloading or dispatching tasks to avoid a redundant per-worker fetch

- reset the per-model byte budget when the active model changes instead of keeping the largest model seen
@netlify

netlify Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for bg-x ready!

Name Link
🔨 Latest commit 45eeb74
🔍 Latest deploy log https://app.netlify.com/projects/bg-x/deploys/6af40263be5840b641e1a06c
😎 Deploy Preview https://deploy-preview-4--bg-x.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@isixe
isixe merged commit a9aced0 into main Nov 11, 2026
5 checks passed
@isixe
isixe deleted the fix/onnx-backend-fallback branch November 11, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant