<h2 dir="auto">🐛 Bug</h2>
<p dir="auto">Product of ones is zero on cuda. This seems like a rather common issue, but i found no mentions of it here after a brief keyword search.</p>
<h2 dir="auto">To reproduce</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch
print(torch.__version__)
print(torch.prod(torch.ones(10 ** 6, device='cuda')))"><pre class="notranslate"><code class="notranslate">import torch
print(torch.__version__)
print(torch.prod(torch.ones(10 ** 6, device='cuda')))
</code></pre></div>
<p dir="auto">prints</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.0.1.post2
tensor(0., device='cuda:0')"><pre class="notranslate"><code class="notranslate">1.0.1.post2
tensor(0., device='cuda:0')
</code></pre></div>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">I'd expect it to be 1 :)</p>

<h2 dir="auto">Environment</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Collecting environment information...
PyTorch version: 1.0.1.post2
Is debug build: No
CUDA used to build PyTorch: 9.0.176

OS: Ubuntu 16.04.1 LTS
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
CMake version: version 3.5.1

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 9.0.176
GPU models and configuration: 
GPU 0: Tesla M40
GPU 1: Tesla M40
GPU 2: Tesla M40
GPU 3: Tesla M40

Nvidia driver version: 396.37
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.6.0.21
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.1.4

Versions of relevant libraries:
[pip] numpy==1.16.3
[pip] numpydoc==0.7.0
[pip] torch==1.0.1.post2
[pip] torchvision==0.2.1
[conda] blas                      1.0                         mkl  
[conda] faiss-gpu                 1.4.0           py36_cuda8.0.61_1    pytorch
[conda] mkl                       2018.0.1             h19d6760_4  
[conda] mkl-service               1.1.2            py36h17a0993_4  
[conda] pytorch                   1.0.1           py3.6_cuda8.0.61_cudnn7.1.2_2    pytorch
[conda] torch                     1.0.1.post2               &lt;pip&gt;
[conda] torchvision               0.2.1                      py_2    pytorch"><pre class="notranslate"><code class="notranslate">Collecting environment information...
PyTorch version: 1.0.1.post2
Is debug build: No
CUDA used to build PyTorch: 9.0.176

OS: Ubuntu 16.04.1 LTS
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
CMake version: version 3.5.1

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 9.0.176
GPU models and configuration: 
GPU 0: Tesla M40
GPU 1: Tesla M40
GPU 2: Tesla M40
GPU 3: Tesla M40

Nvidia driver version: 396.37
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.6.0.21
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.1.4

