Comments (2)
找到原因了,流式输出时,模型的response是通过对每个step的token单独解码,然后和历史response拼接,作为当前step的response,这样子有个问题,例如”淩“,对应的token是[233, 186, 172],单独对233、186、172解码会出现”�“,拼接后会输出”���“。
我的解决办法是解码时如果出现乱码,缓存当前step的token,然后继续下个step,直到缓存的长度超过限制(5)或解码出明文,则清空缓存的token。
修改modeling_internlm.py中stream_chat()方法中ChatStreamer类:
class ChatStreamer(BaseStreamer):
def __init__(self, tokenizer) -> None:
super().__init__()
self.tokenizer = tokenizer
self.queue = response_queue
self.query = query
self.history = history
self.response = ""
self.cache = []
self.received_inputs = False
self.queue.put((self.response, history + [(self.query, self.response)]))
def put(self, value):
if len(value.shape) > 1 and value.shape[0] > 1:
raise ValueError("ChatStreamer only supports batch size 1")
elif len(value.shape) > 1:
value = value[0]
if not self.received_inputs:
# The first received value is input_ids, ignore here
self.received_inputs = True
return
self.cache.extend(value.tolist())
token = self.tokenizer.decode(self.cache, skip_special_tokens=True)
if "�" in token and len(token) <= 5:
return
self.cache = []
if token.strip() != "<eoa>":
self.response = self.response + token
history = self.history + [(self.query, self.response)]
self.queue.put((self.response, history))
else:
self.end()
from internlm.
Brilliant! Would you like to create a PR to fix it as a new contributor?
from internlm.
Related Issues (20)
- [QA] 如果想基于internLM使用领域数据微调出一个领域模型,应该使用internLM-20B-chat还是internLM-20B-sft? HOT 3
- [Bug] llama.cpp internlm2 function calling bug HOT 6
- [QA] 如何提升推理速度? HOT 2
- 请问是否支持在MindSpore的910A或者910B上部署? HOT 5
- [QA] 书生2模型有关chat_template的问题 HOT 5
- [Bug] 微调eval阶段使用generate的结果会出现</s> HOT 2
- 请问是否支持200k上文的微调,需要什么样的配置?[QA] HOT 2
- [QA] InternLM 2 对文字种类的识别, 生成能力以及微调相关问题 HOT 6
- [Bug] InternLM2 int4 出现重复说话、重复前置内容(system prompt)现象 HOT 11
- [Bug] When loading a model by using transformers and using stream chat, it seems no whitespace character in English response. HOT 1
- [QA] Number of training tokens for Internlm2 1.8B, 7B, and 20B? HOT 3
- [QA] 请问是否会开源PPO的训练code和reward model? HOT 1
- [Feature] 是否已经支持tensorrt-llm或者计划支持? HOT 2
- [Bug] Special tokens are still mismatched. HOT 2
- [Bug] internlm2-chat-20b huggingface下载503报错,模型不存在
- 一人血书求讲解怎么来洗数据! HOT 5
- 万人血书 InternLM2-4B ❗❕❗❕❗ HOT 1
- [QA] Can internlm2 be supported in fastchat? HOT 6
- [Bug] failing everytime and getting CUDA out of memory HOT 6
- [Bug] internlm2_chat_1.8b 模型不支持多轮对话 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from internlm.