Skip to content

Limited support for pad on CoreML backend #739

@philloooo

Description

@philloooo

pad is implemented on CoreML backend but with lots of constraints.
On CoreML (See doc), three modes are supported - constant, reflect, replicate(maps to edge mode).

  1. symmetric mode is not supported (On tflite backend, edge mode is not supported.)
  2. padding for more than the last two dimensions only supports 'constant' mode. (not documented, but it errors out with this message). One of the webnn samples - Fast style transfer need to use >2D padding for reflect mode.
  3. If mode is “reflect” then beginning and ending paddings can be at most input size-1 (same as tensorflow).
  4. If mode is “replicate” (aka edge) then beginning and ending paddings can be at most input size.

For the third constraint, we can probably update the spec to add such constraint? #377

For the others, my first question is - @fdwr @huningxin are there reasonable emulations for these unsupported modes and rank limits?

Further questions are - @mwyrzykowski do you think if CoreML can improve pad support with:

  • Add support for symmetric mode
  • Support padding for more than two dimensions for none constant mode.
  • Remove the padding value constraints for 'replicate' modes since it doesn't make much sense, it only uses the edge values to replicate.

If none of the restrictions can be emulated / nor supported by CoreML, we will need to either:
a. Add these constraints to WebNN API.
b. Expose the modes limits through opSupportLimits. The rank constraints are tricky to expose - as it varies by mode.
c. Just let them fail on CoreML with async error messages.. - Not ideal for browser compatibility.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions