0
点赞
收藏
分享

微信扫一扫

开源模型ChatGLM3本地安装部署

文章目录

1、环境要求

1.1、硬件环境

  • 最低要求:
  • 流畅运行FP16版本的,最低的配置要求:

1.2、软件环境

Python环境

2、下载模型运行源码

2.1、从 github 下载源码

cd /mnt/d/project/python
git clone https://github.com/THUDM/ChatGLM3.git

2.2、安装依赖

cd /mnt/d/project/python/ChatGLM3
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

3、下载模型

可以从Huggingface, Modelsope, SwanHub三个平台下载模型。

  • 若使用 Huggingface 下载模型
git lfs install
git clone https://huggingface.co/THUDM/chatglm3-6b.git
  • 若使用 Modelscope 下载模型,没工具的情况下,用Modelscope下载最快
git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
  • 若使用 SwanHub 下载模型
git lfs install
git clone https://swanhub.co/ZhipuAI/chatglm3-6b.git

4、使用本地模型运行示例

4.1、基本对话示例

模型路径:/mnt/d/project/python/model/THUDM/chatglm3-6b,修改basic_demo目录中的cli_demo.py、web_demo_gradio.py、web_demo_streamlit.py模型路径代码。

# cli_demo.py、web_demo_gradio.py、web_demo_streamlit.py
MODEL_PATH = os.environ.get('MODEL_PATH', '/mnt/d/project/python/model/THUDM/chatglm3-6b')
4.1.1、命令行demo
python basic_demo/cli_demo.py

在这里插入图片描述

4.1.2、网页demo
python basic_demo/web_demo_gradio.py

# ModuleNotFoundError: No module named 'peft'
pip install peft -i https://mirrors.aliyun.com/pypi/simple/

在这里插入图片描述

在这里插入图片描述

4.1.3、网页demo2
# 基于Gradio的网页版demo
python basic_demo/web_demo_streamlit.py

# 基于Streamlit的网页版demo,其效果与Gradio相同,但是更加流畅。
streamlit run basic_demo/web_demo_streamlit.py

在这里插入图片描述
在这里插入图片描述

4.2、代码解释器聊天示例

Code Interpreter可以让普通用户(非程序员)用自然语言完成以前需要写代码来完成的复杂工作。
参考:https://github.com/THUDM/ChatGLM3/blob/main/composite_demo/README.md
安装依赖

cd composite_demo
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

安装Jupyter 内核,

ipython kernel install --name chatglm3-demo --user

修改代码中配置的本地模型路径

# 修改配置composite_demo/client.py
MODEL_PATH = os.environ.get('MODEL_PATH', '/mnt/d/project/python/model/THUDM/chatglm3-6b')

# 或者通过环境变量配置模型路径
export MODEL_PATH=/mnt/d/project/python/model/THUDM/chatglm3-6b

启动demo:

streamlit run main.py

ChatGLM3 Demo 拥有三种模式:

  • Chat: 对话模式,在此模式下可以与模型进行对话。

  • Tool: 工具模式,模型除了对话外,还可以通过工具进行其他操作。

  • Code Interpreter: 代码解释器模式,模型可以在一个Jupyter环境中执行代码并获取结果,以完成复杂任务。

    本文使用Code Interpreter读取excel学生成绩文件,并统计1班语文平均分。在这里插入图片描述
    在这里插入图片描述

参考自官方资料:https://zhipu-ai.feishu.cn/wiki/WvQbwIJ9tiPAxGk8ywDck6yfnof

举报

相关推荐

0 条评论