Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132) #1943

Open
hurricane013 opened this issue Mar 5, 2020 · 22 comments

Comments

@hurricane013
Copy link

hurricane013 commented Mar 5, 2020

I have created .pt file of keypoint_rcnn using torch=1.5 and vision=0.6.0 now trying to integrate it with my android app. The error I am getting is as below.

E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.pytorch.helloworld, PID: 15691
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.helloworld/org.pytorch.helloworld.MainActivity}: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132)
(no backtrace available)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Caused by: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132)
(no backtrace available)
at org.pytorch.NativePeer.initHybrid(Native Method)
at org.pytorch.NativePeer.(NativePeer.java:18)
at org.pytorch.Module.load(Module.java:23)
at org.pytorch.helloworld.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:7148)
at android.app.Activity.performCreate(Activity.java:7139)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1293)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102)
... 11 more

@fmassa
Copy link
Member

fmassa commented Mar 10, 2020

Hi,

I suppose you are trying to use torchscript to convert the model to mobile, is that correct?

I suspect that this might not work out-of-the-box currently, because PyTorch mobile doesn't yet support using operators registered outside of PyTorch (like roi_align in torchvision).

@dreiss is that still the case?

@dreiss
Copy link

dreiss commented Mar 10, 2020

Yes, but I think this issue is unrelated. It's just due to a change in the serialization format (which I think was reverted).

@fmassa
Copy link
Member

fmassa commented Mar 10, 2020

Ok, following @dreiss comment, if you update PyTorch and torchvision this issue should go away, but you'll still have issues exporting keypoint-rcnn to mobile.

@hurricane013
Copy link
Author

Yes @fmassa you are correct. I used pytorch 1.4 snapshot as a dependency, above error disappeared. But still I am getting build failed that even without showing any error. Now I am confused with what should be exact issue.

@fmassa
Copy link
Member

fmassa commented Mar 11, 2020

@hurricane013 as I mentioned in the above post, we currently do not support exporting keypoint-rcnn to mobile yet unfortunately, but support for it will be added in future releases.

@cansozbir
Copy link

Hi, I wrote a simple MNIST classifier with CNN and got the same error on my android project.

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.predictor, PID: 7253 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.predictor/com.example.predictor.MainActivity}: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132) (no backtrace available) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: com.facebook.jni.CppException: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at ../caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at ../caffe2/serialize/inline_container.cc:132) (no backtrace available) at org.pytorch.NativePeer.initHybrid(Native Method) at org.pytorch.NativePeer.<init>(NativePeer.java:18) at org.pytorch.Module.load(Module.java:23) at com.example.predictor.MainActivity.onCreate(MainActivity.kt:47) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) ... 11 more Disconnected from the target VM, address: 'localhost:8602', transport: 'socket'

@fmassa
Copy link
Member

fmassa commented Apr 6, 2020

@hurricane013 simple CNN models should work with mobile, I would expect this to be a version issue and if you update PyTorch / torchvision and re-save your weights, it should work

@cansozbir
Copy link

I see.
These are my package versions:

import torch
torch.version
'1.5.0.dev20200306'
import torchvision
torchvision.version
'0.6.0a0+f534fb5'

and this is what I added to dependencies.

implementation 'org.pytorch:pytorch_android:1.4.0'
implementation 'org.pytorch:pytorch_android_torchvision:1.4.0'

Should I install pytorch's 1.4 version or is there any implementation for 1.5?

@fmassa
Copy link
Member

fmassa commented Apr 6, 2020

Yes, I think you might want to install PyTorch 1.4 and torchvision 0.5.0.

But I would recommend posting this question on the pytorch discuss forums, as this is outside of the scope of torchvision and I don't have much context to be able to help with android-specific issues

@hurricane013
Copy link
Author

hurricane013 commented Apr 25, 2020

@hurricane013 simple CNN models should work with mobile, I would expect this to be a version issue and if you update PyTorch / torchvision and re-save your weights, it should work

@fmassa As I mentioned, I used 1.4 snapshot which is latest as a dependency in my android app, but i am still getting build failed without any error.

@jxmorris12
Copy link

If anyone encounters this, this is what happened to me:

  1. Updated torchvision to a version not compatible with torch
  2. Run code that loaded a torchvision dataset, then threw an error
  3. Downgraded torchvision to proper version
  4. Re-ran code that loaded that dataset, which had been downloaded in a newer format, which couldn't be recognized by older torchvision

To fix it, I removed the dataset that torchvision had already downloaded.

@NeighborhoodCoding
Copy link

NeighborhoodCoding commented Sep 11, 2020

