ChatGLM-6B 是一個開源的、支持中英雙語問答的對話語言模型,基于 General Language Model (GLM) 架構,具有 62 億參數(shù)。結合模型量化技術,用戶可以在消費級的顯卡上進行本地部署(INT4 量化級別下最低只需 6GB 顯存)。ChatGLM-6B 使用了和 ChatGLM 相同的技術,針對中文問答和對話進行了優(yōu)化。經過約 1T 標識符的中英雙語訓練,輔以監(jiān)督微調、反饋自助、人類反饋強化學習等技術的加持,62 億參數(shù)的 ChatGLM-6B 已經能生成相當符合人類偏好的回答。
ChatGLM-6B-INT8 是 ChatGLM-6B 量化后的模型權重。具體的,ChatGLM-6B-INT8 對 ChatGLM-6B 中的 28 個 GLM Block 進行了 INT8 量化,沒有對 Embedding 和 LM Head 進行量化。量化后的模型理論上 8G 顯存(使用 CPU 即內存)即可推理,具有在嵌入式設備(如樹莓派)上運行的可能。
在 CPU 上運行時,會根據(jù)硬件自動編譯 CPU Kernel ,請確保已安裝 GCC 和 OpenMP (Linux一般已安裝,對于Windows則需手動安裝),以獲得最佳并行計算能力。
本模型環(huán)境需安裝最新版的modelscope
pip install modelscope==1.4.3 -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
可以通過如下代碼調用 ChatGLM-6B-int8 模型來生成對話:
from modelscope.utils.constant import Tasks
from modelscope.pipelines import pipeline
pipe = pipeline(task=Tasks.chat, model='thomas/ChatGLM-6B-Int8', model_revision='v1.0.3')
inputs = {'text':'你好', 'history': []}
result = pipe(inputs)
inputs = {'text':'介紹下清華大學', 'history': result['history']}
result = pipe(inputs)
print(result)
關于更多的使用說明,包括如何運行命令行和網(wǎng)頁版本的 DEMO,以及使用模型量化以節(jié)省顯存,請參考我們的 Github Repo。
本倉庫的代碼依照 Apache-2.0 協(xié)議開源,ChatGLM-6B 模型的權重的使用則需要遵循 Model License。
如果你覺得我們的工作有幫助的話,請考慮引用下列論文:
@inproceedings{
zeng2023glm-130b,
title={{GLM}-130B: An Open Bilingual Pre-trained Model},
author={Aohan Zeng and Xiao Liu and Zhengxiao Du and Zihan Wang and Hanyu Lai and Ming Ding and Zhuoyi Yang and Yifan Xu and Wendi Zheng and Xiao Xia and Weng Lam Tam and Zixuan Ma and Yufei Xue and Jidong Zhai and Wenguang Chen and Zhiyuan Liu and Peng Zhang and Yuxiao Dong and Jie Tang},
booktitle={The Eleventh International Conference on Learning Representations (ICLR)},
year={2023},
url={https://openreview.net/forum?id=-Aw0rrrPUF}
}
@inproceedings{du2022glm,
title={GLM: General Language Model Pretraining with Autoregressive Blank Infilling},
author={Du, Zhengxiao and Qian, Yujie and Liu, Xiao and Ding, Ming and Qiu, Jiezhong and Yang, Zhilin and Tang, Jie},
booktitle={Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
pages={320--335},
year={2022}
}