You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
已解决。原因是:有的需要两个或多个tokenid才能解码出有意义的字符,单个tokenid解码出来的可能是无意义的乱码。解决办法:1.通过try-catch捕获UnicodeDecodeError异常,然后将多个tokenid拼在一起解码。2.通过ret_byte=model.weight.tokenizer.decode_byte([token_id]); res = ret_byte.decode(errors='ignore')去解码。建议使用方法2。
【现象】
qwen1.5-14B-Chat模型在解码时报UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 1: unexpected end of data。
【描述】
模型输入是:假设f(x)=x,那么f(x)1到2的积分是多少。模型输出的tokenId包含11995、18137,这两个tokenId会导致上述异常。它们在词表中对应的是特殊字符,解码tokenId的方法是:model = pyfastllm.create_llm(model_path); model.weight.tokenizer.decode([11995, 18137])。另外尝试用原始模型的tokenizer解码是可以解码的,只是显示出来的是人类无法理解的字符,它不抛上述解码异常。我觉得1是要处理解码异常的问题,2是生成的tokenId应该是有问题的,即使它们被正常解码出来了,它们似乎与问题也不太相关。
【flm模型转换方法】
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained(xxx, trust_remote_code = True)
model = AutoModel.from_pretrained(xxx, trust_remote_code = True)
from fastllm_pytools import llm
model = llm.from_hf(model, tokenizer, dtype = "int8")
model.save("model.flm")
【模型推理方法】
prompt_input = “假设f(x)=x,那么f(x)1到2的积分是多少”
model = pyfastllm.create_llm("model.flm")
input_ids = model.weight.tokenizer.encode(prompt_input)
handle = model.launch_response(input_ids)
...
resp_token = model.fetch_response(handle)
content = model.weight.tokenizer.decode([resp_token])
print(content)
The text was updated successfully, but these errors were encountered: