-
Notifications
You must be signed in to change notification settings - Fork 26.3k
torch.histc added a finite range check to resolve segfaults if tensor has inf. also added checks for nan values, min>max #27712
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
| } | ||
|
|
||
| TORCH_CHECK(!(std::isinf(minval) || std::isinf(maxval)), "range of [", minval, ", ", maxval, "] is not finite"); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, let's also add the example from the issue to a unit test too
torch.histc added a finite range check to resolve torch.histc segfaults if tensor has inf
torch.histc added a finite range check to resolve torch.histc segfaults if tensor has inf
vadimkantorov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be fine for NaN?
|
@vadimkantorov good point! I added a check for that and it will throw an error for tensors with nan values in case a finite range is not specified |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look awesome! CI failure is likely unrelated, after rebasing and passing CI we should be good to go.
| } | ||
| TORCH_CHECK(!(std::isinf(minvalue) || std::isinf(maxvalue) || std::isnan(minvalue) || std::isnan(maxvalue)), "range of [", minvalue, ", ", maxvalue, "] is not finite"); | ||
| TORCH_CHECK(minvalue < maxvalue, "max must be larger than min"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows CI gives error:
15:26:54 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_math.h(409): error: more than one instance of overloaded function "fpclassify" matches the argument list:
15:26:54 SummaryOps.cu
15:26:54 function "fpclassify(float)"
15:26:54 function "fpclassify(double)"
15:26:54 function "fpclassify(long double)"
15:26:54 argument types are: (uint8_t)
15:26:54 detected during:
15:26:54 instantiation of "__nv_bool isinf(_Ty) [with _Ty=uint8_t]"
15:26:54 C:/Jenkins/workspace/pytorch-builds/pytorch-win-ws2016-cuda9-cudnn7-py3-build/aten/src/ATen/native/cuda/SummaryOps.cu(326): here
15:26:54 instantiation of "at::Tensor at::<unnamed>::_histc_cuda_template(const at::Tensor &, int64_t, input_t, input_t) [with input_t=uint8_t]"
15:26:54 C:/Jenkins/workspace/pytorch-builds/pytorch-win-ws2016-cuda9-cudnn7-py3-build/aten/src/ATen/native/cuda/SummaryOps.cu(357): here
To fix this issue, in this file I think we should write THCNumerics<input_t>::isinf(val) instead of std::isinf(val), and THCNumerics<input_t>::isnan(val) instead of std::isnan(val) (this is taken from
pytorch/aten/src/ATen/native/cuda/MultinomialKernel.cu
Lines 244 to 245 in 2432986
| assert(!THCNumerics<scalar_t>::isinf(val)); | |
| assert(!THCNumerics<scalar_t>::isnan(val)); |
). This only applies to CUDA code though, and we don't need to change the CPU code.
| TORCH_CHECK(!(THCNumerics<input_t>::isinf(minvalue) || THCNumerics<input_t>::isinf(maxvalue) || THCNumerics<input_t>::isnan(minvalue) || THCNumerics<input_t>::isnan(maxvalue)), "range of [", minvalue, ", ", maxvalue, "] is not finite"); | ||
| TORCH_CHECK(minvalue < maxvalue, "max must be larger than min"); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rocm build is failing with:
18:29:27 [ 87%] Linking CXX executable ../bin/generate_proposals_op_gpu_test
18:29:29 ../lib/libtorch.so: undefined reference to `isinf(float)'
18:29:29 ../lib/libtorch.so: undefined reference to `isnan(float)'
18:29:29 ../lib/libtorch.so: undefined reference to `isnan(double)'
18:29:29 ../lib/libtorch.so: undefined reference to `isinf(double)'
18:29:29 clang: �[0;1;31merror: �[0mlinker command failed with exit code 1 (use -v to see invocation)�[0m
To fix this, I think we need to #include <THC/THCNumerics.cuh> at the top of this file after #include <ATen/cuda/CUDAApplyUtils.cuh>, taking inspiration from the aten/src/ATen/native/cuda/MultinomialKernel.cu file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh okay 👌 thanks!!
| maxval = maxval + 1; | ||
| } | ||
|
|
||
| TORCH_CHECK(!(std::isinf(minval) || std::isinf(maxval) || std::isnan(minval) || std::isnan(maxval)), "range of [", minval, ", ", maxval, "] is not finite"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::isnan -> th_isnan
|
Current CI errors seem unrelated and we are ready to merge this PR :D |
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjali411 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
… has inf. also added checks for nan values, min>max (#27712) Summary: pytorch/pytorch#27464 Pull Request resolved: pytorch/pytorch#27712 Differential Revision: D18064544 Pulled By: anjali411 fbshipit-source-id: c9c6d8eb4d55f2b5320409ba238bf44b0be8902e
|
@anjali411 merged this pull request in 136bb07. |
|
@anjali411 this previously segfaulted right? so not BC-breaking? |
… has inf. also added checks for nan values, min>max (pytorch#27712) Summary: pytorch#27464 Pull Request resolved: pytorch#27712 Differential Revision: D18064544 Pulled By: anjali411 fbshipit-source-id: c9c6d8eb4d55f2b5320409ba238bf44b0be8902e
#27464