I get the following error when trying to initialize a traced model with the iOS framework:
PyTorchDemo[25132:6735005] false CHECK FAILED at /Users/distiller/project/c10/core/Backend.h (tensorTypeIdToBackend at /Users/distiller/project/c10/core/Backend.h:106)
(no backtrace available)
The error appears similar to these Android issues:
opened 01:37AM - 16 Oct 19 UTC
closed 04:40PM - 24 Oct 19 UTC
Hello,
I'm trying to deploy a custom model in python to Android using pytorch… mobile. I used torch.jit.trace to trace and then save the model. The saved model is working correctly when I load it in both C++ and python. However, when using pytorch_android, the following error occurred when loading the module (inside Module.load(modelFileAbsolutePath) function). The only thing different from the PyTorchDemoApp is the model file path. And I've confirmed that the model file path is correct and the file exists. I'm using pytorch 1.3.0 in both python and android.
Any suggestions on why the model loading would fail? Would this be related to [this issue](https://github.com/pytorch/pytorch/issues/26764)? Any suggestions on how to get more debugging information? Thank you!
```
2019-10-15 21:25:36.585 24959-25880/org.pytorch.demo E/PyTorchDemo: Error during image analysis
com.facebook.jni.CppException: false CHECK FAILED at ../c10/core/Backend.h (tensorTypeIdToBackend at ../c10/core/Backend.h:106)
(no backtrace available)
at org.pytorch.Module$NativePeer.initHybrid(Native Method)
at org.pytorch.Module$NativePeer.<init>(Module.java:70)
at org.pytorch.Module.<init>(Module.java:25)
at org.pytorch.Module.load(Module.java:21)
at org.pytorch.demo.vision.ImageClassificationActivity.analyzeImage(ImageClassificationActivity.java:168)
at org.pytorch.demo.vision.ImageClassificationActivity.analyzeImage(ImageClassificationActivity.java:31)
at org.pytorch.demo.vision.AbstractCameraXActivity.lambda$setupCameraX$2$AbstractCameraXActivity(AbstractCameraXActivity.java:90)
at org.pytorch.demo.vision.-$$Lambda$AbstractCameraXActivity$t0OjLr-l_M0-_0_dUqVE4yqEYnE.analyze(lambda)
at androidx.camera.core.ImageAnalysisAbstractAnalyzer.analyzeImage(ImageAnalysisAbstractAnalyzer.java:57)
at androidx.camera.core.ImageAnalysisNonBlockingAnalyzer$1.run(ImageAnalysisNonBlockingAnalyzer.java:135)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
```
My model contains nn.Functional.interpolate layer and it is converted properly to .pt model using jit.
But Loading same model in android giving issues.
This is happening in case of interpolate layer only.
Edit - Error trace
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.custom_model/org.pytorch.custom_model.MainActivity}: com.facebook.jni.CppException: false CHECK FAILED at …/c10/core/Backend.h (tensorTypeIdToBackend at …/c10/core/Backend.h:106)
(no backtrace…
The second linked issue states that there’s an Android update with a fix --is there a fix for the iOS framework?
The model I’m using was traced with PyTorch 1.3.1, and I’m using LibTorch 1.3.1
ljk53
(Jiakai Liu)
December 6, 2019, 4:23am
2
Looks like the fix was landed to master as mentioned on #29806 so it will be part of 1.4 release. You can test the nightly build of iOS. @IvanKobzarev could you please confirm?
Yeah, I’m pretty sure this is resolved. If you want to verify, the steps for testing with the nightly build are in the first half of this comment: Incomprehensible behaviour
xta0
(Tao Xu)
December 9, 2019, 10:28pm
4
Hi @kennywalker , are you using cocoapods on iOS? if so, the correct version should be 1.3.1. If the error still exist, try the iOS nightly build - https://ossci-ios-build.s3.amazonaws.com/libtorch_ios_nightly_build.zip . Let me know if you have any questions.
1 Like
The model loads with the nightly build.
Thank you for the help @ljk53 , @David_Reiss , @xta0
1 Like
Hi @xta0
I was using cocoapods 1.3.1. Can the 1.4 podspec be published?.
xta0
(Tao Xu)
December 10, 2019, 7:12pm
7
Hi @kennywalker , we’re going to publish 1.4 in Jan (Hopefully). Could you give a solution mark on this? If there is any questions, feel free to leave a comment.
thoval
January 7, 2020, 11:21am
8
Hi @xta0 , is there an update about the release date of 1.4 for iOS?
xta0
(Tao Xu)
January 10, 2020, 1:09am
9
I think it’ll be in the middle of Jan. @jspisak do you know the exact date?
jspisak
(PyTorch Product Guy)
January 10, 2020, 2:15am
10
Yes, we are targeting mid next week to release 1.4. Look for the blog post on pytorch.org .
Dear @xta0 , I tried to use the current iOS nightly build, but it doesn’t work. I’ve noticed that the file libtorch.a
has only 944 bytes.
Dear @kennywalker , could you share with us the version you downloaded on December 19th, please?
xta0
(Tao Xu)
January 15, 2020, 6:22pm
13
@fabricionarcizo the nightly build is from master branch. We’ve recently split the libtorch.a
into multiple libraries. If you unzip the nightly build, you should see this - libtorch_cpu.a
which is the old libtorch.a
.
@xta0 I just tried to compile the libtorch.a
using the branch v1.4.0
with the following command:
SELECTED_OP_LIST=predictor.yaml BUILD_PYTORCH_MOBILE=1 IOS_ARCH=arm64 ./scripts/build_ios.sh
It compiles correctly, but I got some additional error when I try to link the libtorch.a
on Xcode.
Undefined symbol: c10::NonVariableTypeMode::is_enabled()
Undefined symbol: torch::jit::script::Module::module_object() const
Undefined symbol: c10::NonVariableTypeMode::set_enabled(bool)
Undefined symbol: caffe2::detail::_typeMetaDataInstance_preallocated_6
Undefined symbol: at::TypeDefault::to(at::Tensor const&, c10::TensorOptions const&, bool, bool)
xta0
(Tao Xu)
January 16, 2020, 7:41pm
15
@fabricionarcizo SELECTED_OP_LIST
is used for the custom build. Also, the build is in arm64, were you running in simulator?
Since I don’t have your code, my recommendation is to follow the tutorials