【大模型】更强的 ChatGLM3-6B 来了,开源可商用

在这里插入图片描述

简介

ChatGLM3-6B

ChatGLM3-6B 是 ChatGLM 系列最新一代的开源模型,在保留了前两代模型对话流畅、部署门槛低等众多优秀特性的基础上,ChatGLM3-6B 引入了如下特性:

  1. 更强大的基础模型: ChatGLM3-6B 的基础模型 ChatGLM3-6B-Base 采用了更多样的训练数据、更充分的训练步数和更合理的训练策略。在语义、数学、推理、代码、知识等不同角度的数据集上测评显示,ChatGLM3-6B-Base 具有在 10B 以下的预训练模型中最强的性能
  2. 更完整的功能支持: ChatGLM3-6B 采用了全新设计的 Prompt 格式,除正常的多轮对话外。同时原生支持工具调用(Function Call)、代码执行(Code Interpreter)和 Agent 任务等复杂场景。
  3. 更全面的开源序列: 除了对话模型 ChatGLM3-6B 外,还开源了基础模型 ChatGLM-6B-Base、长文本对话模型 ChatGLM3-6B-32K。以上所有权重对学术研究完全开放,在填写问卷进行登记后亦允许免费商业使用

环境配置

环境搭建

具体搭建过程参考:
【AI实战】最强开源 6B 中文大语言模型ChatGLM3-6B,从零开始搭建
- ChatGLM2-6B 搭建

安装依赖

pip install protobuf transformers==4.30.2 cpm_kernels torch>=2.0 gradio mdtex2html sentencepiece accelerate

代码及模型权重拉取

拉取 ChatGLM3-6B

git clone https://github.com/THUDM/ChatGLM3-6B

github网站偶尔会抽风,需要耐心等待,如果失败了,再重新拉取

拉取 ChatGLM3-6B 模型权重及代码

cd ChatGLM3-6B
git clone https://huggingface.co/THUDM/chatglm3-6b

由于权重文件特别大,如果失败了,执行 rm -rfi ChatGLM3-6B,再重新拉取。

查看文件列表:

ls -l ChatGLM3-6B

输出:

.gitattributes  1.52 kB
MODEL_LICENSE   4.13 kB
README.md   9.04 kB
config.json 1.25 kB
configuration_chatglm.py    2.31 kB
modeling_chatglm.py 51.5 kB
pytorch_model-00001-of-00007.bin    1.83 GB
pytorch_model-00002-of-00007.bin    1.97 GB
pytorch_model-00003-of-00007.bin    1.93 GB
pytorch_model-00004-of-00007.bin    1.82 GB
pytorch_model-00005-of-00007.bin    1.97 GB
pytorch_model-00006-of-00007.bin    1.93 GB
pytorch_model-00007-of-00007.bin    1.05 GB
pytorch_model.bin.index.json    20.4 kB
quantization.py 14.7 kB
tokenization_chatglm.py 10.1 kB
tokenizer.model 1.02 MB
tokenizer_config.json   

终端测试

进入python环境:

python3

输入代码:

from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("./ChatGLM3-6B", trust_remote_code=True)
model = AutoModel.from_pretrained("./ChatGLM3-6B", trust_remote_code=True).half().cuda()
model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
print(response)

输出:

晚上睡不着可能会让你感到焦虑或不舒服,但以下是一些可以帮助你入睡的方法:

1. 制定规律的睡眠时间表:保持规律的睡眠时间表可以帮助你建立健康的睡眠习惯,使你更容易入睡。尽量在每天的相同时间上床,并在同一时间起床。
2. 创造一个舒适的睡眠环境:确保睡眠环境舒适,安静,黑暗且温度适宜。可以使用舒适的床上用品,并保持房间通风。
3. 放松身心:在睡前做些放松的活动,例如泡个热水澡,听些轻柔的音乐,阅读一些有趣的书籍等,有助于缓解紧张和焦虑,使你更容易入睡。
4. 避免饮用含有咖啡因的饮料:咖啡因是一种刺激性物质,会影响你的睡眠质量。尽量避免在睡前饮用含有咖啡因的饮料,例如咖啡,茶和可乐。
5. 避免在床上做与睡眠无关的事情:在床上做些与睡眠无关的事情,例如看电影,玩游戏或工作等,可能会干扰你的睡眠。
6. 尝试呼吸技巧:深呼吸是一种放松技巧,可以帮助你缓解紧张和焦虑,使你更容易入睡。试着慢慢吸气,保持几秒钟,然后缓慢呼气。

如果这些方法无法帮助你入睡,你可以考虑咨询医生或睡眠专家,寻求进一步的建议。

网页测试

使用 gradio 搭建页面

安装 gradio

pip install gradio   -i https://pypi.tuna.tsinghua.edu.cn/simple

加载模型并启动服务

修改模型路径;

vi web_demo.py

到6,7行:

tokenizer = AutoTokenizer.from_pretrained("THUDM/ChatGLM3-6B", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/ChatGLM3-6B", trust_remote_code=True).cuda()

修改为:

tokenizer = AutoTokenizer.from_pretrained("./ChatGLM3-6B", trust_remote_code=True)
model = AutoModel.from_pretrained("./ChatGLM3-6B", trust_remote_code=True).cuda()

开启服务:

python web_demo.py

测试地址:

http://10.192.x.x:7860/

参考

  1. https://github.com/THUDM/ChatGLM3-6B
  2. https://huggingface.co/THUDM/ChatGLM2-6B
  3. https://huggingface.co/THUDM/ChatGLM3-6B
  4. https://github.com/THUDM/GLM

猜你喜欢

转载自blog.csdn.net/zengNLP/article/details/134754465