<p dir="auto"><strong>pytorch version:</strong> '0.1.12_2'</p>
<p dir="auto">It is not so easy to describe the exact bug here, but I think it is sufficient to provide an example in which strange results can be reproduced.</p>
<p dir="auto">Use the serialised version of Tensor in the attachment. Then run this snippet (also included in the attachment)</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
import torch
from torch.autograd import Variable

x_restored = Variable(torch.load('x.pth'), requires_grad=False)
x_res_repeated = x_restored.repeat(10, 1)

print(x_restored.eq(x_res_repeated[0]).data.numpy().sum())
print(x_restored.eq(x_res_repeated[0]).data.sum())
print(x_restored.eq(x_res_repeated[0]).sum())
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-k">from</span> <span class="pl-s1">torch</span>.<span class="pl-s1">autograd</span> <span class="pl-k">import</span> <span class="pl-v">Variable</span>

<span class="pl-s1">x_restored</span> <span class="pl-c1">=</span> <span class="pl-v">Variable</span>(<span class="pl-s1">torch</span>.<span class="pl-en">load</span>(<span class="pl-s">'x.pth'</span>), <span class="pl-s1">requires_grad</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
<span class="pl-s1">x_res_repeated</span> <span class="pl-c1">=</span> <span class="pl-s1">x_restored</span>.<span class="pl-en">repeat</span>(<span class="pl-c1">10</span>, <span class="pl-c1">1</span>)

<span class="pl-en">print</span>(<span class="pl-s1">x_restored</span>.<span class="pl-en">eq</span>(<span class="pl-s1">x_res_repeated</span>[<span class="pl-c1">0</span>]).<span class="pl-s1">data</span>.<span class="pl-en">numpy</span>().<span class="pl-en">sum</span>())
<span class="pl-en">print</span>(<span class="pl-s1">x_restored</span>.<span class="pl-en">eq</span>(<span class="pl-s1">x_res_repeated</span>[<span class="pl-c1">0</span>]).<span class="pl-s1">data</span>.<span class="pl-en">sum</span>())
<span class="pl-en">print</span>(<span class="pl-s1">x_restored</span>.<span class="pl-en">eq</span>(<span class="pl-s1">x_res_repeated</span>[<span class="pl-c1">0</span>]).<span class="pl-en">sum</span>())</pre></div>
<p dir="auto">The output</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="3200
3200
Variable containing:
 128
[torch.ByteTensor of size 1]"><pre class="notranslate"><code class="notranslate">3200
3200
Variable containing:
 128
[torch.ByteTensor of size 1]
</code></pre></div>
<p dir="auto">I would expect the summation to return the same results regardless of whether we operate on numpy arrays, pytorch tensors or <code class="notranslate">Variable</code> holding a <code class="notranslate">Tensor</code> in the <code class="notranslate">data</code> field. (Which means it should return a Variable holding a Tensor with the right capacity to store the summed value.<br>
However, this is unfortunately not the case.</p>
<p dir="auto"><a href="https://github.com/pytorch/pytorch/files/1124295/bug_reproduce.zip">bug_reproduce.zip</a></p>
<p dir="auto">Test script:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import torch
from torch.autograd import Variable

byte_tensor = torch.ByteTensor(256)
byte_tensor[:] = 1
byte_variable = Variable(byte_tensor)
# The results should be the same, but actually not
print('byte_tensor.sum():')
print(byte_tensor.sum())
print('byte_variable.sum():')
print(byte_variable.sum())"><pre class="notranslate"><code class="notranslate">import torch
from torch.autograd import Variable

byte_tensor = torch.ByteTensor(256)
byte_tensor[:] = 1
byte_variable = Variable(byte_tensor)
# The results should be the same, but actually not
print('byte_tensor.sum():')
print(byte_tensor.sum())
print('byte_variable.sum():')
print(byte_variable.sum())
</code></pre></div>
<p dir="auto">Results:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="byte_tensor.sum():
256
byte_variable.sum():
Variable containing:
 0
[torch.ByteTensor of size 1]"><pre class="notranslate"><code class="notranslate">byte_tensor.sum():
256
byte_variable.sum():
Variable containing:
 0
[torch.ByteTensor of size 1]
</code></pre></div>
<p dir="auto">Looks like <code class="notranslate">ByteTensor</code> <strong>does handle overflow</strong> but <code class="notranslate">Variable(ByteTensor)</code> <strong>doesn't</strong>. Such inconsistency has caused some troubles when I'm calculating my model's accuracy.</p>