Skip to content

OnnxRuntimeGenAIChatClient in WINUI3 S4 Hibernation Scenario: Model Residue When Not Disposed, Crash on Dispose() Call #1836

@suki-lqh

Description

@suki-lqh

Untitled Document

Describe the bug
After initializing the model using OnnxRuntimeGenAIChatClient in WINUI3, when entering S4, we observed that the memory usage of the NPU has dropped to 0, but the OnnxRuntimeGenAIChatClient was not released. During inference, it remains in the inference state without any data returned. Therefore, we added Dispose() when entering S4. However, an uncatchable crash occurs when calling dispose() on OnnxRuntimeGenAIChatClient while entering S4.

PowerManager.SystemSuspendStatusChanged += PowerManager_SystemSuspendStatusChanged;
private void PowerManager_SystemSuspendStatusChanged(object sender, object e)
{
    if (PowerManager.SystemSuspendStatus == SystemSuspendStatus.Entering)
    {
        try
        {
            model.Dispose();//model is OnnxRuntimeGenAIChatClient
        }
        catch
        {

        }
        finally
        {

        }
    }
    Debug.WriteLine($"PowerManager_SystemSuspendStatusChanged:{Enum.GetName(PowerManager.SystemSuspendStatus)}");
}

To Reproduce
Steps to reproduce the behavior:

  1. Initialize the model
  2. Wait for the initialization to complete
  3. Enter S4 (if there is no crash, try entering S4 multiple times)

Expected behavior
The model should be released normally.

Desktop (please complete the following information)

  • OS: Windows 11 Home 25H2 26200.6588
  • OnnxRuntimeGenAI.QNN: 0.10.0
  • NPU driver: 30.0.140.1000/30.0.145.1000

Additional context
You can add any other relevant information about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions