赞
踩
ChatGLM2-6B 是开源中英双语对话模型 ChatGLM-6B 的第二代版本,在保留了初代模型对话流畅、部署门槛较低等众多优秀特性的基础之上,ChatGLM2-6B 引入了如下新特性:
参考视频:ChatGLM+Langchain构建本地知识库,只需6G显存,支持实时上传文档_哔哩哔哩_bilibili
可以查看目前使用的系统版本信息。
- $cat /proc/version
-
- Linux version 5.15.133.1-microsoft-standard-WSL2 (root@1c602f52c2e4) (gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP Thu Oct 5 21:02:42 UTC 2023
如果安装有显卡驱动,可以使用下面的代码来查看显卡信息。
- nvidia-smi #查看显卡信息
-
- Sat Mar 9 19:31:33 2024
- +-----------------------------------------------------------------------------------------+
- | NVIDIA-SMI 550.40.06 Driver Version: 551.23 CUDA Version: 12.4 |
- |-----------------------------------------+------------------------+----------------------+
- | 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 3090 On | 00000000:AF:00.0 Off | N/A |
- | 32% 25C P8 6W / 350W | 134MiB / 24576MiB | 0% Default |
- | | | N/A |
- +-----------------------------------------+------------------------+----------------------+
- | 1 NVIDIA GeForce RTX 3090 On | 00000000:D8:00.0 Off | N/A |
- | 32% 24C P8 11W / 350W | 144MiB / 24576MiB | 0% Default |
- | | | N/A |
- +-----------------------------------------+------------------------+----------------------+
-
- +-----------------------------------------------------------------------------------------+
- | Processes: |
- | GPU GI CI PID Type Process name GPU Memory |
- | ID ID Usage |
- |=========================================================================================|
- | 0 N/A N/A 227 G /Xwayland N/A |
- | 1 N/A N/A 227 G /Xwayland N/A |
- +-----------------------------------------------------------------------------------------+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
git clone https://github.com/THUDM/ChatGLM2-6B.git
国内访问GitHub可能较慢,可以使用镜像:
git clone https://gitclone.com/github.com/THUDM/ChatGLM2-6B.git
- conda create --name chatglm python=3.10
- conda activate chatglm
- cd ChatGLM2-6B/
下载依赖:
pip install -r requiremnets.txt
- Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
- Collecting protobuf (from -r requirements.txt (line 1))
- Downloading https://pypi.tuna.tsinghua.edu.cn/packages/39/3f/16bdd9d43b024c1d178e817826e4e1ca8a25da3faff1e7566f341094143d/protobuf-5.26.0-cp37-abi3-manylinux2014_x86_64.whl (302 kB)
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 302.8/302.8 kB 4.6 MB/s eta 0:00:00
- Collecting transformers==4.27.1 (from -r requirements.txt (line 2))
- Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6d/9b/2f536f9e73390209e0b27b74691355dac494b7ec8154f3012fdc6debbae7/transformers-4.27.1-py3-none-any.whl (6.7 MB)
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.7/6.7 MB 3.0 MB/s eta 0:00:00
- Collecting cpm_kernels (from -r requirements.txt (line 3))
- Using cached https://pypi.tuna.tsinghua.edu.cn/packages/af/84/1831ce6ffa87b8fd4d9673c3595d0fc4e6631c0691eb43f406d3bf89b951/cpm_kernels-1.0.11-py3-none-any.whl (416 kB)
- Collecting torch>=2.0 (from -r requirements.txt (line 4))
- Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a7/ad/fbe7d4cffb76da4e478438853b51305361c719cff929ab70a808e7fb75e7/torch-2.2.1-cp310-cp310-manylinux1_x86_64.whl (755.5 MB)
- ━━━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 162.2/755.5 MB 1.8 MB/s eta 0:05:23
git clone https://gitee.com/hf-models/chatglm2-6b.git
- from transformers import AutoTokenizer, AutoModel
-
- tokenizer = AutoTokenizer.from_pretrained("/home/david/20240207/ChatGLM2-6B/model/chatglm2-6b",trust_remote_code=True)
- model = AutoModel.from_pretrained("/home/david/20240207/ChatGLM2-6B/model/chatglm2-6b",trust_remote_code=True).quantize(4).half().cuda()
- model = model.eval()
-
-
- response, history = model.chat(tokenizer,"你好",history=[])
- print(response)
- response, history = model.chat(tokenizer,"晚上睡不着应该怎么办",history=history)
- print(response)
-
- $python main.py
-
- Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
- Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
- Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
- Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████████████████| 7/7 [00:10<00:00, 1.48s/it]
- 你好声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/817549推荐阅读
相关标签
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。