【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)
相关推荐
格鸰爱童话12 分钟前
向AI学习项目技能(二)
java·人工智能·python·学习
Sagittarius_A*16 分钟前
傅里叶变换:从空域到频域的图像分析【计算机视觉】
图像处理·人工智能·python·opencv·计算机视觉·傅里叶变换·频域滤波
Pyeako23 分钟前
深度学习--循环神经网络原理&局限&与LSTM解决方案
人工智能·python·rnn·深度学习·lstm·循环神经网络·遗忘门
困死,根本不会29 分钟前
蓝桥杯python备赛笔记之(八)动态规划(DP)
笔记·python·学习·算法·蓝桥杯·动态规划
weixin1997010801629 分钟前
货铺头商品详情页前端性能优化实战
java·前端·python
深蓝电商API36 分钟前
爬虫监控告警:结合企业微信或钉钉,打造 7×24 小时实时预警系统
爬虫·python·钉钉·企业微信
懷淰メ38 分钟前
python3GUI--socket+PyQt5开发局域网微信(含功能、详细介绍、分享)
python·学习·gui·大学生·pyqt5·微信界面
risc12345640 分钟前
channel.read(dest, channelPosition) 的读取大小限制
开发语言·python
xixixi777771 小时前
拥抱AI大模型时代:开发者如何利用智能编程工具提升效率
人工智能·python·ai·大模型·aigc·代码
李昊哲小课1 小时前
Python 高级数据结构
开发语言·数据结构·python