[go: nahoru, domu]

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

Pad function wrap mode #70269

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mattbahr
Copy link
Contributor
@mattbahr mattbahr commented Jun 24, 2024

Relates to #57672

I've added wrap padding as an option to the pad function. Much of the code I carried over from the MirrorPad op. The main difference between the two implementations is the ToInputCoord function:

https://github.com/mattbahr/tensorflow/blob/4833ab97fc7cbdabef6be49d621084930800c4a8/tensorflow/core/kernels/wrap_pad_op.h#L273-L284

EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index ToInputCoord(Index k,
int dim) const {
const Index m = impl_.dimensions()[dim];
k -= padding_[dim].first;
if (k < 0) {
return -k + left_offset_;
}
if (k < m) {
return k;
}
return m - (k - m) + right_offset_;
}

An alternative to this solution could be to update the MirrorPad op to handle WRAP mode on top of REFLECT and SYMMETRIC. This would eliminate the duplicated code and not require the maintenance of a brand new op, but I wasn't sure if that might be increasing the scope of that op beyond what it should be.

This implementation works as is on CPU and GPU. I haven't gotten to TPU or XLA yet.

See the NumPy documentation for how padding should work in wrap mode: https://numpy.org/doc/stable/reference/generated/numpy.pad.html

@google-ml-butler google-ml-butler bot added the size:L CL Change Size: Large label Jun 24, 2024
@google-ml-butler google-ml-butler bot added the awaiting review Pull request awaiting review label Jun 24, 2024
@gbaned gbaned added this to Assigned Reviewer in PR Queue via automation Jun 25, 2024
@gbaned gbaned removed the awaiting review Pull request awaiting review label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L CL Change Size: Large
Projects
PR Queue
  
Assigned Reviewer
Development

Successfully merging this pull request may close these issues.

None yet

2 participants