Repository: pytorch
Issue: LibTorch cannot load PyTorch exported model
Labels: module: docs,module: serialization,triaged

## 🐛 Bug

Since [version 1.6](https://github.com/pytorch/pytorch/releases/tag/v1.6.0) models are exported with the same serialisation format that is used by TorchScript:
> the same as the TorchScript serialization format, making serialization more consistent across PyTorch

And indeed, the exported archives have a similar file structure.

The exported archive indeed has a similar file structure as the TorchScript serialisation format, but it is still not possible to load this archive in LibTorch.

## To Reproduce

Steps to reproduce the behavior:

1. save model in PyTorch: `torch.save(model, "model.pt")`
2. load archive in LibTorch: ~~`model = torch::load("model.pt");`~~ `model = torch::jit::load("model.pt");`
3. stack trace

```
invalid model file: [enforce fail at inline_container.cc:222] . file not found: archive/constants.pkl
frame #0: c10::ThrowEnforceNotMet(char const*, int, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void const*) + 0x67 (0x7f48c3b3ec97 in /home/christian/Development/cofusion_base_ws/devel/lib/libc10.so)
frame #1: caffe2::serialize::PyTorchStreamReader::getRecordID(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0xd6 (0x7f4906242f26 in /home/christian/Development/cofusion_base_ws/devel/lib/libtorch_cpu.so)
frame #2: caffe2::serialize::PyTorchStreamReader::getRecord(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x34 (0x7f4906242fa4 in /home/christian/Development/cofusion_base_ws/devel/lib/libtorch_cpu.so)
frame #3: torch::jit::readArchiveAndTensors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, c10::optional<std::function<c10::StrongTypePtr (c10::QualifiedName const&)> >, c10::optional<std::function<c10::intrusive_ptr<c10::ivalue::Object, c10::detail::intrusive_target_default_null_type<c10::ivalue::Object> > (c10::StrongTypePtr, c10::IValue)> >, c10::optional<c10::Device>, caffe2::serialize::PyTorchStreamReader&) + 0xda (0x7f49075662ea in /home/christian/Development/cofusion_base_ws/devel/lib/libtorch_cpu.so)
frame #4: <unknown function> + 0x30ddbdd (0x7f4907566bdd in /home/christian/Development/cofusion_base_ws/devel/lib/libtorch_cpu.so)
frame #5: <unknown function> + 0x30e01b1 (0x7f49075691b1 in /home/christian/Development/cofusion_base_ws/devel/lib/libtorch_cpu.so)
frame #6: torch::jit::load(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) + 0x179 (0x7f4907569ad9 in /home/christian/Development/cofusion_base_ws/devel/lib/libtorch_cpu.so)
frame #7: torch::jit::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) + 0x75 (0x7f490756c435 in /home/christian/Development/cofusion_base_ws/devel/lib/libtorch_cpu.so)
```

## Expected behavior

LibTorch should load/deserialise the model.

## Environment

```
PyTorch version: 1.7.0
Is debug build: True
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.1 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: 10.0.0-4ubuntu1 
CMake version: version 3.16.3

Python version: 3.8 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce GTX 1650
Nvidia driver version: 455.32.00
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.17.4
[pip3] numpydoc==1.1.0
[pip3] torch==1.7.0
[pip3] torchvision==0.8.1
[conda] Could not collect
```

## Additional context

<!-- Add any other context about the problem here. -->


cc @ezyang @gchanan @zou3519 @bdhirsh @jlin27 @mruberry