<p dir="auto">When I multiply two sliced tensors of different dtypes, the result is arbitrary. This happens silently without even a warning being printed. As this works fine in numpy I expected it to work in pytorch as well.<br>
Apparently, this can be avoided by making the slices contiguous.</p>
<p dir="auto">Here's a notebook for reproducing the behavior: <a href="https://gist.github.com/koelscha/4dc9255a83e39b36b1cf20afa3c6fa74">https://gist.github.com/koelscha/4dc9255a83e39b36b1cf20afa3c6fa74</a></p>
<p dir="auto">PS: I'm using pytorch 1.3.0</p>
<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>
<ul dir="auto">
<li>Addition of different data typed tensors after permute giving incorrect results.</li>
<li>Addition of same data typed tensors is fine</li>
<li>Addition of different datatyped tensors was not allowed in pytorch 1.2, so this never happened in 1.2 version.</li>
</ul>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">Steps to reproduce the behavior:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; t = torch.tensor([[1, 2], [5, 6]])
&gt;&gt;&gt; 
&gt;&gt;&gt; t1 = t.permute(1,0)
&gt;&gt;&gt; 
&gt;&gt;&gt; m = torch.tensor([[1.0], [2.0]])
&gt;&gt;&gt; 
&gt;&gt;&gt; 
&gt;&gt;&gt; t
tensor([[1, 2],
        [5, 6]])
&gt;&gt;&gt; t.dtype
torch.int64
&gt;&gt;&gt;
&gt;&gt;&gt; t1
tensor([[1, 5],
        [2, 6]])
&gt;&gt;&gt; t1.dtype
torch.int64
&gt;&gt;&gt;
&gt;&gt;&gt; m
tensor([[1.],
        [2.]])
&gt;&gt;&gt; m.dtype
torch.float32
&gt;&gt;&gt; 
&gt;&gt;&gt; t+m
tensor([[2., 3.],
        [7., 8.]])
&gt;&gt;&gt; 
&gt;&gt;&gt; t1+m
tensor([[2., 3.],
        [7., 8.]])
&gt;&gt;&gt; "><pre lang="&gt;&gt;&gt;" class="notranslate"><code class="notranslate">&gt;&gt;&gt; t = torch.tensor([[1, 2], [5, 6]])
&gt;&gt;&gt; 
&gt;&gt;&gt; t1 = t.permute(1,0)
&gt;&gt;&gt; 
&gt;&gt;&gt; m = torch.tensor([[1.0], [2.0]])
&gt;&gt;&gt; 
&gt;&gt;&gt; 
&gt;&gt;&gt; t
tensor([[1, 2],
        [5, 6]])
&gt;&gt;&gt; t.dtype
torch.int64
&gt;&gt;&gt;
&gt;&gt;&gt; t1
tensor([[1, 5],
        [2, 6]])
&gt;&gt;&gt; t1.dtype
torch.int64
&gt;&gt;&gt;
&gt;&gt;&gt; m
tensor([[1.],
        [2.]])
&gt;&gt;&gt; m.dtype
torch.float32
&gt;&gt;&gt; 
&gt;&gt;&gt; t+m
tensor([[2., 3.],
        [7., 8.]])
&gt;&gt;&gt; 
&gt;&gt;&gt; t1+m
tensor([[2., 3.],
        [7., 8.]])
&gt;&gt;&gt; 
</code></pre></div>
<h2 dir="auto">Expected behavior</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt;t1+m
 tensor([[2., 6.],
         [4., 8.]]"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt;t1+m
 tensor([[2., 6.],
         [4., 8.]]
</code></pre></div>
<h2 dir="auto">Environment</h2>
<p dir="auto">PyTorch version: 1.3.0<br>
Is debug build: No<br>
CUDA used to build PyTorch: 10.1.243</p>
<p dir="auto">OS: Ubuntu 16.04.6 LTS<br>
GCC version: (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609<br>
CMake version: Could not collect</p>
<p dir="auto">Python version: 3.6<br>
Is CUDA available: Yes<br>
CUDA runtime version: 10.1.243<br>
GPU models and configuration: GPU 0: GeForce GTX 1080 Ti<br>
Nvidia driver version: 418.87.01<br>
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.4.1</p>
<p dir="auto">Versions of relevant libraries:<br>
[pip3] numpy==1.17.3<br>
[pip3] torch==1.3.0<br>
[pip3] torchvision==0.4.1<br>
[conda] Could not collect</p>
<h2 dir="auto">Additional context</h2>
<p dir="auto">workaround:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt;t1 = t.permute(1,0).contiguous()

&gt;&gt;&gt; t1
tensor([[1, 5],
        [2, 6]])
&gt;&gt;&gt; m
tensor([[1.],
        [2.]])
&gt;&gt;&gt; t1+m
tensor([[2., 6.],
        [4., 8.]])
&gt;&gt;&gt; "><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt;t1 = t.permute(1,0).contiguous()

&gt;&gt;&gt; t1
tensor([[1, 5],
        [2, 6]])
&gt;&gt;&gt; m
tensor([[1.],
        [2.]])
&gt;&gt;&gt; t1+m
tensor([[2., 6.],
        [4., 8.]])
&gt;&gt;&gt; 
</code></pre></div>
<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>