Skip to content

Fix: Skip CPU provider in SetProviderSessionOptions - #2179

Merged
baijumeswani merged 4 commits into
microsoft:mainfrom
jiafatom:fix/skip-cpu-provider-append
Jun 9, 2026
Merged

Fix: Skip CPU provider in SetProviderSessionOptions#2179
baijumeswani merged 4 commits into
microsoft:mainfrom
jiafatom:fix/skip-cpu-provider-append

Conversation

@jiafatom

@jiafatom jiafatom commented May 22, 2026

Copy link
Copy Markdown
Contributor

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.cpp with a fallthrough path that passes unrecognized provider names to ORT's AppendExecutionProviderV1. ORT's strict whitelist (added in commit 4d03aeff0e) rejects cpu since 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:

  • If no provider options are set: skip silently (backward-compatible no-op)
  • If provider options are present: throw a clear error explaining that CPU EP does not support provider options and does not need explicit registration

This ensures:

  1. Existing code using append_provider('cpu') continues to work
  2. Misconfigurations (setting CPU provider options that would be silently lost) are caught early with a helpful error message

Testing

Added regression test TEST(CAPITests, AppendCpuProvider) that verifies cpu, CPU, and CPUExecutionProvider all succeed without error.

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>
@jiafatom
jiafatom requested a review from a team as a code owner May 22, 2026 20:04
Copilot AI review requested due to automatic review settings May 22, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 iterating providers_list in SetProviderSessionOptions.
  • Avoids propagating CPU provider names into ORT’s EP-append APIs (V1/V2 paths), preventing “Unknown provider name 'CPU'” runtime errors on newer ORT.

Comment thread src/models/session_options.cpp Outdated
Comment thread src/models/session_options.cpp Outdated
jiafatom and others added 2 commits May 22, 2026 13:15
- 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>
Comment thread src/models/session_options.cpp
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>
@jiafatom
jiafatom requested a review from baijumeswani May 22, 2026 23:30
@baijumeswani
baijumeswani merged commit 5d8b46e into microsoft:main Jun 9, 2026
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants