Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching backends yields error - Failed to execute 'dispatch' on 'MLContext': Invalid inputs: The context of MLGraph doesn't match the context of the MLTensor with name "pixel_values" #69

Open
ibelem opened this issue Dec 11, 2024 · 2 comments

Comments

@ibelem
Copy link
Contributor

ibelem commented Dec 11, 2024

Repro Steps:

  1. Run WebNN on a NPU supported device e.g. Intel LNL
  2. Enable WebNN on Chrome Canary
  3. Visit Image Classification demo on NPU https://microsoft.github.io/webnn-developer-preview/demos/image-classification/?provider=webnn&devicetype=npu&model=mobilenet-v2&run=1
  4. Click Classify button

Actual Result

PASS

Repro Steps: (cont.)

  1. Click WebNN GPU button
  2. Click Classify button

Actual Result

Failed to execute 'dispatch' on 'MLContext': Invalid inputs: The context of MLGraph doesn't match the context of the MLTensor with name "pixel_values"

Note

Error also occurs when switching from WebNN GPU to WebNN NPU

Environment

  • Google Chrome Version 133.0.6887.4 (Official Build) canary (64-bit)

This version of Transformers.js distribution was built using the following components:

  1. ONNX Runtime Web: 1.21.0-dev.20241122-a2ba3cb547
  2. Transformers.js: v3 branch
  3. Get performance data: patch

Related Issues

Related Fixes

@egalli Please help to check this issue. Thanks!

CC @fdwr @Honry

Image

@ibelem
Copy link
Contributor Author

ibelem commented Dec 11, 2024

@egalli

  1. Add let classifier; before main()

  2. Update

const classifier = await transformers.pipeline("image-classification", modelPath, options);

to

classifier = await transformers.pipeline("image-classification", modelPath, options);

  1. Add codes in updateBackend()
        if (classifier) {
            await classifier.dispose();

            // let model = classifier.model.sessions?.model;
            // await model.release();

            // classifier = null;
            console.log("classifier.dispose() completed");
        }

Added codes above in demo application side (index.js), the classifier dispose() method was invoked successfully, but the issue still exists when clicking Classify button. Do you have any insights? Thanks!

egalli added a commit to egalli/onnxruntime that referenced this issue Dec 13, 2024
We weren't checking that MLTensors were from the same context before reusing them.

Found while debugging microsoft/webnn-developer-preview#69
@egalli
Copy link

egalli commented Dec 13, 2024

It looks like we weren't checking the context before attempting to reuse existing MLTensors. I have created a PR fthat fixes the issue microsoft/onnxruntime#23100

guschmue pushed a commit to microsoft/onnxruntime that referenced this issue Dec 17, 2024
We weren't checking that MLTensors were from the same context before
reusing them.

Found while debugging microsoft/webnn-developer-preview#69
guschmue pushed a commit to microsoft/onnxruntime that referenced this issue Dec 20, 2024
We weren't checking that MLTensors were from the same context before
reusing them.

Found while debugging microsoft/webnn-developer-preview#69
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

No branches or pull requests

2 participants