Hi, I got a strange error when I load my saved model

lightly: <p>After training, I saved my model with following code:</p>
<pre><code class="lang-auto">state = {'value_net1': agent.value_net1.state_dict(),
         'value_optimizer1': agent.value_optimizer1.state_dict(),
         'value_net2': agent.value_net2.state_dict(),
         'value_optimizer2': agent.value_optimizer2.state_dict(),
         'q_approximation': agent.q_approximation.state_dict(),
         'q_optimizer': agent.q_optimizer.state_dict(),
         }
torch.save(state, self.output_path + 'epi{}_{}.pkl'.format(self.episode_number,name))
</code></pre>
<p>then I need to load the data with sentence:</p>
<pre><code class="lang-auto">checkpoint = torch.load(path_of_data, map_location=torch.device('cpu'))

</code></pre>
<p>I got an error:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/5/a58dd06bb080454703b95833cfa5e476d0a24c2e.png" data-download-href="https://discuss.pytorch.org/uploads/default/a58dd06bb080454703b95833cfa5e476d0a24c2e" title="微信截图_20220818222333"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/5/a58dd06bb080454703b95833cfa5e476d0a24c2e_2_690x160.png" alt="微信截图_20220818222333" data-base62-sha1="nCyCjGzRN4q94hb2U3VB9xtS8ua" width="690" height="160" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/5/a58dd06bb080454703b95833cfa5e476d0a24c2e_2_690x160.png, https://discuss.pytorch.org/uploads/default/optimized/3X/a/5/a58dd06bb080454703b95833cfa5e476d0a24c2e_2_1035x240.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/a/5/a58dd06bb080454703b95833cfa5e476d0a24c2e.png 2x" data-dominant-color="F2F2F5"><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">微信截图_20220818222333</span><span class="informations">1136×264 32.6 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>
It is really strange. I alway save and load my model in this way, but I never got an error. I don’t know what wrong with my code this time.</p>

ptrblck: <p>I’m unsure what’s causing the error as I cannot reproduce it locally by trying to pass invalid inputs to <code>torch.load</code>. Could you check what <code>path_of_data</code> contains?</p>

lightly: <p>Thank you for your reply!  I stored the variable “state”  in the data_path. the “state”  is a dictionary variable, which includes three model : value_net1,value_net2 and q_approximation, and their optimizers.</p>

ptrblck: <p>I cannot reproduce the issue using some random modules and optimizers for the mentioned classes:</p>
<pre><code class="lang-python">value_net1 = nn.Linear(1, 1)
value_optimizer1 = torch.optim.SGD(value_net1.parameters(), lr=1e-3)

value_net2 = nn.Linear(2, 2)
value_optimizer2 = torch.optim.SGD(value_net2.parameters(), lr=1e-3)

q_approximation = nn.Linear(3, 3)
q_optimizer = torch.optim.SGD(q_approximation.parameters(), lr=1e-3)


state = {'value_net1': value_net1.state_dict(),
         'value_optimizer1': value_optimizer1.state_dict(),
         'value_net2': value_net2.state_dict(),
         'value_optimizer2': value_optimizer2.state_dict(),
         'q_approximation': q_approximation.state_dict(),
         'q_optimizer': q_optimizer.state_dict(),
         }
torch.save(state, "tmp.pt")

checkpoint = torch.load("tmp.pt")
</code></pre>
<p>and can properly load the checkpoint.</p>

lightly: <p>Thank you! Maybe there is  something  wrong with my model. But what strange is that these model perform welI during training, and can be saved. I seems need to check my models again. thank you again!</p>