Skip to content

Commit 5d65b58

Browse files
Add missing validation steps for several ops
A follow-on to webmachinelearning#706 and the [audit](https://docs.google.com/spreadsheets/d/1S5-bMWN1hDrkPGiHFCyX-OjcbEBj1a-aWNdtTQ2dcGg) by @huningxin that adds validation steps to several ops identified for edge cases in the Chromium prototype implementation. This touches the following ops: - convTranspose2d - outputSizes items must be valid dimensions - lstm - steps must be greater than 0 - pool2d - windowDimensions must be greater than 0 - pool2d - outputSizes items must be valid dimensions - pool2d - specified output sizes must be floor() or ceil() of calculated output sizes - split - splits (if a number) must be greater than 0 Fixes webmachinelearning#818 as well.
1 parent fccaccb commit 5d65b58

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

index.bs

+28-7
Original file line numberDiff line numberDiff line change
@@ -2658,15 +2658,19 @@ partial dictionary MLOpSupportLimits {
26582658
1. If |options|.{{MLConv2dOptions/bias}} [=map/exists=]:
26592659
1. If its [=MLOperand/shape=] is not [=list/equal=] to « |outputChannels| », then [=exception/throw=] a {{TypeError}}.
26602660
1. If its [=MLOperand/dataType=] is not one of its [=/allowed data types=] (according to [this table](#constraints-conv2d)), then [=exception/throw=] a {{TypeError}}.
2661-
1. Let |outputSizes| be the result of [=MLGraphBuilder/calculating conv2d output sizes=] given |inputHeight|, |inputWidth|, |filterHeight|, |filterWidth|, |options|.{{MLConv2dOptions/padding}}, |options|.{{MLConv2dOptions/strides}}, and |options|.{{MLConv2dOptions/dilations}}.
2661+
1. Let « |outputHeight|, |outputWidth| » be the result of [=MLGraphBuilder/calculating conv2d output sizes=] given |inputHeight|, |inputWidth|, |filterHeight|, |filterWidth|, |options|.{{MLConv2dOptions/padding}}, |options|.{{MLConv2dOptions/strides}}, and |options|.{{MLConv2dOptions/dilations}}.
2662+
1. If either |outputHeight| or |outputWidth| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
26622663
1. Switch on |options|.{{MLConv2dOptions/inputLayout}}:
26632664
<dl class=switch>
26642665
: {{MLInputOperandLayout/"nchw"}}
2665-
:: Let |outputShape| be « |batches|, |outputChannels|, floor( |outputSizes|[0] ), floor( |outputSizes|[1] ) ».
2666+
:: Let |outputShape| be « |batches|, |outputChannels|, floor( |outputHeight| ), floor( |outputWidth| ) ».
26662667
: {{MLInputOperandLayout/"nhwc"}}
2667-
:: Let |outputShape| be « |batches|, floor( |outputSizes|[0] ), floor( |outputSizes|[1] ), |outputChannels| ».
2668+
:: Let |outputShape| be « |batches|, floor( |outputHeight| ), floor( |outputWidth| ), |outputChannels| ».
26682669
</dl>
26692670
1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
2671+
2672+
Issue: The preceding step appears redundant with the validation of |outputHeight| and |outputWidth| above. Remove it?
2673+
26702674
1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |outputShape|.
26712675
1. *Make graph connections:*
26722676
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
@@ -2852,6 +2856,10 @@ partial dictionary MLOpSupportLimits {
28522856
1. Otherwise, if |options|.{{MLConvTranspose2dOptions/outputPadding}}'s [=list/size=] is not 2, then [=exception/throw=] a {{TypeError}}.
28532857
1. If |options|.{{MLConvTranspose2dOptions/outputSizes}} [=map/exists=]:
28542858
1. If its [=list/size=] is not 2, then [=exception/throw=] a {{TypeError}}.
2859+
1. If any of its [=list/items=] is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
2860+
2861+
Issue: The preceding step appears redundant with the validation of |outputHeight| and |outputWidth| below. Remove it?
2862+
28552863
1. Otherwise:
28562864
1. If |options|.{{MLConvTranspose2dOptions/outputPadding}}[0] is greater than or equal to |options|.{{MLConvTranspose2dOptions/strides}}[0], or |options|.{{MLConvTranspose2dOptions/outputPadding}}[1] is greater than or equal to |options|.{{MLConvTranspose2dOptions/strides}}[1], then [=exception/throw=] a {{TypeError}}.
28572865
1. If |options|.{{MLConvTranspose2dOptions/groups}} is 0, then [=exception/throw=] a {{TypeError}}.
@@ -2884,6 +2892,7 @@ partial dictionary MLOpSupportLimits {
28842892
1. Otherwise:
28852893
1. Let |outputHeight| be the result of [=MLGraphBuilder/calculating convtranspose output size=] given |inputHeight|, |filterHeight|, |padding|[0], |padding|[1], |strides|[0], |dilations|[0], and |outputPadding|[0].
28862894
1. Let |outputWidth| be the result of [=MLGraphBuilder/calculating convtranspose output size=] given |inputWidth|, |filterWidth|, |padding|[2], |padding|[3], |strides|[1], |dilations|[1] and |outputPadding|[1].
2895+
1. If either |outputHeight| or |outputWidth| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
28872896
1. Switch on |options|.{{MLConvTranspose2dOptions/inputLayout}}:
28882897
<dl class=switch>
28892898
: {{MLInputOperandLayout/"nchw"}}
@@ -2892,6 +2901,9 @@ partial dictionary MLOpSupportLimits {
28922901
:: Let |outputShape| be « |batches|, floor( |outputHeight| ), floor( |outputWidth| ), |outputChannels| ».
28932902
</dl>
28942903
1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
2904+
2905+
Issue: The preceding step appears redundant with the validation of |outputHeight| and |outputWidth| above. Remove it?
2906+
28952907
1. Let |desc| be the result of [=creating an MLOperandDescriptor=] given |input|'s [=MLOperand/dataType=] and |outputShape|.
28962908
1. *Make graph connections:*
28972909
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
@@ -5602,6 +5614,7 @@ partial dictionary MLOpSupportLimits {
56025614
1. Let |numDirections| be 2 if |options|.{{MLLstmOptions/direction}} is {{MLRecurrentNetworkDirection/"both"}}, or 1 otherwise.
56035615
1. If the [=MLOperand/dataType=] of any of |input|, |weight| or |recurrentWeight| is not one of its [=/allowed data types=] (according to [this table](#constraints-lstm)), then [=exception/throw=] a {{TypeError}}.
56045616
1. If the [=MLOperand/rank=] of any of |input|, |weight| or |recurrentWeight| is not its [=/allowed rank=], then [=exception/throw=] a {{TypeError}}.
5617+
1. If |steps| is 0, then [=exception/throw=] a {{TypeError}}.
56055618
1. If |input|'s [=MLOperand/shape=][0] is not equal to |steps|, then [=exception/throw=] a {{TypeError}}.
56065619
1. Let |batchSize| be |input|'s [=MLOperand/shape=][1].
56075620
1. Let |inputSize| be |input|'s [=MLOperand/shape=][2].
@@ -6547,6 +6560,7 @@ partial dictionary MLOpSupportLimits {
65476560
</dl>
65486561
1. If |options|.{{MLPool2dOptions/windowDimensions}} does not [=map/exist=], set |options|.{{MLPool2dOptions/windowDimensions}} to « |inputHeight|, |inputWidth| ».
65496562
1. If |options|.{{MLPool2dOptions/windowDimensions}}'s [=list/size=] is not 2, then [=exception/throw=] a {{TypeError}}.
6563+
1. If any [=list/item=] in |options|.{{MLPool2dOptions/windowDimensions}} is equal to 0, then [=exception/throw=] a {{TypeError}}.
65506564
1. If |options|.{{MLPool2dOptions/outputSizes}} [=map/exists=], or if |options|.{{MLPool2dOptions/padding}} does not [=map/exist=], set |options|.{{MLPool2dOptions/padding}} to the [=/list=] « 0, 0, 0, 0 ».
65516565
1. If |options|.{{MLPool2dOptions/padding}}'s [=list/size=] is not 4, then [=exception/throw=] a {{TypeError}}.
65526566
1. If |options|.{{MLPool2dOptions/strides}} does not [=map/exist=], set |options|.{{MLPool2dOptions/strides}} to the [=/list=] « 1, 1 ».
@@ -6560,11 +6574,13 @@ partial dictionary MLOpSupportLimits {
65606574
1. If any value in |options|.{{MLPool2dOptions/dilations}} is not greater than 0, then [=exception/throw=] a {{TypeError}}.
65616575
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}.
65626576
1. *Calculate the output shape:*
6563-
1. If |options|.{{MLPool2dOptions/outputSizes}} [=map/exists=], then let « |outputHeight|, |outputWidth| » be |options|.{{MLPool2dOptions/outputSizes}}.
6577+
1. Let « |windowHeight|, |windowWidth| » be |options|.{{MLPool2dOptions/windowDimensions}}.
6578+
1. Let « |calculatedOutputHeight|, |calculatedOutputWidth| » be the result of [=MLGraphBuilder/calculating conv2d output sizes=] given |inputHeight|, |inputWidth|, |windowHeight|, |windowWidth|, |options|.{{MLPool2dOptions/padding}}, |options|.{{MLPool2dOptions/strides}}, and |options|.{{MLPool2dOptions/dilations}}.
6579+
1. If |options|.{{MLPool2dOptions/outputSizes}} [=map/exists=], then:
6580+
1. Let « |outputHeight|, |outputWidth| » be |options|.{{MLPool2dOptions/outputSizes}}.
6581+
1. If neither |outputHeight| equals floor( |calculatedOutputHeight| ) and |outputWidth| equals floor( |calculatedOutputWidth| ), nor |outputHeight| equals ceil( |calculatedOutputHeight| ) and |outputWidth| equals ceil( |calculatedOutputWidth| ), then [=exception/throw=] a {{TypeError}}.
65646582
1. Otherwise:
6565-
1. Let « |windowHeight|, |windowWidth| » be |options|.{{MLPool2dOptions/windowDimensions}}.
6566-
1. Let |outputSizes| be the result of [=MLGraphBuilder/calculating conv2d output sizes=] given |inputHeight|, |inputWidth|, |windowHeight|, |windowWidth|, |options|.{{MLPool2dOptions/padding}}, |options|.{{MLPool2dOptions/strides}}, and |options|.{{MLPool2dOptions/dilations}}.
6567-
1. Let « |outputHeight|, |outputWidth| » be |outputSizes|.
6583+
1. Let « |outputHeight|, |outputWidth| » be « |calculatedOutputHeight|, |calculatedOutputWidth| ».
65686584
1. Switch on |options|.{{MLPool2dOptions/roundingType}}:
65696585
<dl class=switch>
65706586
: {{MLRoundingType/"floor"}}
@@ -6576,6 +6592,7 @@ partial dictionary MLOpSupportLimits {
65766592
1. Set |outputWidth| to ceiling(|outputWidth|).
65776593
1. Set |outputHeight| to ceiling(|outputHeight|).
65786594
</dl>
6595+
1. If either |outputHeight| or |outputWidth| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
65796596
1. Switch on |options|.{{MLPool2dOptions/layout}}:
65806597
<dl class=switch>
65816598
: {{MLInputOperandLayout/"nchw"}}
@@ -6584,6 +6601,9 @@ partial dictionary MLOpSupportLimits {
65846601
:: Let |outputShape| be « |batches|, |outputHeight|, |outputWidth|, |channels| ».
65856602
</dl>
65866603
1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
6604+
6605+
Issue: The preceding step appears redundant with the validation of |outputHeight| and |outputWidth| above. Remove it?
6606+
65876607
1. Set |desc|.{{MLOperandDescriptor/shape}} to |outputShape|.
65886608
1. *Make graph connections:*
65896609
1. Let |output| be the result of [=creating an MLOperand=] given [=this=] and |desc|.
@@ -7816,6 +7836,7 @@ partial dictionary MLOpSupportLimits {
78167836
1. Let |axis| be |options|.{{MLSplitOptions/axis}}.
78177837
1. If |axis| is greater than or equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}.
78187838
1. If |splits| is an {{unsigned long}}:
7839+
1. If |splits| is 0, then [=exception/throw=] a {{TypeError}}.
78197840
1. If |input|'s [=MLOperand/shape=][|axis|] % |splits| is not 0, then [=exception/throw=] a {{TypeError}}.
78207841
1. Otherwise, let |splitCount| be |splits|.
78217842
1. If |splits| is a [=sequence=]<{{unsigned long}}>:

0 commit comments

Comments
 (0)