ChatGLM3在windows10上部署与调试

一、ChatGLM3介绍

ChatGLM3 是智谱AI和清华大学 KEG 实验室联合发布的新一代对话预训练模型。ChatGLM3-6B 是 ChatGLM3 系列中的开源模型,在保留了前两代模型对话流畅、部署门槛低等众多优秀特性的基础上,ChatGLM3-6B 引入了如下特性:

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

二、ChatGLM3下载

2.1、下载代码

https://github.com/THUDM/ChatGLM3

2.2、下载模型

https://modelscope.cn/models/ZhipuAI/chatglm3-6b/summary

git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git

三、修改ChatGLM3的配置

3.1、修改basic_demo下的cli_demo.py

3.2、修改basic_demo下的cli_demo_bad_word_ids.py

3.3、修改basic_demo下的web_demo.py

3.4、修改basic_demo下的web_demo2.py

3.5、修改openai_api_demo下的openai_api.py

四、安装ChatGLM3依赖环境

4.1、根据conda创建python虚拟环境

conda create -n chatglm3 python=3.8

4.2、激活chatglm3

conda activate chatglm3

 4.3、进入ChatGLM3代码目录

cd D:\workspace\opensource\openai\ChatGLM3

 4.4、安装requirements.txt

pip install protobuf transformers>=4.30.2 cpm_kernels torch>=2.0 gradio mdtex2html sentencepiece accelerate  -i https://pypi.douban.com/simple/
pip install -r  requirements.txt

五、多种方法启动ChatGLM3

5.1、启动cli_demo.py

python cli_demo.py

 演示效果

5.2、启动web_demo.py

(chatglm3) D:\workspace\opensource\openai\ChatGLM3\basic_demo>python web_demo.py
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [00:04<00:00,  1.48it/s]

演示效果

5.3、启动web_demo2.py

streamlit run web_demo2.py

(chatglm3) D:\workspace\opensource\openai\ChatGLM3\basic_demo>streamlit run web_demo2.py

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8502
  Network URL: http://192.168.1.103:8502

Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [03:56<00:00, 33.82s/it]

演示效果

5.4、启动python openai_api.py

(chatglm3) D:\workspace\opensource\openai\ChatGLM3\openai_api_demo>python openai_api.py
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [00:04<00:00,  1.51it/s]
INFO:     Started server process [12124]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

采用curl测试

curl.exe -X POST -H 'Content-Type: application/json' -i 'http://127.0.0.1:8000/v1/chat/completions' --data '{"model": "chatglm3-6b", "messages": [{"role": "system", "content": "You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user'\''s instructions carefully. Respond using markdown."}, {"role": "user", "content": "你好,给我讲一个故事,大概150字"}], "stream": false, "max_tokens": 100, "temperature": 0.8, "top_p": 0.8}'
{"model": "chatglm3-6b", "messages": [{"role": "system", "content": "You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown."}, {"role": "user", "content": "你好,给我讲一个故事,大概150字"}], "stream": false, "max_tokens": 100, "temperature": 0.8, "top_p": 0.8}

采用python openai_api_request.py测试

python openai_api_request.py
2023-11-24 16:00:19.558 | DEBUG    | __main__:create_chat_completion:144 - ==== request ====
{'messages': [ChatMessage(role='system', content="You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.", name=None, function_call=None), ChatMessage(role='user', content='你好,给我讲一个故事,大概100字', name=None, function_call=None)], 'temperature': 0.8, 'top_p': 0.8, 'max_tokens': 100, 'echo': False, 'stream': False, 'repetition_penalty': 1.1, 'functions': None}

 

从chatglm2-6b部署来看,chatglm3的部署比之前简单了。 

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值