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
Whether to include or exclude the current value in the output, meaning inclusive presum addition (see https://en.wikipedia.org/wiki/Prefix_sum) or exclusive post-sum addition. Given input *[1,2,3,4]*, inclusive addition would yield an output of *[1,3,6,10]* whereas exclusive would yield *[0,1,3,6]*. The default is inclusive.
2977
+
Whether to include or exclude the current value in the output, meaning inclusive prefix sum or exclusive prefix sum [[Prefix-sum]]. Given input *[1,2,3,4]*, inclusive addition would yield an output of *[1,3,6,10]* whereas exclusive would yield *[0,1,3,6]*. The default is inclusive.
2978
2978
2979
2979
: <dfn>reversed</dfn>
2980
2980
::
2981
-
Whether to reverse the summation direction along the active axis to instead start from the high coordinate to low coordinate. Given input *[1,2,3,4]*, inclusive forward addition would yield an output of *[1,3,6,10]* whereas backward summation would yield *[10,9,7,4]*. The default is exclusive.
2981
+
Whether to reverse the summation direction along the active axis to instead start from the high coordinate to low coordinate. Given input *[1,2,3,4]*, inclusive forward addition would yield an output of *[1,3,6,10]* whereas backward summation would yield *[10,9,7,4]*. The default is forward.
- *lesser*: Compare if the values of the first input tensor is lesser, element-wise.
3314
3314
- *lesserOrEqual*: Compare if the values of the first input tensor is lesser or equal, element-wise.
3315
3315
- *logicalNot*: Invert the values of the input tensor to values 0 or 1, element-wise. Specifically, when the input value is non-zero, invert it to 0. Conversely, for a zero input value, invert it to 1.
3316
-
- *logicalAnd*: Compute the logical *and* operator, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
3317
-
- *logicalOr*: Compute the logical *or* operator, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
3318
-
- *logicalXor*: Compute the logical *xor* operator, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
3316
+
- *logicalAnd*: Compute the logical *and* of the two input tensors, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
3317
+
- *logicalOr*: Compute the logical *or* of the two input tensors, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
3318
+
- *logicalXor*: Compute the logical *xor* of the two input tensors, element-wise, treating any non-zero value as true and returning elements of 0 or 1.
3319
3319
</div>
3320
3320
3321
3321
<div class="note">
@@ -3328,7 +3328,7 @@ Although operations {{MLGraphBuilder/greaterOrEqual()}} and {{MLGraphBuilder/les
3328
3328
</summary>
3329
3329
1. [=Assert=]: |op| is one of "equal", "notEqual", "greater", "greaterOrEqual", "lesser", "lesserOrEqual", "logicalNot", "logicalAnd", "logicalOr", "logicalXor".
3330
3330
1. If [=this=][=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
3331
-
1. If |op| is "logicalNot":
3331
+
1. If |op| is one of "logicalNot", "logicalAnd", "logicalOr", "logicalXor":
3332
3332
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |a| returns false, then [=exception/throw=] a {{TypeError}}.
3333
3333
1. If |a|'s [=MLOperand/dataType=] is not {{MLOperandDataType/"uint8"}}, then [=exception/throw=] a {{TypeError}}.
3334
3334
1. Let |outputShape| be a [=list/clone=] of |a|'s [=MLOperand/shape=].
The <dfn method for=MLGraphBuilder>sign(|input|, |options|)</dfn> method steps are:
3643
-
1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-unary-op | create element-wise unary operation=] given "sign", |input|, signed types « {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}}, {{MLOperandDataType/"int32"}}, {{MLOperandDataType/"int8"}} », and |options|.
3643
+
1. Let |output| be the result of running the [=MLGraphBuilder/element-wise-unary-op | create element-wise unary operation=] given "sign", |input|, « {{MLOperandDataType/"float32"}}, {{MLOperandDataType/"float16"}}, {{MLOperandDataType/"int32"}}, {{MLOperandDataType/"int8"}} », and |options|.
3644
3644
1. If that [=exception/throws=] an error, then re-[=exception/throw=] the error.
Dequantizes an integer tensor to floating point space using the scale and zero-point bias, where `output = (input - zeroPoint) * scale`.
3688
+
Dequantizes an integer tensor to floating point tensor using the scale and zero-point bias, where `output = (input - zeroPoint) * scale`.
3689
3689
3690
3690
TODO: Elaborate on blockwise broadcasting - The operation will be [=broadcast=] according to [[!numpy-broadcasting-rule]]. The input tensors must be [=bidirectionally broadcastable=]. The [=MLOperand/rank=] of the output tensor is the maximum [=MLOperand/rank=] of the input tensors. For each dimension of the output tensor, its size is the maximum size along that dimension of the input tensors, and each dimension must be blockwise compatible with the output (e.g. given an input shape *[12]*, scales of the following shapes are blockwise compatible {*[1]*, *[3]*, *[4]*, *[6]*, *[12]*} as they are all multiples of the input dimensions, but a shape of *[5]* would not be).
- <dfn>input</dfn>: an {{MLOperand}}. The input tensor.
3715
-
- <dfn>scale</dfn>: an {{MLOperand}}. The scale tensor to multiply each input value by after adjusting by the zero point.
3716
-
- <dfn>zeroPoint</dfn>: an {{MLOperand}}. The zero point tensor to subtract from each input value.
3715
+
- <dfn>scale</dfn>: an {{MLOperand}}. The scale tensor to multiply each input value by after adjusting by the zero point. It has the same [=MLOperand/rank=] as the input, and its [=MLOperand/shape=] must evenly divide into the input [=MLOperand/shape=].
3716
+
- <dfn>zeroPoint</dfn>: an {{MLOperand}}. The zero point tensor to subtract from each input value. It has the same [=MLOperand/shape=] as the scale.
3717
3717
- <dfn>options</dfn>: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation.
3718
3718
3719
3719
**Returns:** an {{MLOperand}}. The output tensor that contains the dequantized values.
1. If [=this=].{{MLGraphBuilder/[[hasBuilt]]}} is true, then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
3776
3776
1. If [=MLGraphBuilder/validating operand=] with [=this=] and any of |input|, |scale|, and |zeroPoint| returns false, then [=exception/throw=] a {{TypeError}}.
3777
-
TODO: Add validation for scale and zero point shape.
3777
+
1. If |scale|'s [=MLOperand/rank=] or |zeroPoint|'s [=MLOperand/rank=] mismatches |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}.
3778
+
1. If |scale|'s [=MLOperand/shape=] mismatches |zeroPoint|'s [=MLOperand/shape=], then [=exception/throw=] a {{TypeError}}.
3779
+
1. [=list/For each=] |axis| in [=the range=] 0 to |input|'s [=MLOperand/rank=], exclusive:
3780
+
1. If |scale|'s [=MLOperand/shape=][|axis|] is not exactly divisible into |input|'s [=MLOperand/shape=][|axis|], then [=exception/throw=] a {{TypeError}}.
3781
+
1. If |zeroPoint|'s [=MLOperand/shape=][|axis|] is not exactly divisible into |input|'s [=MLOperand/shape=][|axis|], then [=exception/throw=] a {{TypeError}}.
Quantizes a floating point tensor to integer point space using the scale and zero-point bias, where `output = clamp(roundToNearestEvens(input / scale) + zeroPoint, 0, 255)`.
3797
+
Quantizes a floating point tensor to integer tensor using the scale and zero-point bias, where `output = clamp(roundToNearestEvens(input / scale) + zeroPoint, 0, 255)`.
3794
3798
3795
3799
TODO: Elaborate on blockwise broadcasting - The operation will be [=broadcast=] according to [[!numpy-broadcasting-rule]]. The input tensors must be [=bidirectionally broadcastable=]. The [=MLOperand/rank=] of the output tensor is the maximum [=MLOperand/rank=] of the input tensors. For each dimension of the output tensor, its size is the maximum size along that dimension of the input tensors, and each dimension must be blockwise compatible with the output (e.g. given an input shape *[12]*, scales of the following shapes are blockwise compatible {*[1]*, *[3]*, *[4]*, *[6]*, *[12]*} as they are all multiples of the input dimensions, but a shape of *[5]* would not be).
- <dfn>input</dfn>: an {{MLOperand}}. The condition tensor.
3820
-
- <dfn>scale</dfn>: an {{MLOperand}}. The scale tensor to multiply each input value by after adjusting by the zero point.
3821
-
- <dfn>zeroPoint</dfn>: an {{MLOperand}}. The zero point tensor to subtract from each input value.
3824
+
- <dfn>scale</dfn>: an {{MLOperand}}. The scale tensor to divide each input value by after adjusting by the zero point. It has the same [=MLOperand/rank=] as the input, and its [=MLOperand/shape=] must evenly divide into the input [=MLOperand/shape=].
3825
+
- <dfn>zeroPoint</dfn>: an {{MLOperand}}. The zero point tensor to add to each rescaled input value. It has the same [=MLOperand/shape=] as the scale.
3822
3826
- <dfn>options</dfn>: an {{MLOperatorOptions}}. Specifies the optional parameters of the operation.
3823
3827
3824
3828
**Returns:** an {{MLOperand}}. The output tensor that contains the quantized values.
1. If [=this=][=MLGraphBuilder/can not build=], then [=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
7945
7949
1. If [=MLGraphBuilder/validating operand=] with [=this=] and |input| returns false, then [=exception/throw=] a {{TypeError}}.
7946
7950
1. If |input|'s [=MLOperand/dataType=] is not one of its [=/allowed data types=] (according to [this table](#constraints-reverse)), then [=exception/throw=] a {{TypeError}}.
7951
+
1. If |axes| is not given, let |axes| be [=the range=] 0 to |inputRank|, exclusive.
7952
+
1. Otherwise, if |axes| contains duplicate values, or if any of its elements is not in [=the range=] 0 to |inputRank|, exclusive, then return failure.
7947
7953
1. *Make graph connections:*
7948
7954
1. Let |output| be the result of [=copying an MLOperand=] given |input|.
7949
7955
1. Let |operator| be an [=operator=] for the "reverse" operation and |options|.
@@ -9542,8 +9548,6 @@ Operations present in other neural network inference APIs can often be emulated
9542
9548
9543
9549
<p class="note">{{Float16Array}} is at <a href="https://tc39.es/process-document/">ECMA Stage 3</a> signaling its design is finished. Implementers wanting to enable this type ahead native implementations can emulate the type by passing raw bits via {{Uint16Array}}. <a href="https://github.com/webmachinelearning/webnn/issues/373">[Issue webnn#373]</a></p>
9544
9550
9545
-
<p class="note">There is no Uint4Array/Int4Array class. Nybbles are stored in byte arrays of {{Uint8Array}} with the lower nybble in the lower bits, meaning tensor element 0 would be found in byte 0 bits 0-3, and tensor element 1 in byte 0 bits 4-7 (and so on, with tensor element 5 in byte 2 bits 4-7). Odd tensor element counts are rounded up to whole bytes, and last nybble is ignored, meaning a 5 element tensor uses 3 bytes.</a></p>
9546
-
9547
9551
<h2 id="acknowledgements">Acknowledgements</h2>
9548
9552
9549
9553
This specification follows the concepts of the Android Neural Networks API C
@@ -10053,6 +10057,12 @@ Thanks to Feng Dai for his continuous contributions that keep web-platform-tests
0 commit comments