惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
T
The Blog of Author Tim Ferriss
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
L
LangChain Blog
博客园_首页
Vercel News
Vercel News
月光博客
月光博客
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - Franky
C
Check Point Blog
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
F
Fortinet All Blogs
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
罗磊的独立博客
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学

Eson Wong's Blog

终端、SSH、launchd、tmux:zsh 启动文件到底读了哪些 我为什么开发 AI 英语听力生成器:Im-Listening Playwright E2E 测试框架入门教程 如何使用 LlamaIndex 构建一个 RAG 检索系统 批评 Milvus 入门教程 怎么在网页中实现自动调整视频的清晰度 什么是检索增强生成(Retrieval-Augmented Generation)? Phonics 自然拼读常见规则 - 辅音字母的发音规律 ESP8266EX 自动下载电路 浅聊 esp8266 墨水屏 Todo List 制作教程 2023 年我买过的最好用的商品 转变自我的密码:《Atomic Habits》读后感 Phonics 自然拼读常见规则 - 音节和元音字母的发音规律 怎么用 Github Actions 部署 Next.js 项目到服务器 使用 v4l 采集摄像头 怎么解决 Prettier 和 ESLint 在 VSCode 里的冲突? 《微习惯》 - 读书笔记 在 iPad 使用 VS Code 写代码
在 Macbook 上运行 ChatGLM-6B
本文作者: Eson Wong · 2023-08-13 · via Eson Wong's Blog

ChatGLM-6B Web
我有一台 32G 内存 Macbook Pro,想要运行大语言模型看能不能替代 OpenAI 的 API。下面是我在 Macbook 上运行 ChatGLM-6B 的步骤。

1
git clone https://github.com/THUDM/ChatGLM-6B

创建虚拟环境

1
2
cd ChatGLM-6B
python3 -m venv .venv

激活虚拟环境

1
source .venv/bin/activate

安装依赖

1
2
3
4
pip install -r requirements.txt


pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

下载模型

1
2
cd ..
git clone https://huggingface.co/THUDM/chatglm-6b chatgml-6b-model

修改代码使用 MPS 后端和下载的好的模型

修改 webapp.py 文件。

  1. .cuda() 改为 .to("mps")
  2. 将模型和 tokenizer 的路径改为 huggingface 上克隆下来的 chatglm-6b 仓库本地路径。下面我的例子中,本地路径为 /Users/eson/git/chatgml-6b-model
1
2
3
4
5
6
7
8
9
10
11
12
-tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
-model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
+tokenizer = AutoTokenizer.from_pretrained(
+ "/Users/eson/git/chatgml-6b-model", trust_remote_code=True
+)
+model = (
+ AutoModel.from_pretrained(
+ "/Users/eson/git/chatgml-6b-model", trust_remote_code=True
+ )
+ .half()
+ .to("mps")
+)

运行

1
python webapp.py

这将会在本地启动一个 web 服务,会自动打开浏览器。