feat: export deviceToExecutionProviders and getSupportedDevices#1646
Open
TimPietrusky wants to merge 1 commit intohuggingface:mainfrom
Open
feat: export deviceToExecutionProviders and getSupportedDevices#1646TimPietrusky wants to merge 1 commit intohuggingface:mainfrom
TimPietrusky wants to merge 1 commit intohuggingface:mainfrom
Conversation
Export two device utility functions from the public API: - `deviceToExecutionProviders(device)` — maps a device string to the ONNX execution providers list (already existed internally) - `getSupportedDevices()` — returns the platform-specific supported devices array in priority order (new convenience wrapper) This lets downstream libraries implement their own device fallback logic without hardcoding platform-specific device lists. Closes huggingface#1645
4 tasks
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Export two device utility functions from the public API so downstream libraries can implement their own device fallback logic:
deviceToExecutionProviders(device)— maps a device string (e.g."auto","cuda","cpu") to the corresponding ONNX execution providers list. Already existed internally, just not re-exported.getSupportedDevices()— returns a copy of the platform-specificsupportedDevicesarray in priority order (e.g.["cuda", "webgpu", "cpu"]on Linux x64,["coreml", "webgpu", "cpu"]on macOS).Why
When
device="auto"and a provider crashes hard (e.g. CUDA whenlibcudnn.sois missing — see #1642), downstream code needs to retry providers individually. Without access to the device list, libraries have to hardcode their own copy of the platform detection logic, which drifts when transformers.js updates.Example usage
Changes
src/backends/onnx.js: addedgetSupportedDevices()functionsrc/transformers.js: re-exporteddeviceToExecutionProvidersandgetSupportedDevicesCloses #1645