Pytorch for Android - LiteModuleLoader

I am getting an error as

java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.helloworld/org.pytorch.helloworld.MainActivity}: com.facebook.jni.CppException: Lite Interpreter verson number does not match. The model version must be between 3 and 5But the model version is 8 ()
Exception raised from parseMethods at …/torch/csrc/jit/mobile/import.cpp:320 (most recent call first):
(no backtrace available)

My gradle settings
dependencies {
implementation ‘androidx.appcompat:appcompat:1.1.0’
implementation ‘org.pytorch:pytorch_android_lite:1.9.0’
implementation ‘org.pytorch:pytorch_android_torchvision:1.9.0’

GitHub - pytorch/android-demo-app: PyTorch android examples of usage in applications HelloWorld from this app.

I converted my GAN model to .ptl and then I tried to load the .ptl file in the same way as mentioned in this sample. I am consistently getting the above error

Looks like the model is generated from a newer runtime, while 1.9 is more than one year old. Possibly try

implementation ‘org.pytorch:pytorch_android_lite:1.12.0’
implementation ‘org.pytorch:pytorch_android_torchvision:1.12.0’

and see if it works?

1 Like

@cccclai No it’s not working

import org.pytorch.IValue;
import org.pytorch.LiteModuleLoader;
import org.pytorch.Module;
import org.pytorch.Tensor;
import org.pytorch.torchvision.TensorImageUtils;
import org.pytorch.MemoryFormat;

If I use 1.12 then I cannot resolve any of the pytorch symbols

I was able to fix it by changing to

implementation ‘org.pytorch:pytorch_android_lite:1.12.2’
implementation ‘org.pytorch:pytorch_android_torchvision:1.12.2’

Seems like 1.12.0 is not stable. By the way do we have any website where we can see the stable android builds. It’s hard to trial and error