Unable to save the pytorch model using torch.jit.scipt

iamexperimentingnow: <p>Hi Team,</p>
<p>I’m trying to save the model after every epoch. Unfortunately, I’m unable to save and I’m getting the below error.</p>
<p>This is the git repo I’m using <a href="https://github.com/CSAILVision/semantic-segmentation-pytorch" class="inline-onebox" rel="noopener nofollow ugc">GitHub - CSAILVision/semantic-segmentation-pytorch: Pytorch implementation for Semantic Segmentation/Scene Parsing on MIT ADE20K dataset</a></p>
<p>in their train script, they are trying to save the model like below,</p>
<pre><code class="lang-auto">(net_encoder, net_decoder, crit) = nets

dict_encoder = net_encoder.state_dict()
dict_decoder = net_decoder.state_dict()

  torch.save(
      dict_encoder,
      '{}/encoder_epoch_{}.pth'.format(cfg.DIR, epoch))
  torch.save(
      dict_decoder,
      '{}/decoder_epoch_{}.pth'.format(cfg.DIR, epoch))
</code></pre>
<p>however, I have changed those bits to torch script manner like below,</p>
<pre><code class="lang-auto">scripted_encoder = torch.jit.script(net_encoder)
scripted_encoder.save('encoder_scripted.pt') 

scripted_decoder = torch.jit.script(net_decoder)
scripted_decoder.save('decoder_scripted.pt') 
</code></pre>
<p>when I try to save the model as torch script way, I get the following error.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/4/c43c7269a89298a765a5980f3507526948ac4196.png" data-download-href="https://discuss.pytorch.org/uploads/default/c43c7269a89298a765a5980f3507526948ac4196" title="Screenshot from 2022-06-17 00-56-52"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c43c7269a89298a765a5980f3507526948ac4196_2_690x388.png" alt="Screenshot from 2022-06-17 00-56-52" data-base62-sha1="rZZ5EmRW7U5tWPtmBQNVa0ASNOC" width="690" height="388" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c43c7269a89298a765a5980f3507526948ac4196_2_690x388.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c43c7269a89298a765a5980f3507526948ac4196_2_1035x582.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c43c7269a89298a765a5980f3507526948ac4196_2_1380x776.png 2x" data-dominant-color="535253"><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 from 2022-06-17 00-56-52</span><span class="informations">1920×1080 333 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>
<p><a class="mention" href="/u/ptrblck">@ptrblck</a>  <a class="mention" href="/u/ppwwyyxx">@ppwwyyxx</a> could you please help me to solve this issue and save the model using torch script.</p>
<h2><a name="sytem-details-1" class="anchor" href="#sytem-details-1"></a>Sytem details:</h2>
<pre><code class="lang-auto"> - PyTorch Version: 1.4.0
 - Torchvision Version: 0.5.0
 - OS: Ubuntu 18.04.3 LTS
 - How you installed PyTorch: `pip`
 - Python version: 3.6.13
 - CUDA/cuDNN version: CUDA Version: 11.0
 - GPU models and configuration: NVIDIA K80
</code></pre>