Following ops cannot be found: [aten::scaled_dot_product_attention]

Hello,I want to deploy the clip model to an Android phone and encountered a problem. Can anyone help me to solve this problem?

first save the model into ‘’ file;

import torch
import clip
from PIL import Image
from tensorboardX import SummaryWriter
from torch.utils.mobile_optimizer import optimize_for_mobile

model, preprocess = clip.load("ViT-B/32")

model = list(model.children())[0]

image_path = "./image.jpg";
image = preprocess(

traced_script_model = torch.jit.trace(model, image)
optimized_script_model = optimize_for_mobile(traced_script_model)

secondly, load the model in android app:

module = LiteModuleLoader.load(assetFilePath(this, ""));

the build.gradle file of the android project:

dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'org.pytorch:pytorch_android_lite:1.13.0'
    implementation 'org.pytorch:pytorch_android_torchvision:1.9.0'

the runtime exception:

com.facebook.jni.CppException: Following ops cannot be found: [aten::scaled_dot_product_attention]. Please check if the operator library is included in the build. If built with selected ops, check if these ops are in the list. If you are a Meta employee, please see for a fix. Or post it in ()
Exception raised from initialize_operators at /home/agunapal/pytorch/torch/csrc/jit/mobile/function.cpp:90 (most recent call first):
(no backtrace available)
1 Like