mlc-ai / mlc-llm

Universal LLM Deployment Engine with ML Compilation
https://llm.mlc.ai/
Apache License 2.0
19.26k stars 1.58k forks source link

[Streamer] Fix UTF-8 handling in streamer #2978

Closed MasterJH5574 closed 1 month ago

MasterJH5574 commented 1 month ago

This PR fixes a bug in the streamer handling for UTF-8 characters. Prior to this PR, the streamer has an assumption that a replacement character () always correspond to an entire token. However, for the Qwen2 model tokenizer, some token can be if decoded directly, which breaks the assumption and leads to incorrect result generated by the streamer.

This PR fixes this issue with a safer behavior that does not rely on such an assumption.