Closed tklausen closed 4 months ago
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
This pull request has been merged in pytorch/opacus@32a465bfa980777e60a763616c83429785aa2ac6.
Thanks for the fix @tklausen :)
Types of changes
Motivation and Context / Related issue
The function
filter_dilated_rows
intensor_utils.py
converts a tensor to an ndarray, modifies the ndarray, and converts the modified ndarray back to a tensor.Bug: If the original tensor is not on the CPU, the conversion to ndarray will fail because tensor.cpu() is not called.
Fix: This PR directly modifies the tensor without ever converting it to an ndarray. This fixes the bug and is more efficient than the original implementation.
How Has This Been Tested (if it applies)
Manually tested with the example provided in the function's DocString.
Also,
filter_dilated_rows
is called if the dilation of a 3d convolution is not 1. Thus, this function is implicitly tested bytests/grad_samples/conv3d_test.py
.Checklist