欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > 【LLM】qwen2本地部署显存占用情况(base3080-12G)

【LLM】qwen2本地部署显存占用情况(base3080-12G)

2024/10/24 4:51:55 来源:https://blog.csdn.net/u013347145/article/details/141743630  浏览:    关键词:【LLM】qwen2本地部署显存占用情况(base3080-12G)

避免辣鸡网站隐藏后文,先上结论

model_namememory
qwen2-7b-int811.6G
qwen2-7b-int48.5G
qwen2-1.5b4.2G
qwen2-1.5b-int83G
qwen2-1.5b-int42.5G

btw: ollama部署的qwen2-1.5b只需要0.9G ,vllm需要4G,不知道是不是量化差异
btw: ollama部署qwen2-1.5b模型是0.9G,显存占用是2G,qwen2-7b模型4G,显存5G,在1070显卡也能跑,但是7b会比较慢

测试环境

  • windows11
  • python310
  • torch2.1
  • cuda12.1
  • 显卡:RTX-3080-12G

模型来源
https://hf-mirror.com/

测试代码
参考的官方调用

from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"  # the device to load the model ontomodel_path = 'path/to/your/model'
model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype="auto",device_map="auto"
)
model = model.bfloat16()  # 解决量化模型报错
print('model ok')tokenizer = AutoTokenizer.from_pretrained(model_path)
print('tokenizer ok')prompt = "Give me a short introduction to large language model. response using chinese"
messages = [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": prompt}
]
print(prompt)text = tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)generated_ids = model.generate(model_inputs.input_ids,max_new_tokens=512
)
generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com