onnxruntime-genai: Phi-3 can't deal with Japanese. How can I solve this issue?
Question
Phi-3 can’t deal with Japanese I enjoy Phi-3 which Microsoft made. I meet the error of onnxruntime_genai. How can I solve this issue ?
Phi-3 can’t deal with Japanese. How can I solve this issue?
Code
import onnxruntime_genai as og
import argparse
import time
model = og.Model(".\Phi-3-mini-128k-instruct-onnx\cpu_and_mobile\cpu-int4-rtn-block-32")
tokenizer = og.Tokenizer(model)
tokenizer_stream = tokenizer.create_stream()
def input_llm(text):
print("Question:",text)
input_tokens = tokenizer.encode(text)
params = og.GeneratorParams(model)
params.try_use_cuda_graph_with_max_batch_size(1)
params.input_ids = input_tokens
generator = og.Generator(model, params)
return generator
def output_llm(generator):
print("Answer:")
stt = time.time()
list_error = []
list_sentence = []
while not generator.is_done():
generator.compute_logits()
generator.generate_next_token()
new_token = generator.get_next_tokens()[0]
if not new_token in list_error:
try:
list_sentence.append(tokenizer_stream.decode(new_token))
except:
list_error.append(new_token)
list_sentence.append(new_token)
print(list_sentence)
fin = time.time()
print(fin-stt)
return list_error
Input
text = "<|user|>こんにちは。データ分析するにはなにをすればいい?<|end|><|assistant|>"
generator = input_llm(text)
list_error= output_llm(generator)
print(list_error)
Output
Question: <|user|>こんにちは。データ分析するにはなにをすればいい?<|end|><|assistant|>
Answer:
['', 'デ', 'ー', 'タ', '分', 233, 161, 147, 'に', 'は', 'い', 'く', 'つ', 'か', 'の', 'ス', 'テ', 'ッ', 'プ', 'が', 'あ', 'り', 'ま', 'す', '。', 'ま', 'ず', '、', 'デ', 'ー', 'タ', 'セ', 'ッ', 'ト', 'を', 232, 146, 145, '集', 'し', 'ま', 'す', '。', 'こ', 'れ', 'は', '、', '必', '要', 'な', '情', '報', 'を', 174, 'む', 'デ', 'ー', 'タ', 'を', '集', 'め', 'る', 'こ', 'と', 'で', 'す', '。', '次', 'に', '、', 'デ', 'ー', 'タ', 'を', 152, 183, '理', 'し', '、', '不', '要', 'な', '部', '分', 'を', '除', '去', 'し', 'ま', 'す', '。', 'こ', 'れ', 'に', 'よ', 'り', '、', '分', 'の', 141, 188, 234, 138, 'が', '向', '上', 'し', 'ま', 'す', '。', 'そ', 'の', '後', '、', 'デ', 'ー', 'タ', 'を', '分', 'し', '、', '意', 148, 182, 'の', 'あ', 'る', '洞', 178, 162, 'や', 'パ', 'タ', 'ー', 'ン', 'を', '見', 'つ', 'け', '出', 'し', 'ま', 'す', '。', '最', '後', 'に', '、', '分', '結', '果', 'を', '解', 236, 139, 'し', '、', '意', 'を', 179, 'き', '出', 'し', '、', 'そ', 'の', '結', '果', 'を', '報', '告', 'し', 'ま', 'す', '。', 'こ', 'れ', 'ら', 'の', 'ス', 'テ', 'ッ', 'プ', 'を', 235, 187, 'む', 'こ', 'と', 'で', '、', 'デ', 'ー', 'タ', '分', 'を', '成', '長', 'さ', 'せ', 'る', 'こ', 'と', 'が', 'で', 'き', 'ま', 'す', '。', '']
63.10930633544922
[233, 161, 147, 232, 146, 145, 174, 152, 183, 141, 188, 234, 138, 148, 182, 178, 162, 236, 139, 179, 235, 187]
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 20 (9 by maintainers)
@hosseinalipour @3x0dv5 @Johannes-Stephan @CLRafaelR we have published packages supporting CUDA 12. Please install using the following instructions: https://onnxruntime.ai/docs/genai/howto/install.html#cuda-12
Hi @natke
Is there any release date or place where i can get the information once the CUDA 12 version is published?
Hi @CLRafaelR Thank you for the extra context.
Yes, you can try to run with that alternate tokenizer. Instead of calling the onnxruntime-genai tokenizer, you can call the new one and set the input ids of the onnxruntime-genai params to the output of the new tokenizer instead.
And yes we plan to publish packages with CUDA 12.
Hi @natke , thank you for your swift response.
I successfully upgraded the package to
0.2.0-rc6. However, I encountered an error that prevented me from performing inference with the model, after removing CUDA 11.x and unifying my system to CUDA 12.x.I’m currently experiencing difficulties reinstalling CUDA 11.x, but I will attempt to run the model and report back once CUDA 11.x is reinstalled. By the way, —although this question deviates from the original inquery—, are there any plans to support CUDA 12.x for onnxruntime-genai? I believe support for CUDA 12.x would be helpful.
I am fully aware that Phi-3 is primarily trained on English data and may not perform as well in other languages. However, judging from the performance of the 128k model (standard model), I feel its Japanese generation capabilities outperform those of Llama-2 and Llama-2-based models that are fine-tuned using Japanese data. When considering the use of a different tokenizer with this ONNX model, for instance, is it possible to use the tokenizer llm-jp/hf-fast-tokenizer-v22b2 · Hugging Face, which can be loaded as follows, as the tokenizer for the ONNX model?
Hi @Hideki105 We have a fix for the Unicode decode error in progress. In the mean time, can you try with this script, which does not using streaming decoding:
The script is in
examples/python.Note: Phi-3-mini was predominantly trained and optimized for English. Its capabilities in other languages are limited, meaning it could understand but will not be as fluent as English. Customers are encouraged to use Microsoft Translator service in tandem to translate prompt and responses for best results.