Skip to content

Commit fd8a8d0

Browse files
inexorabletashfdwr
andauthoredApr 16, 2024
Revise graph resource validation (#622)
* 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>
1 parent 954ed19 commit fd8a8d0

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed
 

‎index.bs

+8-12
Original file line numberDiff line numberDiff line change
@@ -843,16 +843,6 @@ When the {{MLContext/[[contextType]]}} is set to [=context type/default=] with t
843843
:: An object where the keys are the graph output names, and the values are the transferred {{ArrayBufferView}}s for the computed output tensor values.
844844
</dl>
845845

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-
856846
<details open algorithm>
857847
<summary>
858848
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
916906
**Returns:** Promise<{{MLComputeResult}}>.
917907
</div>
918908

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+
919911
<details open algorithm>
920912
<summary>
921913
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
924916
1. Let |realm| be [=this=]'s [=relevant realm=].
925917
1. If |graph|.{{MLGraph/[[context]]}} is not [=this=], then return [=a new promise=] [=rejected=] with a {{TypeError}}.
926918
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}}.
929925
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.
930926
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.
931927
1. Let |promise| be [=a new promise=].

0 commit comments

Comments
 (0)