I am loading a .pth model but when i try to print the params, it gives me error. error is in the image attached. please help if anyone( @ptrblck_de )knows how to remove this error

username: Aman_Chaurasia
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/7/c74a78fc8ba22c48519629e7be1347c7456a8c5c.png" data-download-href="https://discuss.pytorch.org/uploads/default/c74a78fc8ba22c48519629e7be1347c7456a8c5c" title="Screenshot (110)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/7/c74a78fc8ba22c48519629e7be1347c7456a8c5c_2_690x388.png" alt="Screenshot (110)" data-base62-sha1="sr0zyhZtoLiugPsgAkysocyl2Ta" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/7/c74a78fc8ba22c48519629e7be1347c7456a8c5c_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/7/c74a78fc8ba22c48519629e7be1347c7456a8c5c_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/7/c74a78fc8ba22c48519629e7be1347c7456a8c5c_2_1380x776.png 2x" data-dominant-color="EEEFEF"><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">Screenshot (110)</span><span class="informations">1920×1080 247 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>

username: Aman_Chaurasia
cooked: <p><span class="mention">@ptrblck_de</span> sir can you help</p>

username: RupertP
cooked: <p>You are using <code>model.eval()</code> which is used to evaluate your model. When using <code>model.eval()</code> Pytorch will not calculate gradients for your network. As the error clearly tells you params.grad is <code>None</code>. Therefore you have no gradients at that parameter and can’t continue with  <code>abs()</code> and <code>sum()</code>. I also don’t believe that even without the <code>model.eval</code> that you will get gradients without a Feedforward step</p>

username: ptrblck
cooked: <p><code>model.eval()</code> does not change the gradient calculation, but switches the behavior of some modules to evaluation mode, such as dropout (will be disabled) and batchnorm (will use the running stats instead of the batch stats).</p>
<p>However, as <a class="mention" href="/u/rupertp">@RupertP</a> explained, the <code>.grad</code> attributes are <code>None</code> after initializing the model and will just be populated after the first <code>backward</code> call.<br>
It seems you haven’t performed this step yet, so you would have to move the print statement after the first training iteration.</p>
<p>PS: You can post code snippets by wrapping them into three backticks ```, which makes debugging easier.</p>

username: Aman_Chaurasia
cooked: <p>how will i perform the first training iteration on a loaded model. sorry if it seems like a silly question. i am a bit new in this field and do not have deep knowledge</p>

username: ptrblck
cooked: <p>After creating the model instance and loading the checkpoint, you would have to perform a forward and backward pass using the model:</p>
<pre><code class="lang-python"># Model creation
model = MyModel()
# Checkpoint loading
model.load_state_dict(state_dict)
# Forward pass
output = model(data)
# Loss calculation
loss = criterion(output, target)
# Backward Pass
loss.backward()

# Now you can check the gradients
</code></pre>
<p>I would recommend to take a look at the <a href="https://pytorch.org/tutorials/">tutorials</a> which explain this workflow in more detail. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: Aman_Chaurasia
cooked: <p>output = model(data)<br>
what is data here?</p>

username: Aman_Chaurasia
cooked: <p>is data some dummy input?</p>

username: ptrblck
cooked: <p><code>data</code> would be whatever your model expects.<br>
If can be a random input for debugging or your real data created by a <code>Dataset</code>.</p>

username: Aman_Chaurasia
cooked: <p>i did that but i am still getting NoneType error</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3.png" data-download-href="https://discuss.pytorch.org/uploads/default/5bb98ff635419ae1af38b872832b3d3d68eaa1f3" title="Screenshot (111)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_690x388.png" alt="Screenshot (111)" data-base62-sha1="d5r0WRCzJAUUDVnIR80ho0FZSoz" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_1380x776.png 2x" data-dominant-color="EDEDED"><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">Screenshot (111)</span><span class="informations">1920×1080 278 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>

username: Aman_Chaurasia
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/6/2659aed397bc5639061f2c62053e2f06b64d9483.png" data-download-href="https://discuss.pytorch.org/uploads/default/2659aed397bc5639061f2c62053e2f06b64d9483" title="Screenshot (112)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/6/2659aed397bc5639061f2c62053e2f06b64d9483_2_690x388.png" alt="Screenshot (112)" data-base62-sha1="5tghTwH9MqS3DhAOmk144Ioey1J" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/6/2659aed397bc5639061f2c62053e2f06b64d9483_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/2/6/2659aed397bc5639061f2c62053e2f06b64d9483_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/2/6/2659aed397bc5639061f2c62053e2f06b64d9483_2_1380x776.png 2x" data-dominant-color="EFEFF0"><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">Screenshot (112)</span><span class="informations">1920×1080 278 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>

username: Aman_Chaurasia
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/d/fd559c2d19ee5c83feee65019bd8f1e6db6d40ce.png" data-download-href="https://discuss.pytorch.org/uploads/default/fd559c2d19ee5c83feee65019bd8f1e6db6d40ce" title="Screenshot (113)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fd559c2d19ee5c83feee65019bd8f1e6db6d40ce_2_690x388.png" alt="Screenshot (113)" data-base62-sha1="A96dyPpm4vS2ntd7KfkudQbzgOq" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fd559c2d19ee5c83feee65019bd8f1e6db6d40ce_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fd559c2d19ee5c83feee65019bd8f1e6db6d40ce_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fd559c2d19ee5c83feee65019bd8f1e6db6d40ce_2_1380x776.png 2x" data-dominant-color="EFEFF2"><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">Screenshot (113)</span><span class="informations">1920×1080 312 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>

username: Aman_Chaurasia
cooked: <p>i did that but i am still getting NoneType error<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3.png" data-download-href="https://discuss.pytorch.org/uploads/default/5bb98ff635419ae1af38b872832b3d3d68eaa1f3" title="Screenshot (111)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_690x388.png" alt="Screenshot (111)" data-base62-sha1="d5r0WRCzJAUUDVnIR80ho0FZSoz" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/5/b/5bb98ff635419ae1af38b872832b3d3d68eaa1f3_2_1380x776.png 2x" data-dominant-color="EDEDED"><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">Screenshot (111)</span><span class="informations">1920×1080 278 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>

username: Aman_Chaurasia
cooked: <p>Can you please help sir regarding this error?</p>

username: Mughees
cooked: <p>Please post the code here, instead of a screenshot.</p>
<p>Secondly, the error is in the MSE loss. What is the target in your code, I don’t see any of its definition. It seems that shape of the output and target going into the MSE loss is not consistent.</p>

username: Nikronic
cooked: <p>I did not want to mention this, but I have to.<br>
When you ask a question and you expect other members spend time to help you, they expect same thing. So, you can help others by using properly formatted code instead of screen shots, providing relevant data such as stack trace instead of just final error, not mentioning specific members as discourages other people, wrapping relevant issues into single post rather than chat form, etc or most important thing, reading community guidelines and intro tutorials.<br>
In your case, I suggest you to first read the <a href="https://discuss.pytorch.org/faq">faqs</a> and complete the basic user tutorial of forum <a href="https://meta.discourse.org/t/new-users-arent-starting-the-discobot-tutorial/62995/68" rel="nofollow noopener">Discourse</a>.</p>
<p>Bests</p>