com.facebook.jni.CppException: [enforce fail at inline_container.cc:222] . file not found: archive/constants.pkl

Hello Everyone. I was able to load the .pt file in python. But when I tried to load the same model in Java Android I was facing this issue.
Android Java Version:
‘org.pytorch:pytorch_android:1.6.0’
‘org.pytorch:pytorch_android_torchvision:1.7.0’
Python Version:
pytorch:1.6

 Caused by: com.facebook.jni.CppException: [enforce fail at inline_container.cc:222] . file not found: archive/constants.pkl
(no backtrace available)
    at org.pytorch.NativePeer.initHybrid(Native Method)
    at org.pytorch.NativePeer.<init>(NativePeer.java:23)
    at org.pytorch.Module.load(Module.java:24)
    at org.pytorch.Module.load(Module.java:34)
    at org.pytorch.helloworld.MainActivity.onCreate(MainActivity.java:39)
    at android.app.Activity.performCreate(Activity.java:7136)
    at android.app.Activity.performCreate(Activity.java:7127)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)

So please let me know, do I need to make any changes in Java Code while loading the model because I was able to load the sample model provided by the PyTorch Android team(version 1.4.0).

Is it related to versioning of pytorch? And Is pytorch java and pytorch versioning similar?

The version of gradle ‘org.pytorch:pytorch_android:1.6.0’ should be the same for pytorch binaries that you used to generate pt file.

Did you use 1.6.0 version for pt file?

I’m facing the exact same issue. However, I suspect mine is related to quantized model. I’m using PyTorch 1.7.1 to generate the model:

import torchvision, torch
model = torchvision.models.quantization.mobilenet_v2(pretrained=True, quantize=True)
torch.save(model.state_dict(), “model.pt”)

In Android app, I use:

dependencies {
implementation ‘androidx.appcompat:appcompat:1.1.0’
implementation ‘org.pytorch:pytorch_android:1.7.1’
implementation ‘org.pytorch:pytorch_android_torchvision:1.7.1’
}

I got:

Process: org.pytorch.helloworld, PID: 8644
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.helloworld/org.pytorch.helloworld.MainActivity}: com.facebook.jni.CppException: [enforce fail at inline_container.cc:222] . file not found: archive/constants.pkl
(no backtrace available)

Is there something to be done to run quantized model?
I also see the same error w/ Android benchmark binary and iOS benchmark app.

@IvanKobzarev any advice on this?

Never mind. I figured out my mistake.

Facing the same issue, could you share what fixed it for you?

Thanks!

Update: I’ve used PyTorch 1.6 for both save and load but the error remains.