【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)
相关推荐
大模型教程11 小时前
RAG 系统架构设计模式介绍
程序员·llm·agent
无心水11 小时前
【Python实战进阶】4、Python字典与集合深度解析
开发语言·人工智能·python·python字典·python集合·python实战进阶·python工业化实战进阶
上班职业摸鱼人11 小时前
python文件中导入另外一个模块这个模块
python
永远是夏天11 小时前
Python面向对象编程(OOP)全教程:从入门到实战(附案例)
python
AI大模型11 小时前
Google 官方白皮书Prompt Engineering 深度解读
程序员·llm·agent
AI大模型12 小时前
谷歌这本 68 页提示词手册,才是 Gemini 3 Pro 的完全体「附官方内功心法」
程序员·llm·agent
动感小麦兜12 小时前
服务器搭建
linux·服务器·python
Pocker_Spades_A12 小时前
在家写的代码,办公室接着改?Jupyter通过cpolar实现远程访问这么玩
ide·python·jupyter
m5655bj13 小时前
使用 Python 高效复制 Excel 行、列、单元格
开发语言·python·excel
龙言龙论13 小时前
身份证信息批量处理系统:从入门到实战(附exe工具+核心源码)
数据库·python