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

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

model_name memory
qwen2-7b-int8 11.6G
qwen2-7b-int4 8.5G
qwen2-1.5b 4.2G
qwen2-1.5b-int8 3G
qwen2-1.5b-int4 2.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/

测试代码
参考的官方调用

python 复制代码
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"  # the device to load the model onto


model_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)
相关推荐
程序员小远7 分钟前
selenium元素定位---(元素点击交互异常)解决方法
自动化测试·软件测试·python·selenium·测试工具·测试用例·交互
ColderYY12 分钟前
DrissionPage自动化
python·自动化
Python大数据分析@14 分钟前
如何用 Python xlwings库自动化操作 Excel?
python·自动化·excel
qq_124987075333 分钟前
基于Flask的穷游网酒店数据分析系统(源码+论文+部署+安装)
后端·python·flask·毕业设计
Brianna Home41 分钟前
PyTorch实战:CV模型搭建全指南
人工智能·pytorch·经验分享·python·神经网络·结对编程
喜欢吃豆1 小时前
spec-kit深度解析:AI驱动的规范驱动开发(SDD)的架构、哲学与实践启示
人工智能·驱动开发·python·架构·大模型
rengang661 小时前
28-Keras:探讨高层神经网络API及其快速原型设计能力
人工智能·python·神经网络·机器学习·keras
椰羊sqrt1 小时前
MetaTwo靶机实战:SQL注入到权限提升全解析
python·学习·网络安全
程序员大雄学编程1 小时前
「用Python来学微积分」17. 导数与导函数
开发语言·python·数学·微积分
数据智能老司机1 小时前
使用 Python 入门 Model Context Protocol(MCP)——深入解析模型上下文协议(MCP)
llm·agent·mcp