Skip to content

Commit

Permalink
Fix dimensions for 0D scalars (#476)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fdwr authored Feb 13, 2024
1 parent 55183f7 commit c320472
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,10 +1815,7 @@ Data truncation will occur when the specified value exceeds the range of the spe
</div>
1. Let |descriptor| be a new {{MLOperandDescriptor}}.
1. Set |descriptor|.{{MLOperandDescriptor/dataType}} to |type|.
1. Set |descriptor|.{{MLOperandDescriptor/dimensions}} to `undefined`.
<div class="note">
In the case of a scalar constant, |descriptor|.{{MLOperandDescriptor/dimensions}} is ignored.
</div>
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:
Expand Down Expand Up @@ -3995,9 +3992,7 @@ partial interface MLGraphBuilder {
</summary>
<div class=algorithm-steps>
1. Let |numDirections| be 1 if |options|.{{MLLstmOptions/direction}} is {{MLRecurrentNetworkDirection/"forward"}}, or otherwise let it be 2.
<div class="issue">
The shape of |input|, |weight| or |recurrentWeight| could be also checked here.
</div>
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=]:
Expand Down Expand Up @@ -5120,12 +5115,10 @@ partial interface MLGraphBuilder {
</summary>
<div class=algorithm-steps>
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}}.
Expand Down Expand Up @@ -5997,7 +5990,7 @@ The {{MLOperand}} objects are created by the methods of {{MLGraphBuilder}}, inte
<div class=algorithm-steps>
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.
</div>
</details>
Expand Down Expand Up @@ -6069,7 +6062,7 @@ dictionary MLOperandDescriptor {
required MLOperandDataType dataType;

// The dimensions field is only required for tensor operands.
sequence<unsigned long> dimensions;
sequence<unsigned long> dimensions = [];
};
</script>

Expand Down

0 comments on commit c320472

Please sign in to comment.