[论文笔记] 大模型gpu机器推理测速踩坑 (llama/gpt类)

cpu没报错,换gpu就报错。以下是一些踩坑:

坑1:要指定gpu,可以在import torch之前指定gpu。

model = LlamaForCausalLM.from_pretrained(model_path, trust_remote_code=True).to(device)

报错: RuntimeError(‘Expected all tensors to be on the same device, but found at least two devices, cuda:6 and cuda:0! (when checking argument for argument index in method wrapper_CUDA__index_select)’)

坑2:model和input_ids都需要 .to(device),tokenizer不需要。

坑3:不要用device_map=”auto”,不然变量不在一张卡上。就算model和输入都to(device)了,也会报错。

报错:You can’t move a model that has some modules offloaded to cpu or disk.

可以检查参数都在哪个卡,cpu/gpu。但是这样其实检查不出来啥:

坑4:custom_llama不能用AutoModelForCausalLM,要用LlamaForCausalLM。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年12月26日
下一篇 2023年12月26日

相关推荐