Skip to content

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
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

fdwr
Copy link
Collaborator

@fdwr fdwr commented Oct 23, 2024

Fixes #324

Rather than having two output shape parameters, an explicit output size and an output rounding mode, be more explicit in WebNN such that the caller passes the explicit output shape, resolving any higher-level policy beforehand (like with convTranspose2d):

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;
};

Additional changes:

  • Added spec:infra; type:dfn; text:string due to new build failures unrelated to my change (thanks Dominique).
  • Rewrapped instanceNormalization for linter error.
  • Update linter to display line numbers (save valuable time diagnosing errors) and display success message (rather than confusing silence).

Preview | Diff

@fdwr fdwr requested a review from huningxin November 15, 2024 23:31
index.bs Outdated
@@ -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=]).

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is now resolved by Joshua?

@inexorabletash
Copy link
Contributor

This implicitly resolves #374 as well, doesn't it?

@inexorabletash
Copy link
Contributor

inexorabletash commented Feb 25, 2025

This PR needs a redo since there's been a lot of spec churn since Nov 2024. But one thing I noticed in the current spec text:

If options.outputSizes exists, or if options.padding does not exist, set options.padding to the list « 0, 0, 0, 0 ».

That implies that if outputSizes becomes a required option, then any passed padding will always be ignored. Flaw in the current text? I think the first clause "if options.outputSizes exists" is bogus today, and should be removed.

@fdwr
Copy link
Collaborator Author

fdwr commented Jul 18, 2025

I'm confused by the build errors, as I didn't touch any of those lines, and [=string=] seems unrelated 🙃:

      LINE 1713:36: Multiple possible 'string' dfn refs.
      Arbitrarily chose https://infra.spec.whatwg.org/#string
      To auto-select one of the following refs, insert one of these lines into a <pre class=link-defaults> block:
      spec:infra; type:dfn; text:string
      spec:rdf12-concepts; type:dfn; text:string
      [=string=]

@dontcallmedom
Copy link
Contributor

the build error is indeed unrelated to the particular change, but linked to the definition set bikeshed uses for auto-linking.

the simplest short term solution is to add spec:infra; type:dfn; text:string in the existing <pre class="link-defaults"> on L50.

@fdwr
Copy link
Collaborator Author

fdwr commented Jul 19, 2025

@dontcallmedom Thanks, that helped. I encountered a few other random errors (some which were unrelated to my change 🙃), and so I had to extend the linter to display line numbers to save my sanity:

index.html:14723: Unexpected normative reference to [WEBNN]

@fdwr fdwr requested a review from huningxin July 21, 2025 18:19
@huningxin
Copy link
Contributor

From another perspective, would dropping roundingType prevent us from supporting dynamic shape (specifying the concrete input shape at the inference time) in the future? On native ML API side, both CoreML and ONNX supports ceil_mode which is same as PyTorch’s ceil mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify the operand layout support of conv2d and pooling 2d operations
7 participants