开源模型ChatGLM3本地安装部署

1、环境要求

1.1、硬件环境

  • 最低要求:

内存:>= 8GB
显存: >= 5GB(1060 6GB,2060 6GB)

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

内存:>= 16GB
显存:>= 13GB(4080 16GB)

1.2、软件环境

Python环境

python 版本推荐3.10 - 3.11
transformers 库版本推荐为 4.36.2
torch 推荐使用 2.0 及以上的版本,以获得最佳的推理性能

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

  • 18
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

penngo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值