Open anssiko opened 2 years ago
The model loader API exposes the MLContext
interface and it will be enabled by this flag. The webnn-polyfill should adapt to this and only polyfill the MLGraphBuilder and MLGraph interfaces.
@BruceDai , could you please take a look at this issue?
Yes, when testing by Chrome with enabled enable-experimental-web-platform-features flag, the following code would invoke createContext()
function of ML interface from Model Load API.
const context = navigator.ml.createContext(contextOptions);
The createContext()
function of Model Load API is an async function, it returns a Promise\<MLContext> object, while WebNN API MLGraphBuilder constructor requires a context parameter of MLContext type, so the error was alerted.
this.builder_ = new MLGraphBuilder(context);
To fix this issue need modify code using await
, @Honry PTAL, thanks.
const context = await navigator.ml.createContext(contextOptions);
while there's an issue https://github.com/webmachinelearning/model-loader/issues/41 of Model Load API.
And current WebNN Polyfill API checks whether Navigator object has ML interface, if not, WebNN Polyfill API will provide it.
if (navigator.ml == null) {
navigator.ml = new ML();
}
We are enabling latest async and sync APIs (PRs: https://github.com/webmachinelearning/webnn-polyfill/pull/172, https://github.com/webmachinelearning/webnn-samples/pull/150), which should fix this issue.
All samples at https://webmachinelearning.github.io/webnn-samples/ fail with:
If
chrome://flags/#enable-experimental-web-platform-features
is enabled.Tested with Chrome Stable 107 and Canary 109.