Skip to content

Conversation

@weiyuanyue
Copy link
Contributor

@weiyuanyue weiyuanyue commented Dec 3, 2025

AITK-converted NPU models were incorrectly tagged as CPU because the detection logic couldn't parse diverse execution provider configurations from genai_config.json.

Root Cause

The existing implementation had several limitations:

  • Rigid schema parsing: GenAIConfig.cs used fixed Dml and Cuda classes, unable to handle diverse execution providers (OpenVINO, VitisAI, QNN, etc.)
  • Incomplete provider scanning: Only checked decoder-level session options, missing pipeline-level provider configurations
  • Missing NPU detection: No runtime capability to verify if NPU hardware is actually available on the device

Before/After

Before: NPU model shows CPU tag

After: NPU model correctly tagged

Warning dialog for unavailable EPs:

Solution

This PR implements a comprehensive fix with 4 key improvements:

  1. Enhanced GenAI Config Parsing (GenAIConfig.cs)

    • Extended ProviderOptions class with flexible JSON extension data parsing to support various execution providers (DML, QNN, OpenVINO, VitisAI, etc.)
    • Added pipeline-level session options support, as AITK-converted models may specify execution providers at both decoder and pipeline levels
    • Implemented dynamic provider detection using HasProvider() and GetProviderOptions() methods to handle different config structures
  2. Robust Hardware Detection (DeviceUtils.cs, new ExecutionProviderNames.cs)

    • Added HasNPU() method using ONNX Runtime's execution provider device detection
    • Implemented GetEpDevices() to query all available EPs on the device by ensuring certified execution providers are registered before detection
    • Introduced caching mechanism to avoid repeated EP registration overhead
    • Created centralized ExecutionProviderNames constants class to eliminate hardcoded EP strings and ensure consistency across the codebase
  3. Intelligent Model Classification and Validation (UserAddedModelUtil.cs, ModelCompatibility.cs)

    • Completely rewrote GetHardwareAcceleratorFromConfig() to:
      • Check both decoder-level and pipeline-level provider options
      • Properly detect NPU configurations (QNN, OpenVINO with NPU device type, VitisAI)
      • Follow correct priority order: QNN > DML > NPU > GPU > CPU
    • Added ValidateExecutionProviders() to validate required EPs are available before model loading
    • Added NPU compatibility checks in ModelCompatibility.cs with proper error messaging
    • Implemented user-friendly warning dialog when loading models with unavailable execution providers
  4. Code Quality Improvements

    • Standardized EP name references using ExecutionProviderNames constants throughout (ScenarioPage.xaml.cs, WinMLHelpers.cs)
    • Consolidate EP device retrieval to use DeviceUtils

Testing

  • AITK-converted NPU models display the correct NPU tag
  • Models requiring unavailable execution providers show appropriate warnings
  • The application gracefully handles various GenAI config structures
  • Hardware detection is efficient and consistent

Notes

In the current workflow introduced by this PR, the early validation during model addition only checks for EP availability (e.g., attempting to load QNN EP on an Intel machine will trigger a warning dialog). It does not include hardware capability checks (such as verifying the size of dedicated video memory). Hardware capability validation occurs later during model loading, where incompatible models are hidden.
Future work will involve refining compatibility rules and improving the timing of these checks.

Known related issue #523 (will not be fixed in this PR)

@weiyuanyue weiyuanyue marked this pull request as ready for review December 3, 2025 10:50
@weiyuanyue
Copy link
Contributor Author

@copilot

Copy link
Contributor

Copilot AI commented Dec 4, 2025

@weiyuanyue I've opened a new pull request, #525, to work on those changes. Once the pull request is ready, I'll request review from you.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@weiyuanyue weiyuanyue changed the title [Fix] NPU hardware accelerator detection for custom models loaded from AITK converted genai_config.json [Fix]Incorrect CPU Tagging for AITK NPU Models by Enhancing EP Detection Dec 4, 2025
@weiyuanyue weiyuanyue merged commit 46ea2a7 into main Dec 5, 2025
8 checks passed
@weiyuanyue weiyuanyue deleted the milly/npu branch December 5, 2025 03:48
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