@jxmorris12 maybe doing new colab env is much easier...

It just happend to me....so ANNOYING!!
What version of torch, torchvision is needed....???!
EDIT : PyTorch 1.4 and torchvision 0.5.0 seems to work but I'm not perfectly sure yet, and maybe there is more good version to safe. I don know latest version of org.pytorch:pytorch_android yet also.

@chinglamchoi
Copy link

I'm having the same issues on torch=1.4.0 and torchvision=0.5.0. Here's my error message:

Traceback (most recent call last):
File "train.py", line 15, in
model.setup(opt)
File "/home/cchoi/n2d/models/base_model.py", line 29, in setup
self.load_networks(opt.epoch)
File "/home/cchoi/n2d/models/base_model.py", line 129, in load_networks
state_dict = torch.load(load_path, map_location=str(self.device))
File "/home/cchoi/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 527, in load
with _open_zipfile_reader(f) as opened_zipfile:
File "/home/cchoi/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 224, in init
super(_open_zipfile_reader, self).init(torch.C.PyTorchFileReader(name_or_buffer))
RuntimeError: version
<= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /opt/conda/conda-bld/pytorch_1579022027550/work/caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at /opt/conda/conda-bld/pytorch_1579022027550/work/caffe2/serialize/inline_container.cc:132)
frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7f0db93f5627 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libc10.so)
frame #1: caffe2::serialize::PyTorchStreamReader::init() + 0x1f5b (0x7f0dbde669ab in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #2: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::string const&) + 0x64 (0x7f0dbde67bc4 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so)
frame #3: + 0x6ce4b6 (0x7f0deba224b6 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_python.so)
frame #4: + 0x28b8a7 (0x7f0deb5df8a7 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_python.so)

frame #35: __libc_start_main + 0xf0 (0x7f0dfb530840 in /lib/x86_64-linux-gnu/libc.so.6)

@eric4note
Copy link

I ran into the same problem with pytorch 1.4

@neeraj-j
Copy link

The model you are trying to load is trained on PyTorch V1.6 or above. Upgrade your PyTorch version to 1.6.

@Emmanuel12345678
Copy link

Does anyone know how I can reshape Tensor object on android?

@ForrestPi
Copy link

The model trained with PyTorch 1.7 and the backbone is resnet50 , but PyTorch version 1.4 loading the model occurred the same error

@Muratoter
Copy link

Update pytorch latest versions. Follow this link; https://pytorch.org/mobile/android/#using-the-nightly-pytorch-android-libraries

@developershutt
Copy link

Make sure both Python version and Android version of PyTorch is the same.

@dunkeln
Copy link

dunkeln commented Jul 8, 2021

I'm having the same issues on torch=1.4.0 and torchvision=0.5.0. Here's my error message:

Traceback (most recent call last):

File "train.py", line 15, in

model.setup(opt)

File "/home/cchoi/n2d/models/base_model.py", line 29, in setup

self.load_networks(opt.epoch)

File "/home/cchoi/n2d/models/base_model.py", line 129, in load_networks

state_dict = torch.load(load_path, map_location=str(self.device))

File "/home/cchoi/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 527, in load

with _open_zipfile_reader(f) as opened_zipfile:

File "/home/cchoi/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 224, in init

super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))

RuntimeError: version_ <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /opt/conda/conda-bld/pytorch_1579022027550/work/caffe2/serialize/inline_container.cc:132, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 2. Your PyTorch installation may be too old. (init at /opt/conda/conda-bld/pytorch_1579022027550/work/caffe2/serialize/inline_container.cc:132)

frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7f0db93f5627 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libc10.so)

frame #1: caffe2::serialize::PyTorchStreamReader::init() + 0x1f5b (0x7f0dbde669ab in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so)

frame #2: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::string const&) + 0x64 (0x7f0dbde67bc4 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch.so)

frame #3: + 0x6ce4b6 (0x7f0deba224b6 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_python.so)

frame #4: + 0x28b8a7 (0x7f0deb5df8a7 in /home/cchoi/anaconda3/lib/python3.8/site-packages/torch/lib/libtorch_python.so)

frame #35: __libc_start_main + 0xf0 (0x7f0dfb530840 in /lib/x86_64-linux-gnu/libc.so.6)

what fixed your issue? and were you using python2? @chinglamchoi

@paluchasz
Copy link

I had the same problem when using the from_pretrained method from Huggingface transformers and installing latest transformers (4.12.4) and torch (1.10.0) seems to have worked for me.

@NeighborhoodCoding
Copy link

Use PyTorch 1.4 and torchvision 0.5.0, it solves some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests