3分钟利用Modelscope部署ChatGLM3-6B
2023-10-28 本文已影响0人
yefang
该文章仅供学习参考
ChatGLM3对应github地址:https://github.com/THUDM/ChatGLM3
ChatGLM3对应Modelscope地址:https://www.modelscope.cn/models/ZhipuAI/chatglm3-6b/summary
1.如何“白嫖”linux云服务器+GPU资源。
进入网页后选择Notebook快速开发

注册后,选择GPU环境,点击启动创建实例,实例创建需要大约2分钟

启动后,点击查看Notebook

进入之后创建一个新的Notebook

2.配置基础环境
通过感叹号! 可以实现运行linux的命令行语句
# 从git克隆基础环境
! git clone https://github.com/THUDM/ChatGLM3
#因无法实现cd 命令切换路径故使用python自带os库切换路径
import os
os.chdir(r'ChatGLM3')
#安装相关python库
! pip install -r requirements.txt
#因为需要在云服务器部署模型,故将模型拷贝到服务器
! git lfs install
! git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
#加载模型
from modelscope import AutoTokenizer, AutoModel
model_dir = r'chatglm3-6b'
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
model = AutoModel.from_pretrained(model_dir, trust_remote_code=True).half().cuda()
model = model.eval()
静候佳音

3.圆圈转完了,和它交流一下!
问它哲学三问
response, history = model.chat(tokenizer, "你是谁", history=[])
print(response)
response, history = model.chat(tokenizer, "你从哪里来", history=history)
print(response)
response, history = model.chat(tokenizer, "你要到哪里去", history=history)
print(response)
它的回答

让它用pytorch写个700B参数的全连接神经网络
response, history = model.chat(tokenizer, "你能帮我用pytroch写一个700B参数的全连接的神经网络模型吗", history=history)
print(response)
#看看它知不知道B是不是十亿的意思
response, history = model.chat(tokenizer, "上面那个代码对应的模型的参数量是多少呢?", history=history)
print(response)
emmmm..........┓( ´∀` )┏还行,有待提高。
