Skip to content

Fix potential overflow in convert_image_dtype #3107

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

Merged
merged 1 commit into from
Dec 3, 2020

Conversation

fmassa
Copy link
Member

@fmassa fmassa commented Dec 3, 2020

We could have errors with convert_image_dtype such as

aten/src/ATen/native/cpu/PowKernel.cpp:41:5:  runtime error: 5.7896e+76 is outside the range of representable values of type 'float'

This fixes it for now, while we can't use torch.iinfo and torch.finfo in torchscript

We could have errors such as aten/src/ATen/native/cpu/PowKernel.cpp:41:5:  runtime error: 5.7896e+76 is outside the range of representable values of type 'float'

# int to float
# TODO: replace with dtype.is_floating_point when torchscript supports it
if torch.tensor(0, dtype=dtype).is_floating_point():
image = image.to(dtype)
return image / input_max

output_max = _max_value(dtype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear why moving this it fixes the errors. Shall I assume that the if statement is always activated in the problematic cases and thus you never end up executing this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the overflow only happens when dtype is floating point, so moving this after the conditional solves this

@fmassa fmassa merged commit dab4757 into pytorch:master Dec 3, 2020
@fmassa fmassa deleted the fix_convert_img_dtype_overflow branch December 3, 2020 18:40
vfdev-5 pushed a commit to Quansight/vision that referenced this pull request Dec 4, 2020
We could have errors such as aten/src/ATen/native/cpu/PowKernel.cpp:41:5:  runtime error: 5.7896e+76 is outside the range of representable values of type 'float'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants