Fix: Skip CPU provider in SetProviderSessionOptions - #2179
Merged
baijumeswani merged 4 commits intoJun 9, 2026
Conversation
CPU EP is always implicitly registered in ORT sessions. Passing 'cpu' to ORT's SessionOptionsAppendExecutionProvider causes a RuntimeError in ORT 1.24+ which introduced a strict provider name whitelist that does not include CPU (#24433). Previously this worked because older ORT versions silently ignored unknown provider names. With ORT 1.24+, explicitly appending 'cpu' now fails with 'Unknown provider name'. The fix skips CPU/cpu/CPUExecutionProvider in the provider iteration loop since it never needs to be explicitly appended. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents ONNX Runtime GenAI from explicitly appending the CPU Execution Provider in SetProviderSessionOptions, avoiding failures on ORT 1.24+ where SessionOptionsAppendExecutionProvider enforces a strict provider-name whitelist that excludes CPU.
Changes:
- Skip
"cpu","CPU", and"CPUExecutionProvider"entries while iteratingproviders_listinSetProviderSessionOptions. - Avoids propagating CPU provider names into ORT’s EP-append APIs (V1/V2 paths), preventing “Unknown provider name 'CPU'” runtime errors on newer ORT.
- Use case-insensitive comparison for CPU provider name detection (handles 'cpu', 'CPU', 'Cpu', 'cpuexecutionprovider', etc.) - Add regression test in c_api_tests.cpp that verifies appending CPU provider variants does not throw Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address reviewer concern: instead of silently skipping CPU with provider options (which would be lost), throw a clear error message explaining that CPU EP doesn't support provider options and doesn't need explicit registration. Bare 'cpu' with no options is still accepted as a no-op for backward compatibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per reviewer feedback, instead of special-case inline logic: - Add 'cpu'/'cpuexecutionprovider' -> 'CPU' mapping to NormalizeProviderName - Register CPUAppendExecutionProvider as a no-op lambda in the dispatch table - Remove inline case-insensitive skip block and unnecessary <cctype> include This follows the existing provider registration pattern. The lambda still throws if provider options are set (CPU EP doesn't support them). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
baijumeswani
approved these changes
Jun 9, 2026
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.
Fix: Skip CPU provider in SetProviderSessionOptions
Problem
When users call
config.append_provider('cpu'), onnxruntime-genai 0.13.x throws:RuntimeError: [ErrorCode:InvalidArgument] Unknown provider name 'cpu'. Possible options: ...This worked in v0.12.1 but regressed in v0.13.1.
Root Cause
PR #2038 (Decouple plugin execution providers from USE_WINML, March 2026) introduced
src/models/session_options.cppwith a fallthrough path that passes unrecognized provider names to ORT'sAppendExecutionProviderV1. ORT's strict whitelist (added in commit4d03aeff0e) rejectscpusince CPU EP is always implicitly registered and never needs an explicit append call.Fix
In
SetProviderSessionOptions, detect CPU provider names (case-insensitive:cpu,cpuexecutionprovider) and:This ensures:
append_provider('cpu')continues to workTesting
Added regression test
TEST(CAPITests, AppendCpuProvider)that verifiescpu,CPU, andCPUExecutionProviderall succeed without error.