fix: remove webgl backend, add preflight capability check for transformers.js v4.x - #61
Conversation
…light capability check Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
|
@copilot E2E testing is failing now... 2026-03-20T17:05:03.0527838Z ##[group]Run bun run test 2026-03-20T17:05:18.6029764Z error: script "test" exited with code 1 |
…reflight check Co-authored-by: devlux76 <86517969+devlux76@users.noreply.github.com>
Fixed in b0851c0. The Fix: extracted a |
There was a problem hiding this comment.
Pull request overview
This PR updates the worker’s backend selection to match transformers.js@next (v4.x) by removing the invalid webgl device, and adds a synchronous preflight capability check to skip unreachable backends before any model download begins.
Changes:
- Removed
webglfromBackendName/DEVICE_PRIORITYand updated iOS fallback towasmonly. - Added
probeAvailableDevices()and wired it intoloadModel()to filter backends vianavigator.gpu/navigator.mlpresence checks. - Updated/added E2E tests and documentation to reflect the new backend list and preflight behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/worker.ts |
Removes webgl backend and adds preflight backend filtering before attempting pipeline() loads. |
test/worker.e2e.test.ts |
Adds navigator API stubbing helper for jsdom, updates backend assertions, and adds a webgl regression test. |
docs/CODE_DOCUMENTATION.md |
Documents updated DEVICE_PRIORITY and the new probeAvailableDevices() preflight step. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
webglis not a valid device in transformers.js@next (v4.x) — passing it throws"Unsupported device: 'webgl'. Should be one of: webnn-npu, webnn-gpu, webnn-cpu, webnn, webgpu, wasm."at ONNX session init time, after a multi-GB download completes. This caused the entire backend fallback chain to fail in the user's browser.Core fix
webglfromBackendNameandDEVICE_PRIORITY. Non-iOS:['webnn', 'webgpu', 'wasm']; iOS:['wasm'].Preflight capability check
New
probeAvailableDevices()runs synchronously before any network request, filtering out backends whose browser API is absent:loadModel()now iteratesprobeAvailableDevices(DEVICE_PRIORITY)instead of the raw priority list — so a browser without WebGPU/WebNN skips those backends immediately rather than downloading the model first.Tests
webglremoved).'load: pipeline is never called with device=webgl'— records every device passed to the pipeline factory and assertswebglnever appears.Original prompt
This section details on the original issue you should resolve
<issue_title>Please read the docs for transformers@next</issue_title>
<issue_description>This is entirely too trivial to be the entire problem. I'd like you to read the docs for transformers.js@next and go over the entire codebase with a fine toothed comb because this error seems impossible to me if the entire codeback was brought up to transformersjs@next