From c320472d6cc95fb15bfa5c7c7f1727119bd317c3 Mon Sep 17 00:00:00 2001 From: Dwayne Robinson Date: Mon, 12 Feb 2024 19:56:21 -0800 Subject: [PATCH] Fix dimensions for 0D scalars (#476) * Fix dimensions for 0D scalars * Code review comments * reshape CR feedback * More CR feedback * Minor cleanup * Fix bikeshed validation on LSTM tensor names * Fix reshape bad merge * Unbracket MLCommandEncoder in status text to appease bikeshed * CR feedback * Fix empty reshape dimensions to 1, not 0 --- index.bs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/index.bs b/index.bs index 96967327..fbedd725 100644 --- a/index.bs +++ b/index.bs @@ -1815,10 +1815,7 @@ Data truncation will occur when the specified value exceeds the range of the spe 1. Let |descriptor| be a new {{MLOperandDescriptor}}. 1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |type|. - 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to `undefined`. -
- In the case of a scalar constant, |descriptor|.{{MLOperandDescriptor/dimensions}} is ignored. -
+ 1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to an empty [=/list=]. 1. If any of the following sub-steps fail, [=exception/throw=] an "{{OperationError}}" {{DOMException}}. 1. Let |operand| be the result of [=creating an MLOperand=] given [=this=] and |descriptor|. 1. Make a request to the underlying platform to: @@ -3995,9 +3992,7 @@ partial interface MLGraphBuilder {
1. Let |numDirections| be 1 if |options|.{{MLLstmOptions/direction}} is {{MLRecurrentNetworkDirection/"forward"}}, or otherwise let it be 2. -
- The shape of |input|, |weight| or |recurrentWeight| could be also checked here. -
+ 1. If the [=rank=] of |input| or |weight| or |recurrentWeight| is not 3, then [=exception/throw=] a "{{DataError}}" {{DOMException}}. 1. If |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}[0] is not equal to |steps|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}. 1. Let |batchSize| be |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}[1]. 1. If |options|.{{MLLstmOptions/bias}} [=map/exists=]: @@ -5120,12 +5115,10 @@ partial interface MLGraphBuilder {
1. Let |outputShape| be an empty array of {{unsigned long}}. - 1. If |newShape| is a scalar [=number=], set |outputShape| to the [=/list=] « 1 ». - 1. Otherwise, if |newShape| is an array of {{unsigned long}}: - 1. If the [=list/size=] of |newShape| is 0, set |outputShape| to the [=/list=] « 1 » (reshaping to scalar). - 1. If any value in |newShape| is 0, then [=exception/throw=] a "{{DataError}}" {{DOMException}}. - 1. Let |inputElementCount| be the product of all elements in |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. - 1. If product of all values in |newShape| is not equal to |inputElementCount|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}. + 1. If the [=list/size=] of |newShape| is 0, set |outputShape| to an empty [=/list=] for a scalar. + 1. If any value in |newShape| is 0, then [=exception/throw=] a "{{DataError}}" {{DOMException}}. + 1. Let |inputElementCount| be the product of all elements in |input|.{{MLOperand/[[descriptor]]}}.{{MLOperandDescriptor/dimensions}}. Empty dimensions yield an |inputElementCount| of 1. + 1. If product of all values in |newShape| is not equal to |inputElementCount|, then [=exception/throw=] a "{{DataError}}" {{DOMException}}. 1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}. 1. Set |desc|.{{MLOperandDescriptor/dimensions}} to |newShape|. 1. If any of the following sub-steps fail, [=exception/throw=] an "{{OperationError}}" {{DOMException}}. @@ -5997,7 +5990,7 @@ The {{MLOperand}} objects are created by the methods of {{MLGraphBuilder}}, inte
1. If |builder| is not equal to |operand|.{{MLOperand/[[builder]]}}, return false. 1. Let |desc| be |operand|.{{MLOperand/[[descriptor]]}}. - 1. If |desc|.{{MLOperandDescriptor/dimensions}} [=map/exists=] and [=checking dimensions=] given |desc|.{{MLOperandDescriptor/dimensions}} and |desc|.{{MLOperandDescriptor/dataType}} returns false, then return false. + 1. If [=checking dimensions=] given |desc|.{{MLOperandDescriptor/dimensions}} and |desc|.{{MLOperandDescriptor/dataType}} returns false, then return false. 1. Return true.
@@ -6069,7 +6062,7 @@ dictionary MLOperandDescriptor { required MLOperandDataType dataType; // The dimensions field is only required for tensor operands. - sequence dimensions; + sequence dimensions = []; };