Skip to content
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

Support "reflect" padding mode #326

Merged
merged 1 commit into from
Aug 25, 2024
Merged

Support "reflect" padding mode #326

merged 1 commit into from
Aug 25, 2024

Conversation

robertknight
Copy link
Owner

For efficiency and simplicity, reflection padding is only supported for the last
2 dimensions of the input. Any additional dimensions are treated as batch
dimensions which must have the same size in the input and output.

PyTorch has a constraint that the amount of padding must be less than the size
of a dimension, which is useful since it avoids the need for padding to wrap
around by taking an expensive modulus of the dimension size. NumPy however
allows wrap-around, and the example in the ONNX spec relies on this. In this
implementation, wrap-around is supported but it might be necessary to split the
cases in future for efficiency, to avoid a modulus in the common case where the
padding size is less than the dimension size.

For efficiency and simplicity, reflection padding is only supported for the last
2 dimensions of the input. Any additional dimensions are treated as batch
dimensions which must have the same size in the input and output.

PyTorch has a constraint that the amount of padding must be less than the size
of a dimension, which is useful since it avoids the need for padding to wrap
around by taking an expensive modulus of the dimension size. NumPy however
allows wrap-around, and the example in the ONNX spec relies on this. In this
implementation, wrap-around is supported but it might be necessary to split the
cases in future for efficiency, to avoid a modulus in the common case where the
padding size is less than the dimension size.
@robertknight robertknight marked this pull request as ready for review August 25, 2024 11:55
@robertknight robertknight merged commit 5ce30bc into main Aug 25, 2024
2 checks passed
@robertknight robertknight deleted the pad-reflect branch August 25, 2024 11:55
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.

1 participant