【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)
相关推荐
大模型之路8 分钟前
Grok-3:人工智能领域的新突破
人工智能·llm·grok-3
一朵小花9 分钟前
Python中with的用法
python
m0_7482323933 分钟前
基于OpenCV和Python的人脸识别系统_django
python·opencv·django
喝不完一杯咖啡34 分钟前
【AI时代】可视化训练模型工具LLaMA-Factory安装与使用
人工智能·llm·sft·llama·llama-factory
dme.1 小时前
Python爬虫selenium验证-中文识别点选+图片验证码案例
爬虫·python
东方-教育技术博主1 小时前
wps中zotero插件消失,解决每次都需要重新开问题
python
guyoung1 小时前
DeepSeek轻量级本地化部署工具——AIMatrices DeepSeek
rust·llm·deepseek
可乐张1 小时前
AutoGen 技术博客系列 (九):从 v0.2 到 v0.4 的迁移指南
后端·llm
可乐张1 小时前
AutoGen 技术博客系列 (八):深入剖析 Swarm—— 智能体协作的新范式
后端·llm
镰圈量化2 小时前
当电脑上有几个python版本Vscode选择特定版本python
开发语言·vscode·python