近日,通义千问团队震撼开源 Qwen1.5 系列首个千亿参数模型 Qwen1.5-110B-Chat。
千亿级大模型普通显卡是跑不了推理的,普通人一般也没办法本地运行千亿级大模型。
为了探索千亿级大模型到底需要计算资源,我用云计算资源部署了Qwen1.5-110B-Chat,看看部署它到底需要多少存储资源,并且测试在不量化、8bit量化、4bit量化下的显存消耗。
一、下载模型
#模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('qwen/Qwen1.5-110B-Chat', cache_dir='path/to/local/dir')
下载后模型目录结构如下:
.
├── config.json
├── configuration.json
├── generation_config.json
├── LICENSE
├── merges.txt
├── model-00001-of-00062.safetensors
├── model-00002-of-00062.safetensors
├── model-00003-of-00062.safetensors
├── model-00004-of-00062.safetensors
├── model-00005-of-00062.safetensors
...
├── model-00062-of-00062.safetensors
├── model.safetensors.index.json
├── out.txt
├── README.md
├── tokenizer_config.json
├── tokenizer.json
└── vocab.json
0 directories, 73 files
模型Qwen1.5-110B-Chat共占用硬盘空间208G。
二、显卡消耗
按照计算公式:模型显存占用(GB) = 大模型参数(B)*2
那么Qwen1.5-110B-Chat的显存占用量应该为220GB。
实际在部署过程中,没有考虑任何量化技术,占用显存215GB。
因此,如果你想完整部署Qwen1.5-110B-Chat,不考虑任何量化技术,需要3块80GB显存的显卡。
当然你可以玩量化,在 Transformers 中使用 LLM.int8() 只需提前安装pip install bitsandbytes
即可,使用 LLM.int8() 方法量化transformer模型具体示例如下:
8bit量化
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
'qwen/Qwen1___5-110B-Chat',
device_map=