【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)
相关推荐
漂流瓶jz28 分钟前
【AI】大模型LoRA微调原理与实验:基于CMRC2018与Qwen3-0.6B训练实测
人工智能·算法·llm
羲云网络2 小时前
GPT Image 2.6 海报改横竖版:文字安全区、排版分离与交付验收
图像处理·人工智能·python·aigc
曲径海盗3 小时前
【Python 学习第 65 天】字典基础
python·学习笔记·编程入门
Wellijohn3 小时前
Docker 瘦身、手写 MCP、异步并发:被问得最多的 12 个问题,一次答完
python·docker·mcp
明川4 小时前
RAG 到底是什么
人工智能·llm
VW_4046 小时前
csdn-2026-11-23-第一站踩坑
爬虫·python
yiangL_7 小时前
课后作业4:基于 Python 的古诗词词云可视化(P205)
开发语言·python
Dmz丶7 小时前
前端转 AI 100 天 Day 52:RAG 项目实战(一)——从零搭建企业知识库
python
卷无止境10 小时前
用 SimPy 做离散事件仿真:时钟不走步,事件自己排队
后端·python
撸码猿11 小时前
数据采集场景的语序点选验证码:90.2% 整词准确率的本地 OCR 实践
python·ocr