microsoft / microsoft/onnxruntime-inference-examples

onnxruntime-inference-examples use qwen error

Open
#507 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.7k
Forks
414
Avg merge
1d 6h
Merged PRs (30d)
14

Description

I use the demo which is onnx-runtime/onnxruntime-inference-examples/mobile/examples/phi-3/android , but I use the qwen model which is https://huggingface.co/onnx-community/Qwen2.5-0.5B-Instruct/tree/main to instead of the phi-3. Then I push the model_uint8.onnx file to the android phone. When I run the process,it occur some error below:

01-10 18:05:47.205 1957 2157 D AwareLog: iawared: WorkingsetPauseCollect ai.onnxruntime.genai.demo/.MainActivity
01-10 18:05:48.120 24819 24961 W System.err: ai.onnxruntime.genai.GenAIException: Failed to create Tokenizer.
01-10 18:05:48.120 24819 24961 W System.err: at ai.onnxruntime.genai.SimpleGenAI.generate(SimpleGenAI.java:103)
01-10 18:05:48.120 24819 24961 W System.err: at ai.onnxruntime.genai.demo.MainActivity$2$1.run(MainActivity.java:229)
01-10 18:05:48.120 24819 24961 W System.err: at java.lang.Thread.run(Thread.java:933)
01-10 18:05:48.120 24819 24961 W System.err: Caused by: ai.onnxruntime.genai.GenAIException: Token generation loop failed.
01-10 18:05:48.120 24819 24961 W System.err: at ai.onnxruntime.genai.SimpleGenAI.generate(SimpleGenAI.java:97)
01-10 18:05:48.120 24819 24961 W System.err: ... 2 more
01-10 18:05:48.120 24819 24961 W System.err: Caused by: ai.onnxruntime.genai.GenAIException: Got invalid dimensions for input: past_key_values.0.key for the following indices
01-10 18:05:48.120 24819 24961 W System.err: index: 3 Got: 14 Expected: 64
01-10 18:05:48.120 24819 24961 W System.err: Please fix either the inputs/outputs or the model.
01-10 18:05:48.120 24819 24961 W System.err: at ai.onnxruntime.genai.Generator.appendTokenSequences(Native Method)
01-10 18:05:48.120 24819 24961 W System.err: at ai.onnxruntime.genai.Generator.appendTokenSequences(Generator.java:93)
01-10 18:05:48.120 24819 24961 W System.err: at ai.onnxruntime.genai.SimpleGenAI.generate(SimpleGenAI.java:91)
01-10 18:05:48.120 24819 24961 W System.err: ... 2 more
01-10 18:05:48.120 24819 24961 D onnxActivity: GenAIException..

Here is the code :
`try {
Log.d(TAG, "start generator result");
SimpleGenAI generator = new SimpleGenAI(getExternalFilesDir(null).getPath());

                        GeneratorParams params = generator.createGeneratorParams();
                        params.setSearchOption("max_length", 20);
                        ByteBuffer data = ByteBuffer.allocateDirect(4 * Float.BYTES).order(ByteOrder.nativeOrder());
                        FloatBuffer floatBuffer = data.asFloatBuffer();
                        floatBuffer.put(new float[] {1.0f, 2.0f, 3.0f, 4.0f});
                        Tensor tensor = new Tensor(data, new long[]{64, 64}, Tensor.ElementType.uint8);
                        params.setInput(promptQuestion, tensor);
                        String result =
                                generator.generate(params, promptQuestion, null);
                        Log.d(TAG, "Result: " + result);
                        runOnUiThread(() -> {
                            generatedTV.setText(result);
                            sendMsgIB.setEnabled(true);
                            sendMsgIB.setAlpha(1.0f);
                        });

                    } catch (GenAIException e) {
                        e.printStackTrace();
                        Log.d(TAG, "GenAIException..");
                    }`

I don't know how to fix this error. Could anyone help me to fix this error? Thanks a lot.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with mobile/examples/phi-3/android and inspect MainActivity.java, SimpleGenAI.generate, and the model files expected in the app's external-files directory. Compare the Qwen model inputs and past_key_values dimensions with the Phi-3 example and verify the tokenizer and model assets used by the demo. Done means the documented model setup runs without the reported tokenizer or dimension errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
machine-learning, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.