Skip to content

Fix CUDA EP provider_options and use float masks for fallback layers - #255

Closed
justinchuby wants to merge 2 commits into
mainfrom
fix-cuda-provider-options
Closed

Fix CUDA EP provider_options and use float masks for fallback layers#255
justinchuby wants to merge 2 commits into
mainfrom
fix-cuda-provider-options

Conversation

@justinchuby

Copy link
Copy Markdown
Member
  1. Remove CUDA provider_options from EP defaults — explicit options conflict with GenAI's internal session setup, causing NaN. 2. Use float16 additive masks for all fallback Attention layers instead of bool masks (more robust on CUDA). 3. Return empty provider_options list when no options needed.

Two fixes for Gemma4 CUDA EP inference:

1. Remove CUDA provider_options from EP defaults. Explicit CUDA
   provider_options in genai_config.json conflict with GenAI's
   internal session setup (ClearOutput, ReuseEmbeddingsBuffer, etc.),
   causing NaN or crashes for multimodal CUDA models. GenAI's C++
   code handles all CUDA EP configuration internally.

2. Use float16 additive masks for all fallback Attention layers
   (KV-shared and head_dim>256 layers) instead of bool masks. Bool
   masks triggered NaN in ORT's CUDA ConvertAttnMaskToBias path.
   Float16 masks match the working default EP model's behavior.

Tested: CUDA EP model (12 GQA + 23 Attention) generates at 13.5 tok/s
through GenAI with valid output.

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 0d8a6358ef2517

Model Sub-model Changes Status
gemma4 (gemma4) decoder 0
gemma4 (gemma4) embedding 0
gemma4 (gemma4) vision_encoder 0
gemma4_text model 0

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 0d8a6358ef2517

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

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: Justin Chu <justinchu@microsoft.com>
@titaiwangms

Copy link
Copy Markdown
Contributor

This PR is superseded by #262, which goes further by omitting masks entirely for full-attention layers (enabling MEA for head_dim=512) and switching sliding-window to float additive bias. The provider_options fix in this PR is also included in #262.

Recommend closing in favor of #262.

@justinchuby

Copy link
Copy Markdown
Member Author

Closing: this PR is superseded by other changes:

  1. CUDA provider_options removal (changes 1 & 2): This was found to be incorrect — GenAI derives its providers list from provider_options names (config.cpp:1763). Empty provider_options means CPU-only. The correct fix is [{"cuda": {}}], which is already on main via PR Fix genai_config.json provider names to use short format #247.

  2. Float masks for fallback attention (change 3): Superseded by PR Omit mask for full_attention layers to enable MEA for head_dim=512 #262 which goes further — omits the mask entirely for full_attention layers to enable MEA (CUTLASS FMHA) for head_dim=512.

Relevant PRs:

@justinchuby justinchuby closed this May 5, 2026
@justinchuby
justinchuby deleted the fix-cuda-provider-options branch May 7, 2026 01:02
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