-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Pytorch][Vulkan] Fix the implementation of aten::sum.dim_IntList
#111586
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/111586
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 02c3949 with merge base 2a40b7e ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
f6d2a6e
to
d0f5df9
Compare
Summary: The existing implementation of `aten::sum.dim_IntList` depends on the following steps: - store the items of arguments `opt_dim` in a `std::set<int64_t> dims_set;` - iterate through `dims_set` in the reverse order(i.e. from largest to smallest) and compute the sum for one designated dim in `sum_dim` But when `opt_dim` contains negative items and `keepdim==false`, the dimension iteration over the set will be messed up. For example, the existing implementation will fail at the test case `test_sum_dim({10, 7, 5}, {-1, -2});`. We fix the issue by invoking `int64_t dim_normalized = utils::normalize(d, self.dim());` to get normalized dim in the range [0, `self.dim()` - 1]. Moreover the existing TORCH_CHECK of the condition ``` d >= -self.dim() - 1 && d <= self.dim() ``` is wrong and fixed by ``` d >= -self.dim() && d < self.dim() ``` Test Plan: ``` [luwei@devbig984.prn1 /data/users/luwei/fbsource (04b08a835)]$ LD_LIBRARY_PATH=third-party/swiftshader/lib/linux-x64/ buck run fbcode/mode/dev-nosan //xplat/caffe2:pt_vulkan_api_test_bin -- --gtest_filter="*sum*" Building: finished in 0.1 sec (100%) 339/339 jobs, 0/339 updated Total time: 0.2 sec BUILD SUCCEEDED Running main() from third-party/googletest/1.11.0/googletest/googletest/src/gtest_main.cc Note: Google Test filter = *sum* [==========] Running 8 tests from 1 test suite. [----------] Global test environment set-up. [----------] 8 tests from VulkanAPITest [ RUN ] VulkanAPITest.cumsum [ OK ] VulkanAPITest.cumsum (105 ms) [ RUN ] VulkanAPITest.sum_invalid_inputs [ OK ] VulkanAPITest.sum_invalid_inputs (0 ms) [ RUN ] VulkanAPITest.sum_dim_2d [ OK ] VulkanAPITest.sum_dim_2d (145 ms) [ RUN ] VulkanAPITest.sum_dim_3d [ OK ] VulkanAPITest.sum_dim_3d (91 ms) [ RUN ] VulkanAPITest.sum_dim_4d [ OK ] VulkanAPITest.sum_dim_4d (89 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_2d [ OK ] VulkanAPITest.sum_dim_keepdim_2d (63 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_3d [ OK ] VulkanAPITest.sum_dim_keepdim_3d (135 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_4d [ OK ] VulkanAPITest.sum_dim_keepdim_4d (4 ms) [----------] 8 tests from VulkanAPITest (637 ms total) [----------] Global test environment tear-down [==========] 8 tests from 1 test suite ran. (637 ms total) [ PASSED ] 8 tests. ``` Reviewed By: yipjustin Differential Revision: D50442152 fbshipit-source-id: 85a671a405b64725edd2d89c7dce56ff3ef68e51
This pull request was exported from Phabricator. Differential Revision: D50442152 |
d0f5df9
to
02c3949
Compare
…111586) Summary: The existing implementation of `aten::sum.dim_IntList` depends on the following steps: - store the items of arguments `opt_dim` in a `std::set<int64_t> dims_set;` - iterate through `dims_set` in the reverse order(i.e. from largest to smallest) and compute the sum for one designated dim in `sum_dim` But when `opt_dim` contains negative items and `keepdim==false`, the dimension iteration over the set will be messed up. For example, the existing implementation will fail at the test case `test_sum_dim({10, 7, 5}, {-1, -2});`. We fix the issue by invoking `int64_t dim_normalized = utils::normalize(d, self.dim());` to get normalized dim in the range [0, `self.dim()` - 1]. Moreover the existing TORCH_CHECK of the condition ``` d >= -self.dim() - 1 && d <= self.dim() ``` is wrong and fixed by ``` d >= -self.dim() && d < self.dim() ``` Test Plan: ``` [luwei@devbig984.prn1 /data/users/luwei/fbsource (04b08a835)]$ LD_LIBRARY_PATH=third-party/swiftshader/lib/linux-x64/ buck run fbcode/mode/dev-nosan //xplat/caffe2:pt_vulkan_api_test_bin -- --gtest_filter="*sum*" Building: finished in 0.1 sec (100%) 339/339 jobs, 0/339 updated Total time: 0.2 sec BUILD SUCCEEDED Running main() from third-party/googletest/1.11.0/googletest/googletest/src/gtest_main.cc Note: Google Test filter = *sum* [==========] Running 8 tests from 1 test suite. [----------] Global test environment set-up. [----------] 8 tests from VulkanAPITest [ RUN ] VulkanAPITest.cumsum [ OK ] VulkanAPITest.cumsum (105 ms) [ RUN ] VulkanAPITest.sum_invalid_inputs [ OK ] VulkanAPITest.sum_invalid_inputs (0 ms) [ RUN ] VulkanAPITest.sum_dim_2d [ OK ] VulkanAPITest.sum_dim_2d (145 ms) [ RUN ] VulkanAPITest.sum_dim_3d [ OK ] VulkanAPITest.sum_dim_3d (91 ms) [ RUN ] VulkanAPITest.sum_dim_4d [ OK ] VulkanAPITest.sum_dim_4d (89 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_2d [ OK ] VulkanAPITest.sum_dim_keepdim_2d (63 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_3d [ OK ] VulkanAPITest.sum_dim_keepdim_3d (135 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_4d [ OK ] VulkanAPITest.sum_dim_keepdim_4d (4 ms) [----------] 8 tests from VulkanAPITest (637 ms total) [----------] Global test environment tear-down [==========] 8 tests from 1 test suite ran. (637 ms total) [ PASSED ] 8 tests. ``` Reviewed By: yipjustin Differential Revision: D50442152
…111586) Summary: The existing implementation of `aten::sum.dim_IntList` depends on the following steps: - store the items of arguments `opt_dim` in a `std::set<int64_t> dims_set;` - iterate through `dims_set` in the reverse order(i.e. from largest to smallest) and compute the sum for one designated dim in `sum_dim` But when `opt_dim` contains negative items and `keepdim==false`, the dimension iteration over the set will be messed up. For example, the existing implementation will fail at the test case `test_sum_dim({10, 7, 5}, {-1, -2});`. We fix the issue by invoking `int64_t dim_normalized = utils::normalize(d, self.dim());` to get normalized dim in the range [0, `self.dim()` - 1]. Moreover the existing TORCH_CHECK of the condition ``` d >= -self.dim() - 1 && d <= self.dim() ``` is wrong and fixed by ``` d >= -self.dim() && d < self.dim() ``` Test Plan: ``` [luwei@devbig984.prn1 /data/users/luwei/fbsource (04b08a835)]$ LD_LIBRARY_PATH=third-party/swiftshader/lib/linux-x64/ buck run fbcode/mode/dev-nosan //xplat/caffe2:pt_vulkan_api_test_bin -- --gtest_filter="*sum*" Building: finished in 0.1 sec (100%) 339/339 jobs, 0/339 updated Total time: 0.2 sec BUILD SUCCEEDED Running main() from third-party/googletest/1.11.0/googletest/googletest/src/gtest_main.cc Note: Google Test filter = *sum* [==========] Running 8 tests from 1 test suite. [----------] Global test environment set-up. [----------] 8 tests from VulkanAPITest [ RUN ] VulkanAPITest.cumsum [ OK ] VulkanAPITest.cumsum (105 ms) [ RUN ] VulkanAPITest.sum_invalid_inputs [ OK ] VulkanAPITest.sum_invalid_inputs (0 ms) [ RUN ] VulkanAPITest.sum_dim_2d [ OK ] VulkanAPITest.sum_dim_2d (145 ms) [ RUN ] VulkanAPITest.sum_dim_3d [ OK ] VulkanAPITest.sum_dim_3d (91 ms) [ RUN ] VulkanAPITest.sum_dim_4d [ OK ] VulkanAPITest.sum_dim_4d (89 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_2d [ OK ] VulkanAPITest.sum_dim_keepdim_2d (63 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_3d [ OK ] VulkanAPITest.sum_dim_keepdim_3d (135 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_4d [ OK ] VulkanAPITest.sum_dim_keepdim_4d (4 ms) [----------] 8 tests from VulkanAPITest (637 ms total) [----------] Global test environment tear-down [==========] 8 tests from 1 test suite ran. (637 ms total) [ PASSED ] 8 tests. ``` Reviewed By: yipjustin Differential Revision: D50442152
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…ytorch#111586) Summary: The existing implementation of `aten::sum.dim_IntList` depends on the following steps: - store the items of arguments `opt_dim` in a `std::set<int64_t> dims_set;` - iterate through `dims_set` in the reverse order(i.e. from largest to smallest) and compute the sum for one designated dim in `sum_dim` But when `opt_dim` contains negative items and `keepdim==false`, the dimension iteration over the set will be messed up. For example, the existing implementation will fail at the test case `test_sum_dim({10, 7, 5}, {-1, -2});`. We fix the issue by invoking `int64_t dim_normalized = utils::normalize(d, self.dim());` to get normalized dim in the range [0, `self.dim()` - 1]. Moreover the existing TORCH_CHECK of the condition ``` d >= -self.dim() - 1 && d <= self.dim() ``` is wrong and fixed by ``` d >= -self.dim() && d < self.dim() ``` Test Plan: ``` [luwei@devbig984.prn1 /data/users/luwei/fbsource (04b08a835)]$ LD_LIBRARY_PATH=third-party/swiftshader/lib/linux-x64/ buck run fbcode/mode/dev-nosan //xplat/caffe2:pt_vulkan_api_test_bin -- --gtest_filter="*sum*" Building: finished in 0.1 sec (100%) 339/339 jobs, 0/339 updated Total time: 0.2 sec BUILD SUCCEEDED Running main() from third-party/googletest/1.11.0/googletest/googletest/src/gtest_main.cc Note: Google Test filter = *sum* [==========] Running 8 tests from 1 test suite. [----------] Global test environment set-up. [----------] 8 tests from VulkanAPITest [ RUN ] VulkanAPITest.cumsum [ OK ] VulkanAPITest.cumsum (105 ms) [ RUN ] VulkanAPITest.sum_invalid_inputs [ OK ] VulkanAPITest.sum_invalid_inputs (0 ms) [ RUN ] VulkanAPITest.sum_dim_2d [ OK ] VulkanAPITest.sum_dim_2d (145 ms) [ RUN ] VulkanAPITest.sum_dim_3d [ OK ] VulkanAPITest.sum_dim_3d (91 ms) [ RUN ] VulkanAPITest.sum_dim_4d [ OK ] VulkanAPITest.sum_dim_4d (89 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_2d [ OK ] VulkanAPITest.sum_dim_keepdim_2d (63 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_3d [ OK ] VulkanAPITest.sum_dim_keepdim_3d (135 ms) [ RUN ] VulkanAPITest.sum_dim_keepdim_4d [ OK ] VulkanAPITest.sum_dim_keepdim_4d (4 ms) [----------] 8 tests from VulkanAPITest (637 ms total) [----------] Global test environment tear-down [==========] 8 tests from 1 test suite ran. (637 ms total) [ PASSED ] 8 tests. ``` Reviewed By: yipjustin Differential Revision: D50442152 Pull Request resolved: pytorch#111586 Approved by: https://github.com/yipjustin
Summary:
The existing implementation of
aten::sum.dim_IntList
depends on the following steps:opt_dim
in astd::set<int64_t> dims_set;
dims_set
in the reverse order(i.e. from largest to smallest) and compute the sum for one designated dim insum_dim
But when
opt_dim
contains negative items andkeepdim==false
, the dimension iteration over the set will be messed up. For example, the existing implementation will fail at the test casetest_sum_dim({10, 7, 5}, {-1, -2});
.We fix the issue by invoking
int64_t dim_normalized = utils::normalize(d, self.dim());
to get normalized dim in the range [0,self.dim()
- 1].Moreover the existing TORCH_CHECK of the condition
is wrong and fixed by
Test Plan:
Reviewed By: yipjustin
Differential Revision: D50442152