-
Notifications
You must be signed in to change notification settings - Fork 49
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
Revise graph resource validation #622
Revise graph resource validation #622
Conversation
compute() calls validate graph resources with the passed input/output maps and the graph's input/output descriptors. The intent is to ensure that all of a graph's descriptors are matched to a passed resource. However, the steps were only validating that a passed resource had a corresponding descriptor - it wouldn't flag if a resource was missing! The Chromium prototype implementation makes the test reflexive - all descriptors must have a corresponding resource and all resources must have a corresponding descriptor. Incorporate that into the spec in the same way - if number of keys is the same, and each resource has a descriptor, then _ipso facto_* each descriptor has a resource. Fixes webmachinelearning#602 (* = a Latin phrase meaning "the writer is pretentious")
@huningxin and @fdwr - can you please review? Thanks! |
index.bs
Outdated
@@ -840,6 +840,7 @@ When the {{MLContext/[[contextType]]}} is set to [=context type/default=] with t | |||
<summary> | |||
To <dfn>validate graph resources</dfn>, given {{MLNamedArrayBufferViews}} |resources| and [=ordered map=] |descriptors|, run the following steps: | |||
</summary> | |||
1. If |resources|'s [=map/size=] does not equal |descriptors|'s [=map/size=], then return false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this implied by the loop below? (but a quick test is fine)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If resources's keys are [ "a", "b" ] but descriptors's keys are [ "a", "b", "c" ] the loop below won't fail:
- For each name → resource of resources:
So this would iterate over [ "a", "b" ]
- If descriptors[name] does not exist, return false.
descriptors["a"] and descriptors["b"] exist, so this does not fail
- If validating buffer with descriptor given resource and descriptors[name] returns false, then return false.
Presumably this also doesn't fail
- Return true.
So we return true, even though "c" is not provided.
Before reviewing, I'm just thinking aloud the various cases, given a graph that expects 2 inputs and generates 2 outputs...
Anyway, we definitely both agree (per #602) on the case where it "Should fail, because input2 is missing - but it doesn't" ❌. |
Computing a subset of outputs is supported. There was an example using sync compute API https://www.w3.org/TR/2024/CRD-webnn-20240214/#example-4a21156c. Unfortunately, my PR #548 that removes the sync APIs deleted this example together. We may want to bring it back by adapting to async compute API. |
Correct. Based on above ✔🤷♂️❌ it sounds like we might want:
Given this we'd want either one algorithm that takes a flag (is input or output?) or two algorithms. The latter is probably easier. And since they're only used in one place this could be in-line in "execute graph", something like this:
... and then a non-normative note saying something like:
|
SGTM! |
* inputs must be provided, but extra inputs are ignored * requested outputs must exist, but not all outputs must be requested
1e7e2b9 captures the algorithm discussed above. We should probably wait for the WG telecon to decide if this is what we want. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I updated this PR's name/description to match the changes. I think we're probably good to merge now? |
@fdwr , do you have any further comments? |
Yeah, I like it. Thanks for noticing and fixing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Minor merge conflict from the transferred inputs/outputs CR. So just resolved. |
SHA: fd8a8d0 Reason: push, by fdwr Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* Fix unidirectionally broadcast the shapes steps Fix #622 * Update the call sites of "unidirectionally broadcasting the shapes" * Reverse the order of `shapeFrom` and `shapeTo`
compute()
calls validate graph resources with the passed input/output maps and the graph's input/output descriptors. The intent is to ensure that all of a graph's descriptors are matched to a passed resource. However, the steps were only validating that a passed resource had a corresponding descriptor - it wouldn't flag if a resource was missing!The Chromium prototype implementation made the test reflexive - all resources much have matching descriptors and vice versa. After deliberation we settled on a more helpful behavior: all inputs must be provided, but extra inputs are ignored. A requested output must be present, but dropping outputs is allowed.
Fixes #602
Preview | Diff