1. 參考
- ChatGLM2-6B代碼地址
- chatglm2-6b模型地址
- Mac M1芯片部署
2. ChatGLM2-6B 介紹
ChatGLM2-6B 是開源中英雙語對話模型 ChatGLM-6B 的第二代版本,在保留了初代模型對話流暢、部署門檻較低等眾多優(yōu)秀特性的基礎(chǔ)之上,ChatGLM2-6B 引入了如下新特性:
- 更強大的性能。
- 更長的上下文。
- 更高效的推理。
- 更開放的協(xié)議。
詳細介紹參考官方README介紹。
3. 本地運行
3.1 硬件配置
- 芯片:Apple M1 Pro
- 內(nèi)存:32 GB
3.2 下載ChatGLM2-6B代碼
cd /Users/joseph.wang/llm
git clone https://github.com/THUDM/ChatGLM2-6B
3.3 下載需要加載的模型
此步驟下載模型需要科學(xué)上網(wǎng),同時需要耐心,因為下載的時間會比較長。
cd /Users/joseph.wang/llm/ChatGLM-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
內(nèi)存消耗文章來源:http://www.zghlxwxcb.cn/news/detail-824014.html
4. 測試
文章來源地址http://www.zghlxwxcb.cn/news/detail-824014.html
到了這里,關(guān)于基于MacBook Pro M1芯片運行chatglm2-6b大模型的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!