Issue 1:
🐛 Bug

when try load a saveed torch::jit::script::Module that been saved by Module::save before using method torch::jit::load it, error happened.

To Reproduce

Steps to reproduce the behavior:

a pytorch python pretrained script module been prepraed.

load a pretrained fron python script module by method

auto presavedModule = torch::jit::load("./model.pt");

save this module after retrained or inferenced by method

presavedModule.save("./testModel.pt");

reload it

auto local = torch::jit::load("./testModel.pt");

Code:

auto pre = torch::jit::load("./model.pt");

pre.save("localmodel.pt");

auto local = torch::jit::load("./localmodel.pt");

Error message:

terminate called after throwing an instance of 'std::runtime_error'

what(): 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

~~ <--- 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

Expected behavior

non error, and the module will be reloadable and retrainable.

Environment

Please copy and paste the output from our

environment collection script

(or fill out the checklist below manually).

You can get the script and run it with:

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

PyTorch Version (e.g., 1.0): Libtorch,1.3.0 pytorch,1.2.0

OS (e.g., Linux):ubuntu-19.04-desktop-amd64

How you installed PyTorch (conda, pip, source): no conda, with pip

Build command you used (if compiling from source): cmake

Python version: python-3.7.4-amd64

CUDA/cuDNN version: non

GPU models and configuration: non

Any other relevant information: both windows VS and ubuntu have this same phenomenon

Additional context

what I want is,

load python pretrained script module-----> retrain------->save------> reload to retrain or inference.

cc @ezyang @gchanan @zou3519 @jerryzh168 @suo

Issue 2:
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.

the save and reload process will be like the following , but get erro while try reload.

torch::serialize::OutputArchive output_archive;
auto presavedModule = torch::jit::load("D:/localshare/data/model/model.pt");
presavedModule.save("D:/localshare/data/model/testmodel.pt");
auto savedModule = torch::jit::load("D:/localshare/data/model/testmodel.pt");
savedModule.dump(true, true, true);

reported error:

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
~~ <--- 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

Is there any sugesstion:

cc @ezyang @gchanan @zou3519 @jerryzh168 @suo