Skip to content

Lower opset 24→23 for non-default EPs to eliminate memcpy - #254

Merged
justinchuby merged 3 commits into
mainfrom
fix-opset-lowering
May 6, 2026
Merged

Lower opset 24→23 for non-default EPs to eliminate memcpy#254
justinchuby merged 3 commits into
mainfrom
fix-opset-lowering

Conversation

@justinchuby

Copy link
Copy Markdown
Member

ORT CUDA EP registers kernels up to opset 23. Opset 24 models have Reshape/Cast fall to CPU → 280 memcpy. Wire up the ort_lower_opset_for_ep flag to lower opset after optimization. Result: 282→4 memcpy. Workaround until ORT PR #28368 adds opset 24 registrations.

ORT's CUDA EP registers kernels up to opset 23 for standard ops
(Reshape, RMSNormalization, etc.). When the model declares opset 24,
these ops fall to CPUExecutionProvider, creating ~280 MemcpyFromHost
and MemcpyToHost nodes that destroy inference performance.

This implements the ort_lower_opset_for_ep flag (which was declared
in _flags.py but never wired up). When enabled (default), the opset
is lowered from 24 to 23 for all non-default EPs after optimization.

Result: 282 memcpy → 4 memcpy for Gemma4 CUDA EP model.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 0d8a635b3a9548

Model Sub-model Changes Status

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 0d8a635b3a9548

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 60 60 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 107 107 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 53 53 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 61 61 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 58 58 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 98 98 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 59 59 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 56 56 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 61 61 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 58 58 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 408 408 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 166 166 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mobius/_builder.py 85.71% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@titaiwangms titaiwangms 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.

It would be better when this trigger, it sends a message to users to remind us of adding opset to ort.

Address review feedback: log an info message with the original opset,
model name, EP, and a link to the ORT tracking PR when opset lowering
is triggered. This helps users understand the workaround and track
when it can be removed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@justinchuby

Copy link
Copy Markdown
Member Author

Addressed the feedback — added an INFO log message when opset lowering triggers. It now logs the original opset, model name, EP, and links to the ORT tracking PR (microsoft/onnxruntime#28368) so users know the workaround and when it can be removed.

Commit: 69fc529

Comment thread src/mobius/_builder.py Outdated
Comment thread src/mobius/_builder.py Outdated
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby merged commit 496d261 into main May 6, 2026
16 of 18 checks passed
@justinchuby
justinchuby deleted the fix-opset-lowering branch May 6, 2026 14:09
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.

2 participants