This issue was raised in Chromium WebNN CL review by @wacky6 , thanks Jiewei!
MLGraphBuilder takes a context, why do we define compute() on MLContext instead
of the built graph?
The change of moving compute methods from MLGraph to MLContext was introduced by #257 . As @wchao1115 mentioned, the main intention is to avoid adding more compute methods for different execution modes, such as queued execution mode of MLCommandEncoder for WebGPU interop, into the single MLGraph interface. The design choice was made to fold the execution methods into MLContext and MLCommandEncoder interfaces, hopefully "making it easier for developer to associate execution method to the context created with different options."
This allows passing a MLGraph build for a different context. This sounds like the spec is allowing misuse? I'd imagine a CPU graph can't be used with GPU context.
This is not the intention. This looks like an issue of WebNN. The current steps of Synchronous Execution and Asynchronous Execution should validate the MLGraph.[[context]] against the MLContext instance