Skip to content

Commit 3aa67b3

Browse files
inexorabletashfdwr
andauthored
Restrict padding options to better match backend limits (#843)
* Restrict padding options to better match backend limits Per discussion in the linked issues and working group, drop "symmetric" padding since it is not widely supported by backends, isn't used by notable models, and can be emulated. Also for non-constant padding, backends typically impose restrictions on the amount of padding to reasonable values based on the input size, so incorporate those limits too. Resolves #377. Resolves #739. * Update index.bs Co-authored-by: Dwayne Robinson <[email protected]> * Remove 'edge' restrictions --------- Co-authored-by: Dwayne Robinson <[email protected]>
1 parent b152d46 commit 3aa67b3

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

index.bs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7253,8 +7253,7 @@ Inflate the tensor with constant or mirrored values on the edges.
72537253
enum MLPaddingMode {
72547254
"constant",
72557255
"edge",
7256-
"reflection",
7257-
"symmetric"
7256+
"reflection"
72587257
};
72597258

72607259
dictionary MLPadOptions : MLOperatorOptions {
@@ -7334,7 +7333,20 @@ partial dictionary MLOpSupportLimits {
73347333
1. If |beginningPadding|'s [=list/size=] and |endingPadding|'s [=list/size=] are not both equal to |input|'s [=MLOperand/rank=], then [=exception/throw=] a {{TypeError}}.
73357334
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}.
73367335
1. Let |outputShape| be a copy of |input|'s [=MLOperand/shape=].
7337-
1. [=list/For each=] |index| in [=the range=] 0 to |outputShape|'s [=MLOperand/rank=], exclusive:
7336+
1. [=list/For each=] |index| in [=the exclusive range|the range=] 0 to |outputShape|'s [=MLOperand/rank=], exclusive:
7337+
1. Switch on |options|.{{MLPadOptions/mode}}:
7338+
<dl class=switch>
7339+
: {{MLPaddingMode/"constant"}}
7340+
:: Do nothing.
7341+
7342+
: {{MLPaddingMode/"edge"}}
7343+
:: Do nothing.
7344+
7345+
: {{MLPaddingMode/"reflection"}}
7346+
::
7347+
1. If |beginningPadding|[|index|] is greater than or equal to |outputShape|[|index|], then [=exception/throw=] a {{TypeError}}.
7348+
1. If |endingPadding|[|index|] is greater than or equal to |outputShape|[|index|], then [=exception/throw=] a {{TypeError}}.
7349+
</dl>
73387350
1. Add to |outputShape|[|index|] the value of |beginningPadding|[|index|].
73397351
1. Add to |outputShape|[|index|] the value of |endingPadding|[|index|].
73407352
1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}.
@@ -7352,7 +7364,7 @@ partial dictionary MLOpSupportLimits {
73527364
<div class="example">
73537365
<details open>
73547366
<summary>
7355-
Examples for constant, edge, reflection and symmetric padding:
7367+
Examples for constant, edge, and reflection padding:
73567368
</summary>
73577369
<pre highlight="js">
73587370
// input: [[1,2,3], [4,5,6]]
@@ -7382,13 +7394,6 @@ partial dictionary MLOpSupportLimits {
73827394
// [6,5,4,5,6,5,4],
73837395
// [3,2,1,2,3,2,1]]
73847396
builder.pad(input, beginningPadding, endingPadding, {mode: 'reflection'});
7385-
7386-
// "symmetric" padded:
7387-
// [[2,1,1,2,3,3,2],
7388-
// [2,1,1,2,3,3,2],
7389-
// [5,4,4,5,6,6,5],
7390-
// [5,4,4,5,6,6,5]]
7391-
builder.pad(input, beginningPadding, endingPadding, {mode: 'symmetric'});
73927397
</pre>
73937398
</details>
73947399
</div>

0 commit comments

Comments
 (0)