microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.87k stars 2.94k forks source link

[Mobile|Android] Fatal error: ai.onnx.contrib:SentencepieceTokenizer(-1) is not a registered function/op #18226

Open istoneyou opened 1 year ago

istoneyou commented 1 year ago

Describe the issue

When I run the universal-sentence-encoder-multilingual model,I got the below error.

ai.onnxruntime.OrtException: Error code - ORT_FAIL - message: Fatal error: ai.onnx.contrib:SentencepieceTokenizer(-1) is not a registered function/op
      at ai.onnxruntime.OrtSession.createSession(Native Method)
      at ai.onnxruntime.OrtSession.<init>(OrtSession.java:91)
      at ai.onnxruntime.OrtEnvironment.createSession(OrtEnvironment.java:276)
      at ai.onnxruntime.OrtEnvironment.createSession(OrtEnvironment.java:249)
      at com.moto.qa.algorithm.ClipModel.prepareEnvironment(ClipModel.java:41)
      at com.moto.qa.algorithm.TextModel.prepareEnvironment(TextModel.java:57)
      at `com.moto.qa.ui.MainViewModel.lambda$initTextEmbedderModel$1$com-moto-qa-ui-MainViewModel(MainViewModel.java:144)`
      at com.moto.qa.ui.MainViewModel$$ExternalSyntheticLambda2.run(Unknown Source:2)
      at android.os.Handler.handleCallback(Handler.java:984)
      at android.os.Handler.dispatchMessage(Handler.java:104)
      at android.os.Looper.loopOnce(Looper.java:238)
      at android.os.Looper.loop(Looper.java:357)
      at android.os.HandlerThread.run(HandlerThread.java:85)

To reproduce

Model: universal-sentence-encoder-multilingual-3-onnx

     try {
            environment = OrtEnvironment.getEnvironment();
            sessionOptions = new OrtSession.SessionOptions();
            sessionOptions.setOptimizationLevel(OrtSession.SessionOptions.OptLevel.BASIC_OPT);
            sessionOptions.registerCustomOpLibrary(OrtxPackage.getLibraryPath());
            InputStream modelStream = assetManager.open(getModelFileName());
            byte[] modelBytes = new byte[modelStream.available()];
            modelStream.read(modelBytes);
            modelStream.close();
            session = environment.createSession(modelBytes, sessionOptions);
        } catch (Exception e) {
            LogUtil.e(TAG, "prepareEnvironment", e);
        }

Urgency

No response

Platform

Android

OS Version

13

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

None

ONNX Runtime Version or Commit ID

onnxruntime-android 1.13.1

ONNX Runtime API

Java/Kotlin

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

skottmckay commented 1 year ago

What version of the onnxruntime-extensions package are you using?

istoneyou commented 1 year ago

What version of the onnxruntime-extensions package are you using? 0.9.0

skottmckay commented 1 year ago

The SentencePiece tokenizer isn't currently included in the Android package for onnxruntime-extensions. https://github.com/microsoft/onnxruntime-extensions/blob/main/tools/android/package_ops.config

We can look at adding it. In order to prioritize it would be helpful if you could provide some info on what you're trying to do and why? e.g. experimentation, production scenario, hard requirement to use this particular model or it was semi-randomly chosen and a different model which uses a supported tokenizer like BertTokenizer could alternatively be used?

minstrelsy commented 1 year ago

I met the same issue when I was trying to use ulrv6.fairseq.model.onnx to do the tokenizer for Florence text embedding on my Android project. I also tried to convert it to ORT but got the same error message.

Could this be added in onnxruntime-extensions for Android Java/Kotlin runtime? Or do I have to use this model from the native C/C++ code level? Any suggestion?

github-actions[bot] commented 11 months ago

This issue has been automatically marked as stale due to inactivity and will be closed in 7 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

skottmckay commented 11 months ago

It will be included in the next release of extensions.