Feature request
deviceToExecutionProviders() and the supportedDevices array in src/backends/onnx.js are currently internal. Exporting them from the public API would let downstream libraries implement their own device fallback logic without hardcoding platform-specific device lists.
Why this is needed
When device="auto" is used, transformers.js passes the full supportedDevices array (e.g. ['cuda', 'webgpu', 'cpu'] on Linux x64) to InferenceSession.create(). If a provider fails hard — such as CUDA when libcudnn.so is missing — onnxruntime-node crashes instead of falling through to the next provider (see #1642).
To work around this, libraries like wandler need to try each device individually and catch failures. But there's no way to get the platform-specific device list from transformers.js — deviceToExecutionProviders and supportedDevices aren't exported. This forces us to hardcode our own copy of the platform detection logic, which drifts when transformers.js adds new providers or changes the ordering.
Proposed change
Export deviceToExecutionProviders (and optionally supportedDevices) from the package's public API so consumers can call:
import { deviceToExecutionProviders } from '@huggingface/transformers';
const devices = deviceToExecutionProviders('auto');
// e.g. ['cuda', 'webgpu', 'cpu'] on Linux x64
// e.g. ['coreml', 'webgpu', 'cpu'] on macOS
This would allow downstream code to implement per-device retry/fallback without duplicating platform detection logic.
Relationship to #1642
Issue #1642 tracks the root cause (onnxruntime crashing instead of falling back). Even if that gets fixed inside transformers.js or onnxruntime, exporting the device list is independently useful — it lets consumers make informed decisions about device selection, logging, and error handling.
Feature request
deviceToExecutionProviders()and thesupportedDevicesarray insrc/backends/onnx.jsare currently internal. Exporting them from the public API would let downstream libraries implement their own device fallback logic without hardcoding platform-specific device lists.Why this is needed
When
device="auto"is used, transformers.js passes the fullsupportedDevicesarray (e.g.['cuda', 'webgpu', 'cpu']on Linux x64) toInferenceSession.create(). If a provider fails hard — such as CUDA whenlibcudnn.sois missing — onnxruntime-node crashes instead of falling through to the next provider (see #1642).To work around this, libraries like wandler need to try each device individually and catch failures. But there's no way to get the platform-specific device list from transformers.js —
deviceToExecutionProvidersandsupportedDevicesaren't exported. This forces us to hardcode our own copy of the platform detection logic, which drifts when transformers.js adds new providers or changes the ordering.Proposed change
Export
deviceToExecutionProviders(and optionallysupportedDevices) from the package's public API so consumers can call:This would allow downstream code to implement per-device retry/fallback without duplicating platform detection logic.
Relationship to #1642
Issue #1642 tracks the root cause (onnxruntime crashing instead of falling back). Even if that gets fixed inside transformers.js or onnxruntime, exporting the device list is independently useful — it lets consumers make informed decisions about device selection, logging, and error handling.