<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto">When <code class="notranslate">torch.Tensor</code> is divided by <strong>zero tensors</strong> with data type as <strong>int</strong>, including <strong>int8</strong>, <strong>int32</strong>, <strong>int64</strong>, the program is terminated forcibly and throw <strong>Floating point exception (core dumped) error</strong>.<br>
If run the code in jupyter notebook, the kernel would be killed.</p>
<p dir="auto">Based on my experiments,  the bug happens both in torch 1.0 and torch 1.4.</p>
<p dir="auto">However, the bug would not happen if the dividend is not <code class="notranslate">torch.Tensor</code>.</p>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto"><code class="notranslate">torch.ones(3, dtype=torch.int8) / torch.zeros(3, dtype=torch.int8)</code></p>

<h2 dir="auto">Expected behavior</h2>
<ol dir="auto">
<li><code class="notranslate">ZeroDivisionError: division by zero</code>, which is the common bahavior in python when the divisor is zero.<br>
or</li>
<li>get <code class="notranslate">tensor(nan)</code>. (when the data type is float, such as <code class="notranslate">torch.zeros(3, dtype=torch.float64) / torch.zeros(3, dtype=torch.float64)</code>)<br>
or</li>
<li>get <strong>a tensor with very large value</strong>. (when the dividend is an integer or float, such as <code class="notranslate">1 / torch.zeros(3, dtype=torch.int8))</code>)</li>
</ol>
<h2 dir="auto">Environment</h2>
<p dir="auto">PyTorch version: 1.0.1.post2<br>
Is debug build: No<br>
CUDA used to build PyTorch: 9.0.176</p>
<p dir="auto">OS: Ubuntu 16.04.5 LTS<br>
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609<br>
CMake version: version 3.6.3</p>
<p dir="auto">Python version: 3.6<br>
Is CUDA available: Yes<br>
CUDA runtime version: Could not collect<br>
GPU models and configuration:<br>
GPU 0: TITAN Xp<br>
GPU 1: TITAN Xp<br>
GPU 2: TITAN Xp<br>
GPU 3: TITAN Xp</p>
<p dir="auto">Nvidia driver version: 384.145<br>
cuDNN version: Could not collect</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip] numpy==1.16.0<br>
[pip] numpydoc==0.6.0<br>
[pip] torch==1.0.1.post2<br>
[pip] torchsummary==1.5.1<br>
[pip] torchvision==0.2.1<br>
[conda] blas                      1.0                         mkl    <a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free" rel="nofollow">https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free</a><br>
[conda] cuda90                    1.0                  h6433d27_0    pytorch<br>
[conda] mkl                       2019.1                      144    defaults<br>
[conda] mkl-include               2019.1                      144    defaults<br>
[conda] mkl-service               1.1.2                    py36_3    <a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free" rel="nofollow">https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free</a><br>
[conda] pytorch                   0.4.0           py36_cuda9.0.176_cudnn7.1.2_1  [cuda90]  <a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch" rel="nofollow">https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch</a><br>
[conda] torch                     1.0.1.post2               <br>
[conda] torchsummary              1.5.1                     <br>
[conda] torchvision               0.2.1                     <br>
[conda] torchvision               0.2.1                      py_2    <a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch" rel="nofollow">https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch</a></p>
<h2 dir="auto">Additional context</h2>

<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a></p>
<p dir="auto">This seems to be an issue with TH and not pytorch, the same thing happens in lua torch.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import torch
a = torch.IntTensor([0,1])
b = torch.IntTensor([0,1])
print(a.div(b)) # Floating point exception (core dumped)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-v">IntTensor</span>([<span class="pl-c1">0</span>,<span class="pl-c1">1</span>])
<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-v">IntTensor</span>([<span class="pl-c1">0</span>,<span class="pl-c1">1</span>])
<span class="pl-en">print</span>(<span class="pl-s1">a</span>.<span class="pl-en">div</span>(<span class="pl-s1">b</span>)) <span class="pl-c"># Floating point exception (core dumped)</span></pre></div>
<p dir="auto">Another unrelated weirdness happens with float tensors when the answer is <code class="notranslate">inf</code></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import torch
a = torch.FloatTensor([1,1])
b = torch.FloatTensor([0,0])
a.div(b)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-v">FloatTensor</span>([<span class="pl-c1">1</span>,<span class="pl-c1">1</span>])
<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-v">FloatTensor</span>([<span class="pl-c1">0</span>,<span class="pl-c1">0</span>])
<span class="pl-s1">a</span>.<span class="pl-en">div</span>(<span class="pl-s1">b</span>)</pre></div>
<p dir="auto">which works on lua torch, but gives</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;repr(&lt;torch.FloatTensor at 0x7f8a012eee18&gt;) failed: RuntimeError: inconsistent tensor size at /tmp/pip-zh0a53-build/torch/lib/TH/generic/THTensorMath.c:90&gt;"><pre class="notranslate"><code class="notranslate">&lt;repr(&lt;torch.FloatTensor at 0x7f8a012eee18&gt;) failed: RuntimeError: inconsistent tensor size at /tmp/pip-zh0a53-build/torch/lib/TH/generic/THTensorMath.c:90&gt;
</code></pre></div>
<p dir="auto">in pytorch.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a></p>