Different result between Linux and Window

username: jerly-hjzhou
cooked: <p>I change a particular parameter in resent-18 and use it to infer the test set. And I got two extremely different result. I guess the reason is the difference of representation between Linux and Windows, but I’m not sure why is that. My question is what could I do to make these two results the same. The result in Linux is here<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/2/b/2bc478c7318cdc573622781cba9e0e6b499e3ca1.png" alt="image" data-base62-sha1="6fbt93fbqjb0yUY9Ku9F0sjzPA5" width="225" height="21"><br>
and Windows is here<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/4/f/4f538a9a5c724672bc018bd0009b4d823c8a3987.png" alt="image" data-base62-sha1="bjKHP2QDfdcDPbXEsj92kEqDYSr" width="359" height="52"><br>
The code in these two operating systems is almost the same (e.g. batch_size) except for  <code>num_work</code> in <code>DataLoader</code>. My code is below</p>
<pre><code class="lang-auto">import torch
from torchvision import datasets, transforms
import time
model = torch.load('resnet-18/resnet_18-cifar_10.pth')  # 加载模型
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

# in order to modify specific parameter
flag = 0
with torch.no_grad():
    for layerPara in model.parameters():
        if flag &lt; 3:
            flag = flag + 1
            continue
        layerPara[0][0][0][1] = -3e+37
        break

model.to(device)
model.eval()
accuracy = 0.0
correctNum = 0
data_transforms = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
image_datasets = datasets.CIFAR10(root='./data', train=False,
                                  download=True, transform=data_transforms)
test_loader = torch.utils.data.DataLoader(image_datasets, batch_size=250,
                                          shuffle=True, num_workers=0, prefetch_factor=2)
since = time.time()
for data, target in test_loader:
    data = data.to(device)
    target = target.to(device)
    output = model(data)
    pred = output.data.max(1, keepdim=True)[1]  # get the index of the max log-probability
    correctNum += pred.eq(target.data.view_as(pred)).cpu().sum()  # 对预测正确的数据个数进行累加
accuracy = correctNum / len(test_loader.dataset)
print("accuracy is {:.4f}%".format(accuracy * 100))
time_elapsed = time.time() - since
</code></pre>

username: eqy
cooked: <p>An accuracy of 13% suggests that something is either not initialized or there is a preprocessing mismatch between the models. Can you check both versions on a single input image and observe the outputs (even at intermediate parts of the model if necessary) to see where they differ?</p>

username: jerly-hjzhou
cooked: <p>Thank you for your reply. According to your idea, I change batch_size = 1 to calculate a single output.  I got two different outputs in these two OS. Linux is this<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/4/84631a2a6882045ed7094fed4e5d7221947c5c01.png" data-download-href="https://discuss.pytorch.org/uploads/default/84631a2a6882045ed7094fed4e5d7221947c5c01" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/8/4/84631a2a6882045ed7094fed4e5d7221947c5c01.png" alt="image" data-base62-sha1="iT9lNz6o5XfRcmio3biCHhEbekF" width="690" height="39" data-dominant-color="313232"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">814×47 3.44 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
and Windows is this<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/c/eced1cb37ce00f3d39218f59cd7bc2b74ac75f0c.png" data-download-href="https://discuss.pytorch.org/uploads/default/eced1cb37ce00f3d39218f59cd7bc2b74ac75f0c" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/c/eced1cb37ce00f3d39218f59cd7bc2b74ac75f0c.png" alt="image" data-base62-sha1="xNWGZnumSqe0pN2OTM115oYE3QE" width="690" height="68" data-dominant-color="ECECEC"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">774×77 9.77 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
Strangely, when I change the particular parameter in the code I post to 3e+37, both Linux and Windows have the same result.</p>

username: eqy
cooked: <p>You might want to check if the model parameters are loaded correctly in Windows. As a sanity check you can also try printing a few values of the input before it is passed to the model in both cases.</p>

username: jerly-hjzhou
cooked: <p>After the parameter is modified, I print the value and verify it. This problem is too confusing.</p>