You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Bug fix: Make "validate graph resources" test reflexive
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#602
(* = a Latin phrase meaning "the writer is pretentious")
* Update per discussion in PR review
* inputs must be provided, but extra inputs are ignored
* requested outputs must exist, but not all outputs must be requested
---------
Co-authored-by: Dwayne Robinson <dwayner@microsoft.com>
Copy file name to clipboardexpand all lines: index.bs
+8-12
Original file line number
Diff line number
Diff line change
@@ -843,16 +843,6 @@ When the {{MLContext/[[contextType]]}} is set to [=context type/default=] with t
843
843
:: An object where the keys are the graph output names, and the values are the transferred {{ArrayBufferView}}s for the computed output tensor values.
844
844
</dl>
845
845
846
-
<details open algorithm>
847
-
<summary>
848
-
To <dfn>validate graph resources</dfn>, given {{MLNamedArrayBufferViews}} |resources| and [=ordered map=] |descriptors|, run the following steps:
849
-
</summary>
850
-
1. [=map/For each=] |name| → |resource| of |resources|:
851
-
1. If |descriptors|[|name|] does not [=map/exist=], return false.
852
-
1. If [=validating buffer with descriptor=] given |resource| and |descriptors|[|name|] returns false, then return false.
853
-
1. Return true.
854
-
</details>
855
-
856
846
<details open algorithm>
857
847
<summary>
858
848
To <dfn>validate buffer with descriptor</dfn> given {{ArrayBufferView}} |bufferView| and {{MLOperandDescriptor}} |descriptor|, run the following steps:
@@ -916,6 +906,8 @@ In accordance with the [=ArrayBufferView/write|Web IDL warning=], to prevent the
916
906
**Returns:** Promise<{{MLComputeResult}}>.
917
907
</div>
918
908
909
+
Note: Invocations of {{MLContext/compute()}} will fail if any of the {{MLContext/compute(graph, inputs, outputs)/graph}}'s inputs are not provided as {{MLContext/compute(graph, inputs, outputs)/inputs}}, or if any requested {{MLContext/compute(graph, inputs, outputs)/outputs}} do not match the {{MLContext/compute(graph, inputs, outputs)/graph}}'s outputs.
910
+
919
911
<details open algorithm>
920
912
<summary>
921
913
The <dfn method for=MLContext>compute(|graph|, |inputs|, |outputs|)</dfn> method steps are:
@@ -924,8 +916,12 @@ In accordance with the [=ArrayBufferView/write|Web IDL warning=], to prevent the
924
916
1. Let |realm| be [=this=]'s [=relevant realm=].
925
917
1. If |graph|.{{MLGraph/[[context]]}} is not [=this=], then return [=a new promise=][=rejected=] with a {{TypeError}}.
926
918
1. If |graph|.{{MLGraph/[[context]]}}.{{MLContext/[[contextType]]}} is not "[=context type/default=]", then return [=a new promise=][=rejected=] with an "{{OperationError}}" {{DOMException}}.
927
-
1. If [=validating graph resources=] given |inputs| and |graph|.{{MLGraph/[[inputDescriptors]]}} returns false, then return [=a new promise=][=rejected=] with a {{TypeError}}.
928
-
1. If [=validating graph resources=] given |outputs| and |graph|.{{MLGraph/[[outputDescriptors]]}} returns false, then return [=a new promise=][=rejected=] with a {{TypeError}}.
919
+
1. [=map/For each=] |name| → |descriptor| of |graph|.{{MLGraph/[[inputDescriptors]]}}:
920
+
1. If |inputs|[|name|] does not [=map/exist=], then return [=a new promise=][=rejected=] with a {{TypeError}}.
921
+
1. If [=validating buffer with descriptor=] given |inputs|[|name|] and |descriptor| returns false, then return [=a new promise=][=rejected=] with a {{TypeError}}.
922
+
1. [=map/For each=] |name| → |resource| of |outputs|:
923
+
1. If |graph|.{{MLGraph/[[outputDescriptors]]}}[|name|] does not [=map/exist=], then return [=a new promise=][=rejected=] with a {{TypeError}}.
924
+
1. If [=validating buffer with descriptor=] given |resource| and |graph|.{{MLGraph/[[outputDescriptors]]}}[|name|] returns false, then return [=a new promise=][=rejected=] with a {{TypeError}}.
929
925
1. Let |transferredInputs| be the result of [=MLNamedArrayBufferViews/transfer|transferring=]{{MLNamedArrayBufferViews}} |inputs| with |realm|. If that threw an exception, then return [=a new promise=][=rejected=] with that exception.
930
926
1. Let |transferredOutputs| be the result of [=MLNamedArrayBufferViews/transfer|transferring=]{{MLNamedArrayBufferViews}} |outputs| with |realm|. If that threw an exception, then return [=a new promise=][=rejected=] with that exception.
0 commit comments