Fix GPU-CPU device mismatch error in util filter_dilated_rows #633
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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