我前几天写了篇在Macbook Pro(M2 Max)上部署 ChatGLM2-6B 的文章,有网友问,我没有合适的 GPU,但也想体验下,怎么办?我就把我已知的资料搜集整理下,供大家参考。
官方的
https://chatglm.cn/[1]

官方申请
没有尝试过,不清楚是否容易申请,有兴趣的可以自行尝试。
免费的方案
试试我之前介绍的免费 GPU 使用时间,100 小时免费 GPU 算力+长期免费 CPU 计算资源,轻松部署自己的大模型!, 我没有尝试过,如果成功记得告诉我一声,先谢谢了。 Google Colab:免费用户可以运行int4 量化版本[2] , 这个需要魔法,但我想应该难不倒你(不展开讨论,如果搞不定,还是放弃吧)。 https://replicate.com/nomagick/chatglm2-6b huggingface 搜索关键词,寻找可用的space[3]
付费方案
购买 GPU 使用时间,这个可以尝试的地方很多,这里不多说了,有兴趣的可以看看
huggingface Google Colab replicate.com
附 Colab 免费空间运行 ChatGLM2-6B
代码来自chatglm2-6b-colab[4],很简洁,我增加了些中文注释,希望对理解有帮助,有兴趣看视频教程的朋友,可以看下文章结尾放的视频。
#@title Default title text
%cd /content
# 克隆源代码到本地
!git clone https://github.com/THUDM/ChatGLM2-6B
# 安装aria2
# aria2是一个轻量级的多协议、多源、多线程的跨平台下载工具,在命令行操作。它支持HTTP/HTTPS,FTP,SFTP,BitTorrent和Metalink。
!apt -y install -qq aria2
# Download ChatGLM2-6B Models from Huggingface(下载模型到本地)
import os
model_file_names = [
'MODEL_LICENSE',
'README.md',
'config.json',
'configuration_chatglm.py',
'modeling_chatglm.py',
'quantization.py',
'tokenization_chatglm.py',
'tokenizer_config.json',
'pytorch_model.bin',
'tokenizer.model'
]
import os
for fname in model_file_names:
cmd = f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/THUDM/chatglm2-6b-int4/resolve/main/{fname} -d /content/ChatGLM2-6B/models -o {fname}"
os.system(cmd)
# Install dependencies
%cd /content/ChatGLM2-6B
!pip install -r requirements.txt
!pip install gradio
# Lanuch the web
# 使用本地模型
!sed -i "s/THUDM\/chatglm2-6b/\/content\/ChatGLM2-6B\/models/g" web_demo.py
# share=True 的目的是将你的 Gradio 应用程序公开共享,以便其他人可以通过生成的 URL 访问它,这里是方便自己访问。
!sed -i "s/demo.queue().launch(share=False, inbrowser=True)/demo.queue().launch(share=True, inbrowser=True)/g" web_demo.py
# 运行模型,返回共享链接
!python web_demo.py
运行起来后会有一个方便访问的共享链接,

获得共享链接

参考资料
https://chatglm.cn/: https://chatglm.cn/
[2]int4量化版本: https://colab.research.google.com/github/lewangdev/chatglm2-6b-colab/blob/main/chatglm2_6b_int4_colab.ipynb
[3]space: https://huggingface.co/spaces?search=chatglm2
[4]chatglm2-6b-colab: https://github.com/lewangdev/chatglm2-6b-colab
文章转载自alitrack,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




