<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto">when try load a saveed torch::jit::script::Module that been saved by Module::save before using method torch::jit::load it, error happened.</p>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">Steps to reproduce the behavior:</p>
<ol dir="auto">
<li>a pytorch python pretrained script module been prepraed.</li>
<li>load a pretrained fron python script module  by method<br>
auto presavedModule = torch::jit::load("./model.pt");</li>
<li>save this module after retrained or inferenced by method<br>
presavedModule.save("./testModel.pt");</li>
<li>reload it<br>
auto local = torch::jit::load("./testModel.pt");</li>
</ol>

<h2 dir="auto">Code:</h2>
<p dir="auto">auto pre = torch::jit::load("./model.pt");<br>
pre.save("localmodel.pt");<br>
auto local = torch::jit::load("./localmodel.pt");</p>
<h2 dir="auto">Error message:</h2>
<p dir="auto">terminate called after throwing an instance of 'std::runtime_error'<br>
what():  expected newline but found 'number' here:<br>
at code/<strong>torch</strong>/modelv2.py:75:51<br>
import <strong>torch</strong>.modelv2.features.16.conv.1<br>
import <strong>torch</strong>.modelv2.features.17<br>
import <strong>torch</strong>.modelv2.features.17.conv<br>
import <strong>torch</strong>.modelv2.features.17.conv.0<br>
import <strong>torch</strong>.modelv2.features.17.conv.1<br>
import <strong>torch</strong>.modelv2.features.18<br>
class features(Module):<br>
<strong>parameters</strong> = []<br>
<strong>annotations</strong> = []<br>
<strong>annotations</strong>["0"] = <strong>torch</strong>.modelv2.features.0<br>
~~ &lt;--- HERE<br>
<strong>annotations</strong>["1"] = <strong>torch</strong>.modelv2.features.1<br>
<strong>annotations</strong>["2"] = <strong>torch</strong>.modelv2.features.2<br>
<strong>annotations</strong>["3"] = <strong>torch</strong>.modelv2.features.3<br>
<strong>annotations</strong>["4"] = <strong>torch</strong>.modelv2.features.4<br>
<strong>annotations</strong>["5"] = <strong>torch</strong>.modelv2.features.5<br>
<strong>annotations</strong>["6"] = <strong>torch</strong>.modelv2.features.6<br>
<strong>annotations</strong>["7"] = <strong>torch</strong>.modelv2.features.7<br>
<strong>annotations</strong>["8"] = <strong>torch</strong>.modelv2.features.8<br>
<strong>annotations</strong>["9"] = <strong>torch</strong>.modelv2.features.9</p>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">non error, and the module will be reloadable and retrainable.</p>
<h2 dir="auto">Environment</h2>
<p dir="auto">Please copy and paste the output from our<br>
<a href="https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py" rel="nofollow">environment collection script</a><br>
(or fill out the checklist below manually).</p>
<p dir="auto">You can get the script and run it with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py"><pre class="notranslate"><code class="notranslate">wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
</code></pre></div>
<ul dir="auto">
<li>PyTorch Version (e.g., 1.0): Libtorch,1.3.0  pytorch,1.2.0</li>
<li>OS (e.g., Linux):ubuntu-19.04-desktop-amd64</li>
<li>How you installed PyTorch (<code class="notranslate">conda</code>, <code class="notranslate">pip</code>, source): no conda, with pip</li>
<li>Build command you used (if compiling from source): cmake</li>
<li>Python version: python-3.7.4-amd64</li>
<li>CUDA/cuDNN version: non</li>
<li>GPU models and configuration: non</li>
<li>Any other relevant information: both windows VS and ubuntu have this same phenomenon</li>
</ul>
<h2 dir="auto">Additional context</h2>
<p dir="auto">what I want is,<br>
load python pretrained script module-----&gt; retrain-------&gt;save------&gt; reload to retrain or inference.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jerryzh168/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jerryzh168">@jerryzh168</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/suo/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/suo">@suo</a></p>
<p dir="auto">I'm try to retain a JIT module from pytorch using c++ based on Libtorch libtorch-win-shared-with-deps-1.3.0 _cpu, and save retrained module for next usage.<br>
the save and reload process will be like the following , but get erro while try reload.</p>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="		torch::serialize::OutputArchive output_archive;
		auto presavedModule = torch::jit::load(&quot;D:/localshare/data/model/model.pt&quot;);
		presavedModule.save(&quot;D:/localshare/data/model/testmodel.pt&quot;);
		auto savedModule = torch::jit::load(&quot;D:/localshare/data/model/testmodel.pt&quot;);
		savedModule.dump(true, true, true);"><pre class="notranslate">		torch::serialize::OutputArchive output_archive;
		<span class="pl-k">auto</span> presavedModule = torch::jit::load(<span class="pl-s"><span class="pl-pds">"</span>D:/localshare/data/model/model.pt<span class="pl-pds">"</span></span>);
		presavedModule.save(<span class="pl-s"><span class="pl-pds">"</span>D:/localshare/data/model/testmodel.pt<span class="pl-pds">"</span></span>);
		<span class="pl-k">auto</span> savedModule = torch::jit::load(<span class="pl-s"><span class="pl-pds">"</span>D:/localshare/data/model/testmodel.pt<span class="pl-pds">"</span></span>);
		savedModule.dump(<span class="pl-c1">true</span>, <span class="pl-c1">true</span>, <span class="pl-c1">true</span>);</pre></div>
