Handling of "\ufffd" unicode at tokenizer.
Hi, I run this model at LLM8850 and notice that it displays some "¥fffd" instead of actual output. The model actually outputs correct text but it fails to display correctly.
The cause of the problem seems to be at the decode function of tokenizer.
https://huggingface.co/AXERA-TECH/Qwen2.5-3B-Instruct/blob/main/qwen2.5_tokenizer_uid.py#L44
It looks like that the Qwen3 version of the same function have the fix for "¥fffd".
https://huggingface.co/AXERA-TECH/Qwen3-1.7B/blob/main/qwen3_tokenizer_uid.py#L61
I hope this fix will be backported to this model.
I tested it on the Raspberry Pi 5 + LLM8850 platform, and the output was correct.
(base) axera@raspberrypi:~/tangqi/Qwen2.5-3B-Instruct $ ./run_qwen2.5_3b_ctx_axcl_aarch64.sh
[I][ Init][ 130]: LLM init start
[I][ Init][ 34]: connect http://127.0.0.1:12346 ok
[I][ Init][ 57]: uid: e1d920a2-7568-46bf-825d-6e717dea0094
bos_id: -1, eos_id: 151645
2% | █ | 1 / 39 [0.45s<17.36s, 2.25 count/s] tokenizer init ok
[I][ Init][ 45]: LLaMaEmbedSelector use mmap
5% | ██ | 2 / 39 [0.45s<8.70s, 4.48 count/s] embed_selector init ok
[I][ run][ 30]: AXCLWorker start with devid 0
100% | ████████████████████████████████ | 39 / 39 [69.04s<69.04s, 0.56 count/s] init post axmodel ok,remain_cmm(2634 MB)
[I][ Init][ 221]: max_token_len : 2047
[I][ Init][ 224]: kv_cache_size : 256, kv_cache_num: 2047
[I][ Init][ 232]: prefill_token_num : 128
[I][ Init][ 236]: grp: 1, prefill_max_token_num : 1
[I][ Init][ 236]: grp: 2, prefill_max_token_num : 128
[I][ Init][ 236]: grp: 3, prefill_max_token_num : 256
[I][ Init][ 236]: grp: 4, prefill_max_token_num : 384
[I][ Init][ 236]: grp: 5, prefill_max_token_num : 512
[I][ Init][ 236]: grp: 6, prefill_max_token_num : 640
[I][ Init][ 236]: grp: 7, prefill_max_token_num : 768
[I][ Init][ 236]: grp: 8, prefill_max_token_num : 896
[I][ Init][ 236]: grp: 9, prefill_max_token_num : 1024
[I][ Init][ 240]: prefill_max_token_num : 1024
________________________
| ID| remain cmm(MB)|
========================
| 0| 2634|
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
[I][ load_config][ 282]: load config:
{
"enable_repetition_penalty": false,
"enable_temperature": true,
"enable_top_k_sampling": true,
"enable_top_p_sampling": false,
"penalty_window": 20,
"repetition_penalty": 1.2,
"temperature": 0.9,
"top_k": 10,
"top_p": 0.8
}
[I][ Init][ 263]: LLM init ok
Type "q" to exit, Ctrl+c to stop current running
[I][ GenerateKVCachePrefill][ 324]: input token num : 21, prefill_split_num : 1 prefill_grpid : 2
[I][ GenerateKVCachePrefill][ 367]: input_num_token:21
[I][ main][ 234]: precompute_len: 21
[I][ main][ 235]: system_prompt: You are Qwen, created by Alibaba Cloud. You are a helpful assistant.
prompt >> who are you
[I][ SetKVCache][ 614]: prefill_grpid:2 kv_cache_num:128 precompute_len:21 input_num_token:11
[I][ SetKVCache][ 617]: current prefill_max_token_num:896
[I][ Run][ 855]: input token num : 11, prefill_split_num : 1
[I][ Run][ 887]: input_num_token:11
[I][ Run][1016]: ttft: 698.16 ms
I am Qwen, a large language model created by Alibaba Cloud. I am here to assist you with a wide range of questions and tasks to the best of my ability. How may I assist you today?
[N][ Run][1168]: hit eos,avg 5.49 token/s
[I][ GetKVCache][ 583]: precompute_len:74, remaining:950
prompt >> q
[I][ run][ 80]: AXCLWorker exit with devid 0
(base) axera@raspberrypi:~/tangqi/Qwen2.5-3B-Instruct $ axcl-smi
Thank you for the comment. I'm sorry that the context information is not enough.
This problem happens for multi-byte text like japanese and probably chinese text.
example input: "埼玉県について教えて"
You can see several "�" in the answer string.
$ ./run_qwen2.5_3b_ctx_axcl_aarch64.sh
[I][ Init][ 130]: LLM init start
[I][ Init][ 34]: connect http://127.0.0.1:12345 ok
[I][ Init][ 57]: uid: d3c9a150-773f-4b8f-b4ed-6893ee76e312
bos_id: -1, eos_id: 151645
2% | █ | 1 / 39 [0.39s<15.37s, 2.54 count/s] tokenizer init ok[I][ Init][ 45]: LLaMaEmbedSelector use mmap 0 5% | ██ | 2 / 39 [0.39s<7.68s, 5.08 count/s] embed_selector init ok 04 ][ run][ 30]: AXCLWorker start with devid 0
82% | █████████████████████████████████████████████ ██ ██████ | 31 /it 7 axmodel ok,d ███████████████████████████ | 39 / 39 [65.15s<66.87s, 0.58 count/s] init post axmod(2634 MB)2959 MB) Init][ 221]: max_token_len : 2047 04:04:05 [33/133]
[I][ Init][ 224]: kv_cache_size : 256, kv_cache_num: 2047
[I][ Init][ 232]: prefill_token_num : 128
[I][ Init][ 236]: grp: 1, prefill_max_token_num : 1
[I][ Init][ 236]: grp: 2, prefill_max_token_num : 128
[I][ Init][ 236]: grp: 3, prefill_max_token_num : 256
[I][ Init][ 236]: grp: 4, prefill_max_token_num : 384
[I][ Init][ 236]: grp: 5, prefill_max_token_num : 512
[I][ Init][ 236]: grp: 6, prefill_max_token_num : 640
[I][ Init][ 236]: grp: 7, prefill_max_token_num : 768
[I][ Init][ 236]: grp: 8, prefill_max_token_num : 896
[I][ Init][ 236]: grp: 9, prefill_max_token_num : 1024
[I][ Init][ 240]: prefill_max_token_num : 1024
________________________
| ID| remain cmm(MB)|
========================
| 0| 2634|
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
[I][ load_config][ 282]: load config:
{
"enable_repetition_penalty": false,
"enable_temperature": true,
"enable_top_k_sampling": true,
"enable_top_p_sampling": false,
"penalty_window": 20,
"repetition_penalty": 1.2,
"temperature": 0.9,
"top_k": 10,
"top_p": 0.8
}
[I][ Init][ 263]: LLM init ok
Type "q" to exit, Ctrl+c to stop current running
[I][ GenerateKVCachePrefill][ 324]: input token num : 21, prefill_split_num : 1 prefill_grpid : 2
[I][ GenerateKVCachePrefill][ 367]: input_num_token:21
[I][ main][ 234]: precompute_len: 21
[I][ main][ 235]: system_prompt: You are Qwen, created by Alibaba Cloud. You are a helpful assistant.
prompt >> 埼玉県について教えて
[I][ SetKVCache][ 614]: prefill_grpid:2 kv_cache_num:128 precompute_len:21 input_num_token:13
[I][ SetKVCache][ 617]: current prefill_max_token_num:896
[I][ Run][ 855]: input token num : 13, prefill_split_num : 1
[I][ Run][ 887]: input_num_token:13
[I][ Run][1016]: ttft: 694.87 ms
埼玉県について説明します。埼玉県は日本の東北地方太平洋沖を挟って中国地方の南部に位置する県で、首都圏の中心に位置しています。以下に
玉県に関連するいくつかの重要な点をリストアップします。
1. 埼玉県の地理: ��県の面積は日本の県の中で第14位で、主に東京都と千葉県との間に位置しています。県の中心部分は千葉県と隣接してい
す。
2. 都道府県庁所在地: �玉 の県 �所在地 熊谷市です。
3. �光 : �玉 にはいくつかの観光地があります。特に武藏野都市公園や秩父には多くの人々が訪れる観光地があります。また、東秩父温泉
本 �神 などの温泉地や神社も有名です。
4. 鉄道: ��県は主要な鉄道路線が網羅されているため、東京方面、千葉県、神奈川県などへのアクセスが容易です。東武 �道 東武伊勢崎線
東京メトロ丸の内線などが主要な鉄道路線です。
5. 都市化: ��県は高度経 �成長 に多くの工業団地や住宅地が作られ、現在では人口は急速に増加しました。県の大部分は大規模な都市部や
市近郊地域に占められています。
6. 産業: 主な産業としては自動車産業や電子部品産業などが挙げられます。また、産業団地があり、多くの企業が進出しています。
以上の情報は埼玉県の概要を示していますが、県内には多くの地域があり、それぞれ特徴があるため、より具体的な情報が欲しい場合は詳細な地
について質問してください。
[N][ Run][1168]: hit eos,avg 5.48 token/s
[I][ GetKVCache][ 583]: precompute_len:462, remaining:562
Here's the part of output of tokenizer around "3.". You can see some "\ufffd" at the end and start of some text fragmentations.
接收到的数据: {"token_ids":[37541,3407,18],"uid":"d3c9a150-773f-4b8f-b4ed-6893ee76e312"}
127.0.0.1 - - [13/Oct/2025 04:07:50] "POST /decode HTTP/1.1" 200 -
响应消息: {"text": "\u3067\u3059\u3002\n\n3"}
POST 请求路径: /decode
接收到的数据: {"token_ids":[13,8908,99],"uid":"d3c9a150-773f-4b8f-b4ed-6893ee76e312"}
127.0.0.1 - - [13/Oct/2025 04:07:50] "POST /decode HTTP/1.1" 200 -
响应消息: {"text": ". \ufffd"}
POST 请求路径: /decode
接收到的数据: {"token_ids":[111,99225,29490],"uid":"d3c9a150-773f-4b8f-b4ed-6893ee76e312"}
127.0.0.1 - - [13/Oct/2025 04:07:51] "POST /decode HTTP/1.1" 200 -
响应消息: {"text": "\ufffd\u5149\u5730"}
POST 请求路径: /decode
接收到的数据: {"token_ids":[25,4891,253],"uid":"d3c9a150-773f-4b8f-b4ed-6893ee76e312"}
127.0.0.1 - - [13/Oct/2025 04:07:51] "POST /decode HTTP/1.1" 200 -
响应消息: {"text": ": \ufffd"}
POST 请求路径: /decode
接收到的数据: {"token_ids":[120,100658,70999],"uid":"d3c9a150-773f-4b8f-b4ed-6893ee76e312"}
127.0.0.1 - - [13/Oct/2025 04:07:52] "POST /decode HTTP/1.1" 200 -
响应消息: {"text": "\ufffd\u7389\u770c"}
try this one
@hammmm
https://github.com/AXERA-TECH/ax-llm/blob/ax-context/scripts/qwen2.5_tokenizer_uid.py
def decode(self, token_ids):
self.token_ids_cache += token_ids
text = self.tokenizer.decode(self.token_ids_cache)
if "\ufffd" in text and len(self.token_ids_cache) < 9:
print("text 中包含非法字符")
return ""
else:
self.token_ids_cache.clear()
return text.replace("\ufffd","")