当前位置:   article > 正文

ChatGLM3在windows10上部署与调试

chatglm3

一、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、下载模型

  1. https://modelscope.cn/models/ZhipuAI/chatglm3-6b/summary
  2. git lfs install
  3. 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

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

演示效果

5.3、启动web_demo2.py

  1. streamlit run web_demo2.py
  2. (chatglm3) D:\workspace\opensource\openai\ChatGLM3\basic_demo>streamlit run web_demo2.py
  3. You can now view your Streamlit app in your browser.
  4. Local URL: http://localhost:8502
  5. Network URL: http://192.168.1.103:8502
  6. Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [03:56<00:00, 33.82s/it]

演示效果

5.4、启动python openai_api.py

  1. (chatglm3) D:\workspace\opensource\openai\ChatGLM3\openai_api_demo>python openai_api.py
  2. Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [00:04<00:00, 1.51it/s]
  3. INFO: Started server process [12124]
  4. INFO: Waiting for application startup.
  5. INFO: Application startup complete.
  6. 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
  1. 2023-11-24 16:00:19.558 | DEBUG | __main__:create_chat_completion:144 - ==== request ====
  2. {'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的部署比之前简单了。 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/260442
推荐阅读
相关标签
  

闽ICP备14008679号