From 04c019af9ca6bca2b6f695c6a46f95875dc66ba5 Mon Sep 17 00:00:00 2001 From: Aohan Zeng Date: Tue, 14 Mar 2023 01:00:40 +0800 Subject: [PATCH] Update README.md --- README.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index aa45f7a..a262986 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ # ChatGLM-6B ## 介绍 -ChatGLM-6B 是一个开源的、支持中英双语问答和对话的预训练语言模型,基于 [General Language Model (GLM)](https://github.com/THUDM/GLM) 架构,具有 62 亿参数。ChatGLM-6B 使用了和 ChatGLM(内测中,地址 [https://chatglm.cn](https://chatglm.cn))相同的技术面向中文问答和对话进行优化。 +ChatGLM-6B 是一个开源的、支持中英双语问答和对话的预训练语言模型,基于 [General Language Model (GLM)](https://github.com/THUDM/GLM) 架构,具有 62 亿参数。ChatGLM-6B 使用了和 ChatGLM(内测中,地址 [https://chatglm.cn](https://chatglm.cn))相同的技术面向中文问答和对话进行优化。结合 INT4 量化技术,用户可以在消费级的显卡上进行本地部署(最低只需 6GB 显存)。在约 1T tokens 训练量、监督微调、反馈自助、人类反馈强化学习等技术的加持下,62 亿参数的模型已经能生成相当符合人类偏好的回答。 + +## 硬件需求 + +| **量化等级** | **最低 GPU 显存** | +| -------------- | ----------------- | +| FP16(无量化) | 19 GB | +| INT8 | 10 GB | +| INT4 | 6 GB | ## 使用方式 -使用前请先安装`transformers>=4.23.1`和`icetk`。 -```shell -pip install "transformers>=4.23.1,icetk" -``` +使用前请先按照安装依赖:`pip install -r requirements.txt`,其中 transformers 的版本需要大于 4.23.1。 ### 代码调用 @@ -34,6 +39,7 @@ print(history) ### Demo 我们提供了一个基于 [Gradio](https://gradio.app) 的网页版 Demo 和一个命令行 Demo。使用时首先需要下载本仓库: + ```shell git clone https://github.com/THUDM/ChatGLM-6B cd ChatGLM-6B @@ -70,24 +76,23 @@ python cli_demo.py 程序会在命令行中进行交互式的对话,在命令行中输入指示并回车即可生成回复,输入`clear`可以清空对话历史,输入`stop`终止程序。 ## 模型量化 -默认情况下,模型以 FP16 精度加载,运行上述代码需要大概 13GB 显存。如果你的 GPU 显存有限,可以尝试使用 `transformers` 提供的 8bit 量化功能,即将代码中的 +默认情况下,模型以 FP16 精度加载,运行上述代码需要大概 19GB 显存。如果你的 GPU 显存有限,可以尝试允许量化后的模型,即将下述代码 ```python model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda() ``` -替换为(8bit 量化) - +替换为(8-bit 量化) ```python model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().quantize(8).cuda() ``` -或者(4bit 量化) +或者(4-bit 量化) ```python model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().quantize(4).cuda() ``` -使用 8-bit 量化之后大约需要 8GB 的 GPU 显存,使用 4-bit 量化之后大约需要 4GB 的 GPU 显存。 +进行 2 至 3 轮对话后,8-bit 量化下约占用 10GB 的 GPU 显存,4-bit 量化仅需占用 6GB 的 GPU 显存。随着对话轮数的增多,对应消耗显存也随之增长。 ## 引用 @@ -111,4 +116,4 @@ model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).ha pages={320--335}, year={2022} } -``` \ No newline at end of file +```