Versions of relevant libraries:
[pip] numpy==1.16.3
[pip] numpydoc==0.7.0
[pip] torch==1.0.1.post2
[pip] torchvision==0.2.1
[conda] blas                      1.0                         mkl  
[conda] faiss-gpu                 1.4.0           py36_cuda8.0.61_1    pytorch
[conda] mkl                       2018.0.1             h19d6760_4  
[conda] mkl-service               1.1.2            py36h17a0993_4  
[conda] pytorch                   1.0.1           py3.6_cuda8.0.61_cudnn7.1.2_2    pytorch
[conda] torch                     1.0.1.post2               &lt;pip&gt;
[conda] torchvision               0.2.1                      py_2    pytorch
</code></pre></div>
<h2 dir="auto">Additional context</h2>
<p dir="auto">This does not seem to be a floating point precision issue:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="print(torch.prod(torch.ones(130_560, device='cuda'), dim=0))
print(torch.prod(torch.ones(130_561, device='cuda'), dim=0))"><pre class="notranslate"><code class="notranslate">print(torch.prod(torch.ones(130_560, device='cuda'), dim=0))
print(torch.prod(torch.ones(130_561, device='cuda'), dim=0))
</code></pre></div>
<p dir="auto">prints</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tensor(1., device='cuda:0')
tensor(0., device='cuda:0')"><pre class="notranslate"><code class="notranslate">tensor(1., device='cuda:0')
tensor(0., device='cuda:0')
</code></pre></div>
<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">Potentially relates to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="394750037" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/15602" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/15602/hovercard" href="https://github.com/pytorch/pytorch/issues/15602">#15602</a>.</p>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">Steps to reproduce the behavior:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import torch
&gt;&gt;&gt; x = torch.ones([20, 30, 400], dtype=torch.uint8, device='cpu')
&gt;&gt;&gt; x.prod()
tensor(1)
&gt;&gt;&gt; x = torch.ones([20, 30, 400], dtype=torch.uint8, device='cuda')
&gt;&gt;&gt; x.prod()
tensor(0, device='cuda:0')"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">ones</span>([<span class="pl-c1">20</span>, <span class="pl-c1">30</span>, <span class="pl-c1">400</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">torch</span>.<span class="pl-s1">uint8</span>, <span class="pl-s1">device</span><span class="pl-c1">=</span><span class="pl-s">'cpu'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span>.<span class="pl-en">prod</span>()
<span class="pl-en">tensor</span>(<span class="pl-c1">1</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">ones</span>([<span class="pl-c1">20</span>, <span class="pl-c1">30</span>, <span class="pl-c1">400</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">torch</span>.<span class="pl-s1">uint8</span>, <span class="pl-s1">device</span><span class="pl-c1">=</span><span class="pl-s">'cuda'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span>.<span class="pl-en">prod</span>()
<span class="pl-en">tensor</span>(<span class="pl-c1">0</span>, <span class="pl-s1">device</span><span class="pl-c1">=</span><span class="pl-s">'cuda:0'</span>)</pre></div>
<p dir="auto">The results on small Tensors are correct:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; x = torch.ones([2, 3, 4], dtype=torch.uint8, device='cuda')
&gt;&gt;&gt; x.prod()
tensor(1, device='cuda:0')"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">ones</span>([<span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">torch</span>.<span class="pl-s1">uint8</span>, <span class="pl-s1">device</span><span class="pl-c1">=</span><span class="pl-s">'cuda'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span>.<span class="pl-en">prod</span>()
<span class="pl-en">tensor</span>(<span class="pl-c1">1</span>, <span class="pl-s1">device</span><span class="pl-c1">=</span><span class="pl-s">'cuda:0'</span>)</pre></div>

<h2 dir="auto">Expected behavior</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; x = torch.ones([20, 30, 400], dtype=torch.uint8, device='cuda')
&gt;&gt;&gt; x.prod()
tensor(1, device='cuda:0')"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">ones</span>([<span class="pl-c1">20</span>, <span class="pl-c1">30</span>, <span class="pl-c1">400</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">torch</span>.<span class="pl-s1">uint8</span>, <span class="pl-s1">device</span><span class="pl-c1">=</span><span class="pl-s">'cuda'</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">x</span>.<span class="pl-en">prod</span>()
<span class="pl-en">tensor</span>(<span class="pl-c1">1</span>, <span class="pl-s1">device</span><span class="pl-c1">=</span><span class="pl-s">'cuda:0'</span>)</pre></div>
<h2 dir="auto">Environment</h2>
<p dir="auto">PyTorch version: 1.1.0a0+a0d22b6<br>
Is debug build: No<br>
CUDA used to build PyTorch: 9.2.88</p>
<p dir="auto">OS: CentOS Linux 7 (Core)<br>
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)<br>
CMake version: version 3.12.2</p>
<p dir="auto">Python version: 3.7<br>
Is CUDA available: Yes<br>
CUDA runtime version: 9.2.88<br>
GPU models and configuration:<br>
GPU 0: Tesla M40<br>
GPU 1: Tesla M40</p>
<p dir="auto">Nvidia driver version: 396.26<br>
cuDNN version: Probably one of the following:<br>
/usr/local/fbcode/gcc-5-glibc-2.23/lib/libcudnn.so.6<br>
/usr/local/fbcode/gcc-5-glibc-2.23/lib/libcudnn.so.6.0.20<br>
/usr/local/fbcode/gcc-5-glibc-2.23/lib/libcudnn.so.6.0.21<br>
/usr/local/fbcode/gcc-5-glibc-2.23/lib/libcudnn.so.7.1.2<br>
/usr/local/fbcode/gcc-5-glibc-2.23/lib/libcudnn.so.7.1.4<br>
/usr/local/fbcode/platform007/lib/libcudnn.so.7.1.4</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip] numpy (1.15.4)<br>
[pip] torch (1.1.0a0+a0d22b6, /home/shenli/project/pytorch)<br>
[conda] blas                      1.0                         mkl<br>
[conda] mkl                       2019.1                      144<br>
[conda] mkl-include               2019.1                      144<br>
[conda] mkl_fft                   1.0.6            py37hd81dba3_0<br>
[conda] mkl_random                1.0.2            py37hd81dba3_0<br>
[conda] torch                     1.1.0a0+a0d22b6           </p>