Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

本地推理和用提供的demo推理结果不一致 #190

Closed
linsiwei123 opened this issue May 21, 2024 · 5 comments
Closed

本地推理和用提供的demo推理结果不一致 #190

linsiwei123 opened this issue May 21, 2024 · 5 comments

Comments

@linsiwei123
Copy link

本地推理和提供的demo结果不一致是为什么呢,请问demo具体的参数设置是什么呢

@xiaomuv58q666
Copy link

本地效果怎么演示?

@linsiwei123
Copy link
Author

我采用huggingface上提供的加载模型推理的方式,然后传入图片得到结果,和提供的chatdemo结果相差比较大
1716280288465

@czczup
Copy link
Member

czczup commented May 21, 2024

应该是因为推理的超参数设置不一样
image

@Qinger27
Copy link

我采用huggingface上提供的加载模型推理的方式,然后传入图片得到结果,和提供的chatdemo结果相差比较大 1716280288465

请问您使用的gpu是多大的显存?我用了两张32g的卡,模型加载时设置device_map="auto"进行推理, 但是报错RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cuda:1!,请问可以帮忙看一下吗?感谢~

@czczup
Copy link
Member

czczup commented May 30, 2024

found at least two devices

这个bug很多人都遇到了,我暂时没想到比较好的方法能够适配所有情况,有个方案可以解决,需要手工为模型分配设备。

比如这个模型总共26B,2张卡最理想的情况是每张卡13B。因此,除去ViT的6B以外,卡0还需要放7B,也就是20B的LLM有1/3在卡0,有2/3在卡1。

写成代码就是:

device_map = {
    'vision_model': 0,
    'mlp1': 0,
    'language_model.model.tok_embeddings': 0,
    'language_model.model.norm': 1,
    'language_model.output.weight': 1
}
for i in range(16):
    device_map[f'language_model.model.layers.{i}'] = 0
for i in range(16, 48):
    device_map[f'language_model.model.layers.{i}'] = 1
print(device_map)
model = AutoModel.from_pretrained(
    path,
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    trust_remote_code=True,
    device_map=device_map
).eval()

@czczup czczup closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants