1.ChatGLM2 介绍
ChatGLM2-6B 是开源中英双语对话模型 ChatGLM-6B 的第二代版本,在保留了初代模型对话流畅、部署门槛较低等众多优秀特性的基础之上,ChatGLM2-6B 引入了如下新特性:
更强大的性能:基于 ChatGLM 初代模型的开发经验,我们全面升级了 ChatGLM2-6B 的基座模型。ChatGLM2-6B 使用了 GLM 的混合目标函数,经过了 1.4T 中英标识符的预训练与人类偏好对齐训练,评测结果显示,相比于初代模型,ChatGLM2-6B 在 MMLU(+23%)、CEval(+33%)、GSM8K(+571%) 、BBH(+60%)等数据集上的性能取得了大幅度的提升,在同尺寸开源模型中具有较强的竞争力。
更长的上下文:基于 FlashAttention 技术,我们将基座模型的上下文长度(Context Length)由 ChatGLM-6B 的 2K 扩展到了 32K,并在对话阶段使用 8K 的上下文长度训练,允许更多轮次的对话。但当前版本的 ChatGLM2-6B 对单轮超长文档的理解能力有限,我们会在后续迭代升级中着重进行优化。
更高效的推理:基于 Multi-Query Attention 技术,ChatGLM2-6B 有更高效的推理速度和更低的显存占用:在官方的模型实现下,推理速度相比初代提升了 42%,INT4 量化下,6G 显存支持的对话长度由 1K 提升到了 8K。
更开放的协议:ChatGLM2-6B 权重对学术研究完全开放,在获得官方的书面许可后,亦允许商业使用。如果您发现我们的开源模型对您的业务有用,我们欢迎您对下一代模型 ChatGLM3 研发的捐赠。
2.项目介绍
本项目提供了 ChatGLM2-6B 非量化版本在 windows 平台 2张3060显卡机型上进行部署、推理测试教程
3.环境配置
AMD Ryzen 5 3500X 6-Core Processor 3.59 GHz
内存 32.0 GB
Windows 10 企业版
2张N卡:
NVIDIA GeForce RTX 3060 Ti 8G显存
NVIDIA GeForce RTX 3060 12G显存
大容量硬盘:12T
https://blog.csdn.net/weixin_44626085/article/details/132919803
4.vsc创建ai_test.ipynb
通过配置jupter来运行后面的程序
vsc选ipykernel:
http://127.0.0.1:8888/tree?token=11c74157a160f6f8f6a1d4a0791ee24c549f78eb4bb8d402
# 确认GPU型号与显存大小
(base) ai001@CHINAMI-I6IUQDH:~$ nvidia-smi
Thu Apr 4 13:35:23 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.104.07 Driver Version: 537.34 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3060 Ti On | 00000000:04:00.0 On | N/A |
| 0% 48C P8 9W / 200W | 921MiB / 8192MiB | 1% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
| 1 NVIDIA GeForce RTX 3060 On | 00000000:07:00.0 Off | N/A |
| 30% 44C P8 7W / 170W | 12115MiB / 12288MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 38 G /Xwayland N/A |
| 0 N/A N/A 206890 C /python3.9 N/A |
| 1 N/A N/A 38 G /Xwayland N/A |
| 1 N/A N/A 206890 C /python3.9 N/A |
+---------------------------------------------------------------------------------------+
5.环境准备
5.1 目录位置设置
!pwd
!cd /mnt/e/AI-lab/ChatGLM2-6B/
# 检查模型文件正确挂载
!ls -lh /mnt/e/AI-lab/ChatGLM2-6B/
/mnt/e/AI-lab/ChatGLM2-6B
total 12G
-rwxrwxrwx 1 ai001 ai001 6.1K Apr 1 19:21 '=1.24.0'
-rwxrwxrwx 1 ai001 ai001 16K Apr 1 22:11 '=2.0'
-rwxrwxrwx 1 ai001 ai001 946 Sep 13 2023 FAQ.md
-rwxrwxrwx 1 ai001 ai001 4.1K Sep 13 2023 MODEL_LICENSE
-rwxrwxrwx 1 ai001 ai001 4.1K Sep 16 2023 MODEL_LICENSE.txt
-rwxrwxrwx 1 ai001 ai001 8.1K Sep 16 2023 README.md
-rwxrwxrwx 1 ai001 ai001 16K Sep 13 2023 README_EN.md
drwxrwxrwx 1 ai001 ai001 4.0K Sep 16 2023 __pycache__
-rwxrwxrwx 1 ai001 ai001 64K Apr 4 13:50 ai_test.ipynb
-rwxrwxrwx 1 ai001 ai001 2.1K Sep 13 2023 api.py
-rwxrwxrwx 1 ai001 ai001 69K Apr 1 23:02 chatglm2-6b.ipynb
-rwxrwxrwx 1 ai001 ai001 2.3K Apr 1 21:36 cli_demo.py
-rwxrwxrwx 1 ai001 ai001 1.3K Sep 16 2023 config.json
-rwxrwxrwx 1 ai001 ai001 2.3K Sep 16 2023 configuration_chatglm.py
drwxrwxrwx 1 ai001 ai001 4.0K Sep 13 2023 evaluation
-rwxrwxrwx 1 ai001 ai001 1.5K Sep 16 2023 gitattributes.txt
-rwxrwxrwx 1 ai001 ai001 54K Sep 16 2023 modeling_chatglm.py
-rwxrwxrwx 1 ai001 ai001 5.6K Sep 13 2023 openai_api.py
-rwxrwxrwx 1 ai001 ai001 45K Apr 4 12:36 p-tuning-v2.ipynb
drwxrwxrwx 1 ai001 ai001 4.0K Apr 3 21:17 ptuning
-rwxrwxrwx 1 ai001 ai001 1.8G Sep 14 2023 pytorch_model-00001-of-00007.bin
-rwxrwxrwx 1 ai001 ai001 1.9G Sep 14 2023 pytorch_model-00002-of-00007.bin
-rwxrwxrwx 1 ai001 ai001 1.8G Sep 14 2023 pytorch_model-00003-of-00007.bin
-rwxrwxrwx 1 ai001 ai001 1.7G Sep 14 2023 pytorch_model-00004-of-00007.bin
...
-rwxrwxrwx 1 ai001 ai001 2.3K Sep 13 2023 utils.py
-rwxrwxrwx 1 ai001 ai001 2.3K Sep 16 2023 utils.py.1
-rwxrwxrwx 1 ai001 ai001 4.2K Apr 1 21:31 web_demo.py
-rwxrwxrwx 1 ai001 ai001 2.5K Sep 13 2023 web_demo2.py
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
5.2 模型需要的python组件安装
!pip install -r requirements.txt -i https://mirror.sjtu.edu.cn/pypi/web/simple