{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/14219","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/14219/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/14219/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/14219/events","html_url":"https://github.com/pytorch/pytorch/issues/14219","id":382524687,"node_id":"MDU6SXNzdWUzODI1MjQ2ODc=","number":14219,"title":"C++ model load error","user":{"login":"jinfagang","id":21303438,"node_id":"MDQ6VXNlcjIxMzAzNDM4","avatar_url":"https://avatars3.githubusercontent.com/u/21303438?v=4","gravatar_id":"","url":"https://api.github.com/users/jinfagang","html_url":"https://github.com/jinfagang","followers_url":"https://api.github.com/users/jinfagang/followers","following_url":"https://api.github.com/users/jinfagang/following{/other_user}","gists_url":"https://api.github.com/users/jinfagang/gists{/gist_id}","starred_url":"https://api.github.com/users/jinfagang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jinfagang/subscriptions","organizations_url":"https://api.github.com/users/jinfagang/orgs","repos_url":"https://api.github.com/users/jinfagang/repos","events_url":"https://api.github.com/users/jinfagang/events{/privacy}","received_events_url":"https://api.github.com/users/jinfagang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-11-20T06:53:28Z","updated_at":"2018-11-20T09:01:35Z","closed_at":null,"author_association":"NONE","body":"I got error when load model from a tracing typescripts model. The trace model is simple:\r\n\r\n```python\r\nimport torch\r\nimport torchvision\r\nfrom torchvision import transforms\r\nfrom PIL import Image\r\nfrom time import time\r\nimport numpy as np\r\n\r\n# An instance of your model.\r\nmodel = torchvision.models.resnet18(pretrained=True)\r\nmodel.eval()\r\n\r\n# An example input you would normally provide to your model's forward() method.\r\nexample = torch.rand(1, 3, 224, 224)\r\n\r\n# Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing.\r\ntraced_script_module = torch.jit.trace(model, example)\r\ntraced_script_module.save(\"resnet50_typescripts.pt\")\r\n\r\n# evalute time\r\nbatch = torch.rand(64, 3, 224, 224)\r\nstart = time()\r\noutput = traced_script_module(batch)\r\nstop = time()\r\nprint(str(stop - start) + \"s\")\r\n\r\n# read image\r\nimage = Image.open('dog.png').convert('RGB')\r\ndefault_transform = transforms.Compose([\r\n    transforms.Resize([224, 224]),\r\n    transforms.ToTensor(),\r\n    transforms.Normalize(mean=[0.485, 0.456, 0.406],\r\n                         std=[0.229, 0.224, 0.225])\r\n])\r\nimage = default_transform(image)\r\n\r\n# forward\r\noutput = traced_script_module(image.unsqueeze(0))\r\nprint(output[0, :10])\r\n\r\n# print top-5 predicted labels\r\nlabels = np.loadtxt('synset_words.txt', dtype=str, delimiter='\\n')\r\n\r\ndata_out = output[0].data.numpy()\r\nsorted_idxs = np.argsort(-data_out)\r\n\r\nfor i, idx in enumerate(sorted_idxs[:5]):\r\n    print('top-%d label: %s, score: %f' % (i, labels[idx], data_out[idx]))\r\n```\r\n\r\nC++ program is load that model, but even load can not pass. (Build is success)\r\n\r\nAnd error got:\r\n```\r\nterminate called after throwing an instance of 'c10::Error'\r\n  what():  file_format_version <= kMaxSupportedFileFormatVersion ASSERT FAILED at /pytorch/caffe2/serialize/inline_container.h:213, please report a bug to PyTorch. Attempted to read a PyTorch file with version %llu, but the maximum supported version for reading is %llu. Your PyTorch installation may be too old.21 (readAndValidateFileHeader at /pytorch/caffe2/serialize/inline_container.h:213)\r\nframe #0: std::function<std::string ()>::operator()() const + 0x11 (0x7f7a85d6b0d1 in /pt_codes/pt_cpp/libtorch/lib/libc10.so)\r\nframe #1: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x2a (0x7f7a85d6a99a in /pt_codes/pt_cpp/libtorch/lib/libc10.so)\r\nframe #2: <unknown function> + 0x5cb0b0 (0x7f7ab9d900b0 in /pt_codes/pt_cpp/libtorch/lib/libtorch.so.1)\r\nframe #3: <unknown function> + 0x5cb681 (0x7f7ab9d90681 in /pt_codes/pt_cpp/libtorch/lib/libtorch.so.1)\r\nframe #4: <unknown function> + 0x5c8cb6 (0x7f7ab9d8dcb6 in /pt_codes/pt_cpp/libtorch/lib/libtorch.so.1)\r\nframe #5: torch::jit::load(std::istream&) + 0xb4 (0x7f7ab9d8eb64 in /pt_codes/pt_cpp/libtorch/lib/libtorch.so.1)\r\nframe #6: torch::jit::load(std::string const&) + 0x27 (0x7f7ab9d8ec37 in /pt_codes/pt_cpp/libtorch/lib/libtorch.so.1)\r\nframe #7: <unknown function> + 0x8e9b (0x559c7be0ce9b in ./build/ptcpp)\r\nframe #8: __libc_start_main + 0xe7 (0x7f7a853edb97 in /lib/x86_64-linux-gnu/libc.so.6)\r\nframe #9: <unknown function> + 0x801a (0x559c7be0c01a in ./build/ptcpp)\r\n\r\n```\r\n\r\nWhat is wrong with current c++ API? I think it is a bug or something? because the error message is not well printed though."},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/440195174","html_url":"https://github.com/pytorch/pytorch/issues/14219#issuecomment-440195174","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/14219","id":440195174,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDE5NTE3NA==","user":{"login":"t-vi","id":20787943,"node_id":"MDQ6VXNlcjIwNzg3OTQz","avatar_url":"https://avatars2.githubusercontent.com/u/20787943?v=4","gravatar_id":"","url":"https://api.github.com/users/t-vi","html_url":"https://github.com/t-vi","followers_url":"https://api.github.com/users/t-vi/followers","following_url":"https://api.github.com/users/t-vi/following{/other_user}","gists_url":"https://api.github.com/users/t-vi/gists{/gist_id}","starred_url":"https://api.github.com/users/t-vi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-vi/subscriptions","organizations_url":"https://api.github.com/users/t-vi/orgs","repos_url":"https://api.github.com/users/t-vi/repos","events_url":"https://api.github.com/users/t-vi/events{/privacy}","received_events_url":"https://api.github.com/users/t-vi/received_events","type":"User","site_admin":false},"created_at":"2018-11-20T09:01:35Z","updated_at":"2018-11-20T09:01:35Z","author_association":"CONTRIBUTOR","body":"Try using the libs from torch_nightly. PyTorch is still moving too fast to mix versions, so the error your getting (your C++ lib is too old) is legitimate.\r\nYou can just use the Torch_DIR/Caffe2_DIR from the \"shared/Torch\" subdirectory of your PyTorch installation.\r\n"}}
{"actor":{"display_login":"t-vi"}}