Version Problem, how to make PyTorch 1.2 and 1.3 work together

Rizhao_Cai: <p>Hi,</p>
<p>I have some version problems. And need your help. Let discuss it.</p>
<p>I am using the <a href="https://github.com/NervanaSystems/distiller" rel="noopener nofollow ugc">distiller</a> to prune my object detection model.<br>
Then I need to deploy the pruned model on a Jetson TX2 with TensorRT 6.0.</p>
<p>However, for the distiller, it requires the JIT module of PyTorch 1.3.1 to get the graph a module such that the distiller can do the actual pruning (not just putting a zeros mask).</p>
<p>After getting the pruned model, I exported it to an ONNX model with the PyTorch 1.3.1, however, I found that the ONNX parser of TensorRT 6.0 is not compatible with PyTorch 1.3.1, but with PyTorch 1.2.<br>
I have raised this issue on <a href="https://github.com/NVIDIA/TensorRT/issues/376" rel="noopener nofollow ugc">github</a>.</p>
<p>Now I have trouble.<br>
How can I make them work together?</p>
<p>I have tried two ways, but both of them failed.<br>
I created two conda environments, one is with PyTorch 1.3.1 and distiller, called env1.3, another is with PyTorch 1.2.0, called env1.2</p>
<ol>
<li>
<p>Under env1.3, I saved the whole model (not just state_dict) with torch.save and pickle.dump, but when I tried to use torch.load or pickle.load to load the model under env1.2, an error will occury, saying that there is no module called distiller.</p>
</li>
<li>
<p>Under env1.3, I used torch.jit.trace and get a ScriptModulde, and then I used torch.jit.save to save the model to the disk. However, when I used torch.jit.load under env1.2 to load the jit model, I got</p>
</li>
</ol>
<blockquote>
<p>terminate called after throwing an instance of ‘c10::Error’<br>
what():  [enforce fail at inline_container.cc:137] . PytorchStreamReader failed closing reader: file not found<br>
frame <span class="hashtag-raw">#0:</span> c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&amp;, void const*) + 0x47 (0x7f9f1c67ee17 in /home/rizhao/anaconda3/envs/torch/lib/python3.6/site-packages/torch/lib/libc10.so)<br>
frame <span class="hashtag-raw">#1:</span> caffe2::serialize::PyTorchStreamReader::valid(char const*) + 0x6b (0x7f9f1f60775b in /home/rizhao/anaconda3/envs/torch/lib/python3.6/site-packages/torch/lib/libtorch.so)<br>
frame <span class="hashtag-raw">#2:</span> caffe2::serialize::PyTorchStreamReader::~PyTorchStreamReader() + 0x1f (0x7f9f1f6077af in /home/rizhao/anaconda3/envs/torch/lib/python3.6/site-packages/torch/lib/libtorch.so)<br>
frame <span class="hashtag-raw">#3:</span>  + 0x3c17637 (0x7f9f206e6637 in /home/rizhao/anaconda3/envs/torch/lib/python3.6/site-packages/torch/lib/libtorch.so)<br>
frame <span class="hashtag-raw">#4:</span> torch::jit::import_ir_module(std::shared_ptr<a>torch::jit::script::CompilationUnit</a>, std::string const&amp;, c10::optional<a>c10::Device</a>, std::unordered_map&lt;std::string, std::string, std::hash<a>std::string</a>, std::equal_to<a>std::string</a>, std::allocator&lt;std::pair&lt;std::string const, std::string&gt; &gt; &gt;&amp;) + 0x1d0 (0x7f9f206ed220 in /home/rizhao/anaconda3/envs/torch/lib/python3.6/site-packages/torch/lib/libtorch.so)<br>
frame <span class="hashtag-raw">#5:</span>  + 0x4d69dc (0x7f9f66ddf9dc in /home/rizhao/anaconda3/envs/torch/lib/python3.6/site-packages/torch/lib/libtorch_python.so)<br>
frame <span class="hashtag-raw">#6:</span>  + 0x1d3ef4 (0x7f9f66adcef4 in /home/rizhao/anaconda3/envs/torch/lib/python3.6/site-packages/torch/lib/libtorch_python.so)<br>
<br>
frame <span class="hashtag-raw">#22:</span> __libc_start_main + 0xf0 (0x7f9f75830830 in /lib/x86_64-linux-gnu/libc.so.6)</p>
</blockquote>
<p>Aborted (core dumped)</p>
<p>Now, I have no idea how to solve it. Any cues will be much appreciated.</p>

driazati: <p>Are you able to upload the binary (maybe to a GitHub repo or something) you are trying to load so we can try to reproduce this issue?</p>

Rizhao_Cai: <p>Thanks. Can I just upload the ONNX model exported by PyTorch 1.3 or PyTorch 1.2? Besides, I can also upload the exported JIT module.</p>

driazati: <aside class="quote no-group" data-username="Rizhao_Cai" data-post="4" data-topic="69486">
<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/rizhao_cai/48/20465_2.png" class="avatar"> Rizhao_Cai:</div>
<blockquote>
<p>upload the ONNX model exported by PyTorch 1.3 or PyTorch 1.2? Besides, I can also upload the exported</p>
</blockquote>
</aside>
<p>Upload everything you can, at the very least the model you load that causes the error to be thrown</p>