<p dir="auto">reported error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Caught
expected newline but found 'number' here:
at code/__torch__/modelv2.py:75:51
import __torch__.modelv2.features.16.conv.1
import __torch__.modelv2.features.17
import __torch__.modelv2.features.17.conv
import __torch__.modelv2.features.17.conv.0
import __torch__.modelv2.features.17.conv.1
import __torch__.modelv2.features.18
class features(Module):
  __parameters__ = []
  __annotations__ = []
  __annotations__[&quot;0&quot;] = __torch__.modelv2.features.0
                                                   ~~ &lt;--- HERE
  __annotations__[&quot;1&quot;] = __torch__.modelv2.features.1
  __annotations__[&quot;2&quot;] = __torch__.modelv2.features.2
  __annotations__[&quot;3&quot;] = __torch__.modelv2.features.3
  __annotations__[&quot;4&quot;] = __torch__.modelv2.features.4
  __annotations__[&quot;5&quot;] = __torch__.modelv2.features.5
  __annotations__[&quot;6&quot;] = __torch__.modelv2.features.6
  __annotations__[&quot;7&quot;] = __torch__.modelv2.features.7
  __annotations__[&quot;8&quot;] = __torch__.modelv2.features.8
  __annotations__[&quot;9&quot;] = __torch__.modelv2.features.9
Compiled from code
Type class std::runtime_error"><pre class="notranslate"><code class="notranslate">Caught
expected newline but found 'number' here:
at code/__torch__/modelv2.py:75:51
import __torch__.modelv2.features.16.conv.1
import __torch__.modelv2.features.17
import __torch__.modelv2.features.17.conv
import __torch__.modelv2.features.17.conv.0
import __torch__.modelv2.features.17.conv.1
import __torch__.modelv2.features.18
class features(Module):
  __parameters__ = []
  __annotations__ = []
  __annotations__["0"] = __torch__.modelv2.features.0
                                                   ~~ &lt;--- HERE
  __annotations__["1"] = __torch__.modelv2.features.1
  __annotations__["2"] = __torch__.modelv2.features.2
  __annotations__["3"] = __torch__.modelv2.features.3
  __annotations__["4"] = __torch__.modelv2.features.4
  __annotations__["5"] = __torch__.modelv2.features.5
  __annotations__["6"] = __torch__.modelv2.features.6
  __annotations__["7"] = __torch__.modelv2.features.7
  __annotations__["8"] = __torch__.modelv2.features.8
  __annotations__["9"] = __torch__.modelv2.features.9
Compiled from code
Type class std::runtime_error
</code></pre></div>
<p dir="auto">Is there any sugesstion:</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jerryzh168/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jerryzh168">@jerryzh168</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/suo/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/suo">@suo</a></p>