基于MacBook Pro M1芯片运行chatglm2-6b大模型

1. 参考

2. ChatGLM2-6B 介绍

ChatGLM2-6B 是开源中英双语对话模型 ChatGLM-6B 的第二代版本,在保留了初代模型对话流畅、部署门槛较低等众多优秀特性的基础之上,ChatGLM2-6B 引入了如下新特性:

  • 更强大的性能。
  • 更长的上下文。
  • 更高效的推理。
  • 更开放的协议。

详细介绍参考官方README介绍。

3. 本地运行

3.1 硬件配置

  • 芯片:Apple M1 Pro
  • 内存:32 GB

3.2 下载ChatGLM2-6B代码

cd /Users/joseph.wang/llm
git clone https://github.com/THUDM/ChatGLM2-6B

3.3 下载需要加载的模型

此步骤下载模型需要科学上网,同时需要耐心,因为下载的时间会比较长。

cd /Users/joseph.wang/llm/ChatGLM2-6B
mkdir model
cd model
git lfs install
git clone https://huggingface.co/THUDM/chatglm2-6b

在这里插入图片描述

3.4 运行大模型

3.4.1 安装依赖
cd /Users/joseph.wang/llm/ChatGLM-6B
pip install -r requirements.txt

其中 transformers 库版本推荐为 4.30.2,torch 推荐使用 2.0 及以上的版本,以获得最佳的推理性能。

3.4.2 编辑web_demo.py
cd /Users/joseph.wang/llm/ChatGLM-6B
...
...
# 修改为通过本地加载大模型,这里改本地下载后大模型的路径即可。
tokenizer = AutoTokenizer.from_pretrained("/Users/joseph.wang/llm/ChatGLM-6B/model/chatglm2-6b", trust_remote_code=True)
# 参考 [Mac M1 部署](https://github.com/THUDM/ChatGLM2-6B/blob/main/README.md#mac-%E9%83%A8%E7%BD%B2) 即可
model = AutoModel.from_pretrained("/Users/joseph.wang/llm/ChatGLM-6B/model/chatglm2-6b", trust_remote_code=True).to('mps')
...
...
# 修改本地启动的端口
demo.queue().launch(share=True, inbrowser=True, server_port=1185)
3.4.3 启动
python  web_demo.py

在这里插入图片描述
内存消耗
在这里插入图片描述

4. 测试

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值