-
Notifications
You must be signed in to change notification settings - Fork 53
Remove pool2d MLRoundingType - Simplify the operand layout support of conv2d and pooling 2d operations #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fdwr
wants to merge
21
commits into
webmachinelearning:main
Choose a base branch
from
fdwr:pool2dNoMLRoundingType
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3c9dd92
Remove pool2d MLRoundingType
fdwr ce04478
Merge with main
fdwr fdde61f
Delete lingering rounding type field definition
fdwr 2e35d5d
Bikeshed warnings
fdwr 8761da5
Make outputSizes required
fdwr 9a6bc2e
Merge with main
fdwr 84d78fe
Nit extra space after required
fdwr 54aacac
Revert required dictionary since it causes bikeshed errors
fdwr b330e18
Merge branch 'main' into pool2dNoMLRoundingType
fdwr 7a75fb9
Make options required
fdwr cc91b22
Merge branch 'main' into pool2dNoMLRoundingType
fdwr 01706bd
Merge branch 'main' into pool2dNoMLRoundingType
fdwr e4703cf
Merge branch 'main' into pool2dNoMLRoundingType
fdwr 4f4b6cf
Updates from review
fdwr 4439418
Add spec:infra to link-defaults
fdwr a78e74e
Remove optional from MLPool2dOptions
fdwr 58436c6
Remove stale algorithm steps after merge
fdwr 973acb1
Reformat instanceNormalization IDL snippet due to weirdly appearing o…
fdwr 8eb98f2
Add line numbers to linter
fdwr bc09e99
Extend line numbers to other parts, and show final message if everyth…
fdwr de2631c
Restore MLRoundingType
fdwr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,7 +871,7 @@ dictionary MLComputeResult { | |
interface MLContext { | ||
Promise<MLComputeResult> compute( | ||
MLGraph graph, MLNamedArrayBufferViews inputs, MLNamedArrayBufferViews outputs); | ||
|
||
MLOpSupportLimits opSupportLimits(); | ||
}; | ||
</script> | ||
|
@@ -5283,19 +5283,14 @@ partial dictionary MLOpSupportLimits { | |
### Pooling operations ### {#api-mlgraphbuilder-pool2d} | ||
Compute a pooling operation across all the elements within the moving window over the input tensor. | ||
<script type=idl> | ||
enum MLRoundingType { | ||
"floor", | ||
"ceil" | ||
}; | ||
|
||
dictionary MLPool2dOptions : MLOperatorOptions { | ||
sequence<[EnforceRange] unsigned long> windowDimensions; | ||
sequence<[EnforceRange] unsigned long> padding; | ||
sequence<[EnforceRange] unsigned long> strides; | ||
sequence<[EnforceRange] unsigned long> dilations; | ||
MLInputOperandLayout layout = "nchw"; | ||
MLRoundingType roundingType = "floor"; | ||
sequence<[EnforceRange] unsigned long> outputSizes; | ||
required sequence<[EnforceRange] unsigned long> outputSizes; | ||
}; | ||
|
||
partial interface MLGraphBuilder { | ||
|
@@ -5346,16 +5341,16 @@ partial dictionary MLOpSupportLimits { | |
- input tensor: *[batches, height, width, inputChannels]* | ||
- output tensor: *[batches, height, width, outputChannels]* | ||
|
||
: <dfn>roundingType</dfn> | ||
:: | ||
The rounding function used to compute the output shape. | ||
|
||
: <dfn>outputSizes</dfn> | ||
:: | ||
A list of length 2. | ||
Specifies the sizes of the two spacial dimensions of the output tensor. When the output sizes are explicitly specified, the {{MLPool2dOptions/roundingType}} is ignored. | ||
A list of length 2: *[outputHeight, outputWidth]* | ||
Specifies the sizes of the two spatial dimensions of the output tensor. | ||
|
||
If not specified, the output sizes are automatically computed. | ||
The spatial dimensions of the output tensor can be calculated as follows: | ||
|
||
*output size = ((input size - filter size + beginning padding + ending padding) / stride) + 1* | ||
|
||
Then the caller either applies a floor or ceiling depending on whether partial window results are desired. | ||
</dl> | ||
|
||
<div dfn-for="MLGraphBuilder/averagePool2d(input, options), MLGraphBuilder/l2Pool2d(input, options), MLGraphBuilder/maxPool2d(input, options)" dfn-type=argument> | ||
|
@@ -5366,13 +5361,8 @@ partial dictionary MLOpSupportLimits { | |
|
||
**Returns:** an {{MLOperand}}. The output 4-D tensor that contains the | ||
result of the reduction. The logical shape is interpreted according to the | ||
value of *layout*. More specifically, if the *options.roundingType* is {{MLRoundingType/"floor"}}, the spatial dimensions of the output tensor can be calculated as follows: | ||
|
||
`output size = floor(1 + (input size - filter size + beginning padding + ending padding) / stride)` | ||
|
||
or if *options.roundingType* is {{MLRoundingType/"ceil"}}: | ||
|
||
`output size = ceil(1 + (input size - filter size + beginning padding + ending padding) / stride)` | ||
value of *layout*, taking the batch and channel count from the input with | ||
the spatial sizes from *outputSizes*. | ||
</div> | ||
|
||
{{MLOpSupportLimits}} has the following members for pooling operations: | ||
|
@@ -5395,7 +5385,7 @@ partial dictionary MLOpSupportLimits { | |
|
||
<details open algorithm> | ||
<summary> | ||
To <dfn for=MLGraphBuilder>calculate pool2d output sizes</dfn> given {{MLInputOperandLayout}} |layout|, [=/list=] of 4 unsigned integers |inputShape|, {{MLRoundingType}} |roundingType|, [=/list=] of 2 unsigned integers |windowDimensions|, [=/list=] of 4 unsigned integers |padding|, [=/list=] of 2 unsigned integers |strides|, [=/list=] of 2 unsigned integers |dilations|, and optional [=/list=] of 2 unsigned integers |outputSizes|, perform these steps. They return a [=/list=] of 4 unsigned integers. | ||
To <dfn for=MLGraphBuilder>calculate pool2d output sizes</dfn> given {{MLInputOperandLayout}} |layout|, [=/list=] of 4 unsigned integers |inputShape|, [=/list=] of 2 unsigned integers <var ignore>windowDimensions</var>, [=/list=] of 4 unsigned integers <var ignore>padding</var>, [=/list=] of 2 unsigned integers <var ignore>strides</var>, [=/list=] of 2 unsigned integers <var ignore>dilations</var>, and optional [=/list=] of 2 unsigned integers |outputSizes|, perform these steps. They return a [=/list=] of 4 unsigned integers. | ||
</summary> | ||
1. Switch on |layout|: | ||
<dl class=switch> | ||
|
@@ -5404,21 +5394,7 @@ partial dictionary MLOpSupportLimits { | |
: {{MLInputOperandLayout/"nhwc"}} | ||
:: Let « |batches|, |inputHeight|, |inputWidth|, |channels| » be |inputShape|. | ||
</dl> | ||
1. If |outputSizes| is given, then let « |outputHeight|, |outputWidth| » be |outputSizes|. | ||
1. Otherwise: | ||
1. Let |outputSizes| be the result of [=MLGraphBuilder/calculating conv2d output sizes=] given |inputHeight|, |inputWidth|, |windowDimensions|[0], |windowDimensions|[1], |padding|, |strides|, and |dilations|. | ||
1. Let « |outputHeight|, |outputWidth| » be |outputSizes|. | ||
1. Switch on |roundingType|: | ||
huningxin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<dl class=switch> | ||
: {{MLRoundingType/"floor"}} | ||
:: | ||
1. Set |outputWidth| to floor(|outputWidth|). | ||
1. Set |outputHeight| to floor(|outputHeight|). | ||
: {{MLRoundingType/"ceil"}} | ||
:: | ||
1. Set |outputWidth| to ceiling(|outputWidth|). | ||
1. Set |outputHeight| to ceiling(|outputHeight|). | ||
</dl> | ||
1. Let « |outputHeight|, |outputWidth| » be |outputSizes|. | ||
fdwr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. Switch on |layout|: | ||
<dl class=switch> | ||
: {{MLInputOperandLayout/"nchw"}} | ||
|
@@ -5451,7 +5427,7 @@ partial dictionary MLOpSupportLimits { | |
1. If |options|.{{MLPool2dOptions/dilations}}'s [=list/size=] is not 2, then [=exception/throw=] a {{TypeError}}. | ||
1. If any value in |options|.{{MLPool2dOptions/dilations}} is not greater than 0, then [=exception/throw=] a {{TypeError}}. | ||
1. Let |desc| be a copy of |input|.{{MLOperand/[[descriptor]]}}. | ||
1. Let |outputShape| be the result of [=MLGraphBuilder/calculating pool2d output sizes=] given |options|.{{MLPool2dOptions/layout}}, |input|'s [=MLOperand/shape=], |options|.{{MLPool2dOptions/roundingType}}, |options|.{{MLPool2dOptions/windowDimensions}}, |options|.{{MLPool2dOptions/padding}}, |options|.{{MLPool2dOptions/strides}}, |options|.{{MLPool2dOptions/dilations}}, and |options|.{{MLPool2dOptions/outputSizes}} (if it [=map/exists=]). | ||
1. Let |outputShape| be the result of [=MLGraphBuilder/calculating pool2d output sizes=] given |options|.{{MLPool2dOptions/layout}}, |input|'s [=MLOperand/shape=], |options|.{{MLPool2dOptions/windowDimensions}}, |options|.{{MLPool2dOptions/padding}}, |options|.{{MLPool2dOptions/strides}}, |options|.{{MLPool2dOptions/dilations}}, and |options|.{{MLPool2dOptions/outputSizes}} (if it [=map/exists=]). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The outputSizes validation above in 13.2 doesn't appear to be correct--shouldn't it be similar to this logic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is now resolved by Joshua? |
||
1. If any [=list/item=] in |outputShape| is not a [=valid dimension=], then [=exception/throw=] a {{TypeError}}. | ||
1. Set |desc|.{{MLOperandDescriptor/shape}} to |outputShape|. | ||
1. *Make graph connections:* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.