大模型(LLMs)推理篇
1. 为什么大模型推理时显存涨的那么多还一直占着?
- 首先,序列太长了,有很多Q/K/V;
- 其次,因为是逐个预测next token,每次要缓存K/V加速解码。
大模型在gpu和cpu上推理速度如何?
7B量级下:
- cpu推理速度约10token/s;
- 单卡A6000和8核AMD的推理速度通常为 10:1。
推理速度上,int8和fp16比起来怎么样?
根据实践经验,int8模式一般推理会明显变慢(huggingface的实现)
大模型有推理能力吗?
大模型有推理能力。有下面2个方面的体现:
ChatGPT拥有in-context correction的能力,即如果说错了,给出矫正,ChatGPT能"听懂"错在哪儿了,并向正确的方向修正。in-context correction要比in-context learning难了太多,描述越详细清楚,ChatGPT回答得越好。要知道,越详细的描述,在预训练的文本里越难匹配到的。
在询问ChatGPT互联网上并不存在内容的时候,能给出较好答案(如用ChatGPT学建模);ChatGPT能通过信息猜你心中的想法;你可以制定一个全新的游戏规则让ChatGPT和你玩,ChatGPT可以理解。
大模型生成时的参数怎么设置?
生成模型预测调参建议:
建议去调整下 top_p, num_beams, repetition_renalty, temperature, do_sample=True;
数据生成有重复,调高repetition_renalty;
生成任务表达单一的,样本也不多的,可适当调低 temperature,生成的样子跟训练集的比较像;如果要复现训练集的效果,temperature=0.01即可。
以上是经验参数,具体调参根据任务而定,不是固定的。
•参数解释:
top_p=0.9,
#Moderately increase the probability threshold of nucleus sampling to increase the quantity of candidate tokens and increase generation diversity.
temperature=1.0,
#The previous low temperature parameter could lead to a severe polarization in the probability distribution of generated words, which degenerates the generation strategy into greedy decoding.
do_sample=True,
#do_sample parameter is set to False by default. After setting to True, the generation m