feat: auto-select ONNX execution providers with CPU-safe fallback#606
Draft
j-sperling wants to merge 2 commits into
Draft
feat: auto-select ONNX execution providers with CPU-safe fallback#606j-sperling wants to merge 2 commits into
j-sperling wants to merge 2 commits into
Conversation
InferenceSession was constructed without a providers argument, which pins inference to CPUExecutionProvider even on CUDA builds. Select providers explicitly: CUDA when available, CPU always appended as the final fallback, and retry CPU-only if accelerator session creation fails. Selection is an allowlist, not get_available_providers() order: the stock macOS wheel exposes AzureExecutionProvider, which must never be picked implicitly for a local zero-config path. CoreML is opt-in only via the providers argument -- on the default int8 bge-m3 export CoreML places 1490/2384 nodes across 220 partitions and measured ~60x slower than plain CPU from partition copy overhead.
Both fallback paths were silent: a requested-but-unavailable provider was filtered out, and a failed accelerator session quietly retried CPU-only. A user who thinks they are on CUDA could be on CPU with no signal.
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
OnnxEmbeddingbuilds itsInferenceSessionwithout aprovidersargument, pinning inference to CPU even on CUDA builds of onnxruntime. This selects providers explicitly: CUDA auto-selected when available, CPU always appended as the final fallback, plus a CPU-only retry if accelerator session creation fails.get_available_providers()order: the stock macOS wheel exposesAzureExecutionProvider(remote), which should never be picked implicitly for a local zero-config embedding path.providers=argument), based on measurement rather than assumption: on the defaultgpahal/bge-m3-onnx-int8export, CoreML places only 1490/2384 graph nodes across 220 partitions, and the CPU<->CoreML copy overhead measured ~60x slower than plain CPU (407.7s vs 6.6s for 64 texts, Apple M-series). Draft in part to surface this trade-off for discussion.Test plan
tests/test_embeddings_onnx_providers.py: pure-function coverage for auto-selection (CUDA picked, CoreML/Azure not auto-picked, CPU-only runtime, explicit-request filtering, CPU always appended)ruff check/ruff format --checkclean