-
Notifications
You must be signed in to change notification settings - Fork 51
Need clarify constraint of 'beginningPadding' and 'endingPadding' for pad operation in "reflection" and "symmetric" mode #377
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
Comments
Padding in principle isn't and shouldn't be limited to the input size - it just repeats as many times as needed to fill the gap: Now extended with extra repeated padding --> For example with DML_PADDING_OPERATOR_DESC, if you start with a 4D input tensor and pad with 8 trailing elements using DML_PADDING_MODE_REFLECTION, the reflection will occur more than once to yield 12 elements (notice the 8 elements have been repeated more than once).
It's generally the case for imaging API's and texture wrapping in OpenGL/D3D that reflection/mirroring repeats. Evidently though, TF appears limited here:
And PyTorch doesn't like it either:
So the questions are:
If the answers to both of these are no, then limiting the bounds seems reasonable (even if from a pure theory POV, it should just work as expected). |
@philloooo already shared the CoreML's constraints in #739 that
For TFLite, although it doesn't report error, but it gives different results than DirectML, e.g.
Limiting the padding size would give the consistent results across backends. The proposal makes sense to me. |
😳 Indeed, I'd rather give an error than silently dubious results.
Seems safer for now. If a model arises in the future that warrants supporting extended wrapping (mirrored tiling, like WebGPU and WebGL do), we can relax this restriction and emulate it where necessary... |
Decision from the 2025-04-24 W3C meeting was that we would:
Q: Should padding size restriction also apply to constant fills? (it seems unnecessary, but I don't know the limitations of TLLiteRT and CoreML. |
According to my test, WebNN TFLite and CoreML backends can set large padding size for constant mode. For example, a = [1, 2, 3]
pad(a, [100], [100], {mode: 'constant'}) // works on both TFLite and CoreML BTW, CoreML backend has padding size constraints (<= input size) for edge mode. a = [1, 2, 3]
pad(a, [3], [0], {mode: 'edge'}) // works
b = [1, 2, 3]
pad(b, [4], [0], {mode: 'edge'}) // fails with model compilation error |
When I implemented
pad
operation for WebNN-Baseline webmachinelearning/webnn-baseline#47, I found there would be missing constraints of 'beginningPadding' and 'endingPadding' in "reflection" and "symmetric" mode, I propose to add constraints likes below table. @huningxin @wchao1115 @fdwr PTAL, thanks.Reference:
The text was updated successfully, but these errors were encountered: