Allow MLGraphBuilder.build() to be called only once#717
Allow MLGraphBuilder.build() to be called only once#717fdwr merged 2 commits intowebmachinelearning:mainfrom
Conversation
| 1. If |operand| is in [=this=]'s [=MLGraphBuilder/graph=]'s [=computational graph/inputs=], [=set/append=] |operand| to |inputs|. | ||
| 1. [=list/For each=] |input| of |operand|.{{MLOperand/[[operator]]}}'s [=operator/inputs=]: | ||
| 1. [=queue/Enqueue=] |input| to |queue|. |
There was a problem hiding this comment.
Note: this PR does not address #567 (comment) since there didn't appear to be consensus on whether that was desirable (FYI @inexorabletash @fdwr). If folks have strong feelings in either direction then I propose we file a separate issue to discuss; otherwise I propose we leave this as-is for now. WDYT?
There was a problem hiding this comment.
Agree it is a separate issue.
|
@huningxin @fdwr PTAL? |
| 1. If |operand| is in [=this=]'s [=MLGraphBuilder/graph=]'s [=computational graph/inputs=], [=set/append=] |operand| to |inputs|. | ||
| 1. [=list/For each=] |input| of |operand|.{{MLOperand/[[operator]]}}'s [=operator/inputs=]: | ||
| 1. [=queue/Enqueue=] |input| to |queue|. |
| 1. If |operand| is in [=this=]'s [=MLGraphBuilder/graph=]'s [=computational graph/inputs=], [=set/append=] |operand| to |inputs|. | ||
| 1. [=list/For each=] |input| of |operand|.{{MLOperand/[[operator]]}}'s [=operator/inputs=]: | ||
| 1. [=queue/Enqueue=] |input| to |queue|. |
There was a problem hiding this comment.
Agree it is a separate issue.
| 1. If |operand| is in [=this=]'s [=MLGraphBuilder/graph=]'s [=computational graph/inputs=], [=set/append=] |operand| to |inputs|. | ||
| 1. [=list/For each=] |input| of |operand|.{{MLOperand/[[operator]]}}'s [=operator/inputs=]: | ||
| 1. [=queue/Enqueue=] |input| to |queue|. |
| <summary> | ||
| The <dfn method for=MLGraphBuilder>where(|condition|, |input|, |other|)</dfn> method steps are: | ||
| </summary> | ||
| 1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}. |
There was a problem hiding this comment.
🫤 Seeing "if hasBuilt is true then throw this kind of error" repeated in the logic of every single operator feels unclean. Can we have a common graph builder "operator initialization" function that they all call, and that error check can be the very first (and currently only) step in it, kinda like how we centralized casting and broadcasting functionality? Mind you, every single operator still then needs "1. Perform builder-operator-initialization", but it feels 🧼➕ imo. Opinion?
There was a problem hiding this comment.
Hmm I agree the current state is annoyingly duplicative, but I couldn't decide on a useful name of a helper method... This check is performed in MLGraphBuilder.build() as well all methods which mint an MLOperand. Calling a "builder-operator-initialization" algorithm from the build() steps is a bit odd (and nothing is being initialized anyways).
Lacking a good name, I figured inlining the one-liner would be more readable ¯\(ツ)/¯
If you can think of a better name then I'm happy to change it :P
There was a problem hiding this comment.
The pervasive naming challenge... Let me ponder a bit, after some sleep. 😴
There was a problem hiding this comment.
Throwing out another idea: we could maybe use a Bikeshed text macro to reduce the burden on spec authors. We define one today for EMULATED to avoid repetition. This doesn't reduce the burden on spec readers, though.
There was a problem hiding this comment.
True, though we'd still have to name the macro :P
THROW_IF_BUILT?
There was a problem hiding this comment.
THROW_IF_ALREADY_BUILT?
EnsureNotAlreadyBuilt?
...
No particularly bright insights came to me after sleep or over the weekend 😅. Going to merge now and maybe we'll think of something later...
See webmachinelearning/webnn#717 Bug: 354724062 Change-Id: I8ac2bf94b1f5a0db93a042babdc2556eab35034a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5684454 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Austin Sullivan <[email protected]> Cr-Commit-Position: refs/heads/main@{#1332702}
See webmachinelearning/webnn#717 Bug: 354724062 Change-Id: I8ac2bf94b1f5a0db93a042babdc2556eab35034a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5684454 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Austin Sullivan <[email protected]> Cr-Commit-Position: refs/heads/main@{#1332702}
See webmachinelearning/webnn#717 Bug: 354724062 Change-Id: I8ac2bf94b1f5a0db93a042babdc2556eab35034a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5684454 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Austin Sullivan <[email protected]> Cr-Commit-Position: refs/heads/main@{#1332702}
…at most one MLGraph, a=testonly Automatic update from web-platform-tests webnn: Allow an MLGraphBuilder to build at most one MLGraph See webmachinelearning/webnn#717 Bug: 354724062 Change-Id: I8ac2bf94b1f5a0db93a042babdc2556eab35034a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5684454 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Austin Sullivan <[email protected]> Cr-Commit-Position: refs/heads/main@{#1332702} -- wpt-commits: b7777fabd7363bb2e65a3a5da4538bcf0eedee9c wpt-pr: 47285
Currently WebNN spec only allows MLGraphBuilder.build() to be called once, we need to create new builder for every subgraph in WebNN EP. Spec change: webmachinelearning/webnn#717
Currently WebNN spec only allows MLGraphBuilder.build() to be called once, we need to create new builder for every subgraph in WebNN EP. Spec change: webmachinelearning/webnn#717
Currently WebNN spec only allows MLGraphBuilder.build() to be called once, we need to create new builder for every subgraph in WebNN EP. Spec change: webmachinelearning/webnn#717
…at most one MLGraph, a=testonly Automatic update from web-platform-tests webnn: Allow an MLGraphBuilder to build at most one MLGraph See webmachinelearning/webnn#717 Bug: 354724062 Change-Id: I8ac2bf94b1f5a0db93a042babdc2556eab35034a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5684454 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Austin Sullivan <[email protected]> Cr-Commit-Position: refs/heads/main@{#1332702} -- wpt-commits: b7777fabd7363bb2e65a3a5da4538bcf0eedee9c wpt-pr: 47285

Fixes #567
If
MLGraphBuilder.build()results in anything other than aTypeError- e.g. it successfully resolves with an orMLGraphor rejects with aNotSupportedError- thatMLGraphBuilderhas now been "built" and all subsequent methods will now reject with anInvalidStateError.Preview | Diff