You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python interpreter died without Traceback when CPU Tensor divided by zero. #8079
There's no Traceback when a cpu tensor is divided by zero.
i.e.
$ python3
Python 3.6.5 (default, May 11 2018, 13:30:17)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> a = torch.LongTensor([1,2]).cuda()
>>> a/0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: invalid argument 3: divide by zero at /pytorch/aten/src/THC/generic/THCTensorMathPairwise.cu:88
>>> a = torch.LongTensor([1,2])
>>> a/0
Floating point exception #######No Traceback, just exit without any indication.
$ echo $?
136
If there is no Traceback, it will be difficult to locate the bugs.
What about raising an exception instead of just aborting ?
Environment:
Python 3.6 provided by Debian Testing, PyTorch 0.4.0 installed with pip3 (pytorch compiled from source has the same behavior), CUDA 9.1, cudnn 7.1.
dividing an Integer Tensor by an integer 0 (as opposed to Float Tensor divided by 0.0) will lead to this exception. This is not easily catchable (last I looked) at a global level.
Closing this as wontfix, because the amount of effort is really large to justify (full audit of all core libraries and replacing all integer division with a macro that branch-handles divide by zero).
As tricky as this may be to fix, it's still a bug in a very real sense. Allowing C errors to creep into Python code is the result of a leaky abstraction.
@samuela i completely agree. Unfortunately there's no easy fix. We cant set a signal trap, or catch an exception in C land to catch a Floating point exception. The only solution is to actually never do an integer divide by zero, so the entire set of C kernels have to guard against this.
Activity
soumith commentedon Jun 4, 2018
dividing an Integer Tensor by an integer 0 (as opposed to Float Tensor divided by 0.0) will lead to this exception. This is not easily catchable (last I looked) at a global level.
See:
https://stackoverflow.com/a/3105604
https://stackoverflow.com/a/6121690
Closing this as
wontfix, because the amount of effort is really large to justify (full audit of all core libraries and replacing all integer division with a macro that branch-handles divide by zero).samuela commentedon Jul 18, 2018
As tricky as this may be to fix, it's still a bug in a very real sense. Allowing C errors to creep into Python code is the result of a leaky abstraction.
soumith commentedon Jul 18, 2018
@samuela i completely agree. Unfortunately there's no easy fix. We cant set a signal trap, or catch an exception in C land to catch a Floating point exception. The only solution is to actually never do an integer divide by zero, so the entire set of C kernels have to guard against this.
samuela commentedon Jul 18, 2018
@soumith Understood, and I don't think this bug is the worst thing in the world to be completely honest.
FWIW I tried this in TF and they do catch these errors. I'm not sure of their implementation details though.
produces
fmassa commentedon Jul 18, 2018
@samuela can you try to see what happens if the divisor is a
tf.constantas well, potentially with more than one element?samuela commentedon Jul 18, 2018
@fmassa
is mostly the same:
and
is also basically the same: