Large difference in the expected output of training

ran_ran1: <p>I am sorry to ask again but really I need to get answer to know if there is a wrong:<br>
When I call the train method for a previously executed code I get different and large values of train_loss and val_score compared to the expected output<br>
I only modified num_workers=0 instead of num_workers=2 and in loss_function I put reduction=‘sum’ /‘mean’ instead of size_average=false and train_loss += loss.item() instead of train_loss += loss.data[0]<br>
this is what I got:<br>
====&gt; Epoch 1 | Train time: 22280.0055 ms| End time: 30543.6549 ms | Train loss: 124908514341585682432.0000 | Val loss: 157350129654111232.0000<br>
====&gt; Epoch 2 | Train time: 32893.7201 ms| End time: 41595.8421 ms | Train loss: 124899982131354140672.0000 | Val loss: 157340963977348576.0000<br>
====&gt; Epoch 3 | Train time: 5325.6693 ms| End time: 9422.5409 ms | Train loss: 124891590658610954240.0000 | Val loss: 157332308998118176.0000<br>
====&gt; Epoch 4 | Train time: 4294.8182 ms| End time: 11010.9062 ms | Train loss: 124882917710891057152.0000 | Val loss: 157323412109530400.0000<br>
====&gt; Epoch 5 | Train time: 3687.0134 ms| End time: 9978.2672 ms | Train loss: 124873804958520049664.0000 | Val loss: 157314125478089088.0000<br>
====&gt; Epoch 6 | Train time: 3680.8324 ms| End time: 10421.0193 ms | Train loss: 124863944538242154496.0000 | Val loss: 157304785089012768.0000<br>
====&gt; Epoch 7 | Train time: 3582.6883 ms| End time: 10224.6709 ms | Train loss: 124853644313313148928.0000 | Val loss: 157295431260527744.0000<br>
…<br>
and this is what I should get:<br>
===&gt; Epoch 1 | Train time: 1698.5452 ms| End time: 3036.2639 ms | Train loss: 29.3311 | Val loss: 18.4107<br>
====&gt; Epoch 2 | Train time: 1537.3888 ms| End time: 2866.3790 ms | Train loss: 23.3025 | Val loss: 18.3386<br>
====&gt; Epoch 3 | Train time: 1542.4740 ms| End time: 2884.9881 ms | Train loss: 23.2476 | Val loss: 16.7314<br>
====&gt; Epoch 4 | Train time: 1525.3885 ms| End time: 2869.0510 ms | Train loss: 22.8955 | Val loss: 17.5893<br>
====&gt; Epoch 5 | Train time: 1539.6032 ms| End time: 2873.3907 ms | Train loss: 21.6304 | Val loss: 16.0720<br>
====&gt; Epoch 6 | Train time: 1496.8140 ms| End time: 2832.1874 ms | Train loss: 21.3513 | Val loss: 16.0074<br>
====&gt; Epoch 7 | Train time: 1514.0126 ms| End time: 2854.8751 ms | Train loss: 20.4407 | Val loss: 15.8153<br>
this is the code<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/d/1dcdbe2435ec673e911e1c8ba0f7b412a31de86a.png" data-download-href="https://discuss.pytorch.org/uploads/default/1dcdbe2435ec673e911e1c8ba0f7b412a31de86a" title="dd"><img src="https://discuss.pytorch.org/uploads/default/original/3X/1/d/1dcdbe2435ec673e911e1c8ba0f7b412a31de86a.png" alt="dd" data-base62-sha1="4fEEcza9io3aKIrihs2WvX8G33k" width="627" height="500" data-dominant-color="F9F9F9"><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">dd</span><span class="informations">1198×955 44.9 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></p>

ptrblck: <p>Your post doesn’t contain enough information and an increase in the loss value might be expected based on these changes:</p>
<aside class="quote no-group" data-username="ran_ran1" data-post="1" data-topic="162318">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ran_ran1/48/46541_2.png" class="avatar"> ran_ran1:</div>
<blockquote>
<p>I only modified num_workers=0 instead of num_workers=2 and in loss_function I put reduction=‘sum’ /‘mean’ instead of size_average=false and train_loss += loss.item() instead of train_loss += loss.data[0]</p>
</blockquote>
</aside>
<p>It’s however unclear to me what exactly this means, so please post a minimal, executable code snippet by wrapping it into three backticks, which would reproduce the issue.</p>

ran_ran1: <p>sorry if the question is not clear enough.what does I mean is that:<br>
I had to make the following changes to the pre-existing code due to using a newer version of the libraries:<br>
num_workers=0 instead of num_workers=2</p>
<blockquote>
<p>input_trainLoader = torch.utils.data.DataLoader(input_trainn, batch_size=args.batch_size, shuffle=False, num_workers=0)<br>
pad_index_trainLoader = torch.utils.data.DataLoader(pad_index_trainn, batch_size=args.batch_size, shuffle=False, num_workers=0)</p>
</blockquote>
<p>and put reduction=‘sum’ instead of size_average=‘false’</p>
<blockquote>
<p>def loss_function(recon_x, x, pad_index):<br>
MSE = F.mse_loss(recon_x<em>pad_index, x</em>pad_index, reduction=‘sum’)<br>
return MSE</p>
</blockquote>
<p>and put loss.item()instead of loss.data[0]</p>
<blockquote>
<p>train_loss += loss.item()</p>
</blockquote>
<p>And I got results that are not only different, but very huge. My question is, can these results be considered correct and are a natural result of the modifications I made, so I can continue in the executing and comparing later or did one of these modifications negatively affected the results, for example, I should have used reduction=‘none’ instead of size_average=‘false’? is my modifications wrong?</p>

ran_ran1: <p>I am new here ,should I create new topic containing the edited question to get answer?or does not my edited question clear enough?</p>