在阿里云上部署ChatGLM3
默认已经帮我们配置好了环境变量、网络,装好了python甚至pytorch、tensorflow等等,所以这些正常比较麻烦的操作已经不需要我们再搞了。有多文件需要修改变量路径,把默认的“THUDM/chatglm3-6b”修改为“/mnt/workspace/ChatGLM3/chatglm3-6b”因为模型很大(总共11.6GB),所以从modelscope上git下载(放到ChatGLM3下级
·
一、申请阿里云机器学习平台PAI
参考【大模型-第一篇】在阿里云上部署ChatGLM3_使用阿里云服务器部署大模型-CSDN博客
二、部署GLM3
1、环境搭建
默认已经帮我们配置好了环境变量、网络,装好了python甚至pytorch、tensorflow等等,所以这些正常比较麻烦的操作已经不需要我们再搞了。直接下一步
2、git下载GLM3
2.1 git clone下载GLM3仓库
2.1.1首先git clone下载GLM3仓库,并切换到这个文件夹下
git clone https://github.com/THUDM/ChatGLM3
cd ChatGLM3
2.1.2 然后使用 pip 安装依赖:在requirements.txt文件中加入mdtex2html,执行下面代码
pip install -r requirements.txt
2.2 git 下载本地模型
因为模型很大(总共11.6GB),所以从modelscope上git下载(放到ChatGLM3下级目录中)
git lfs install
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
3、修改变量路径并启用
有多文件需要修改变量路径,把默认的“THUDM/chatglm3-6b”修改为“/mnt/workspace/ChatGLM3/chatglm3-6b”
4、运行大模型
cd /mnt/workspace/ChatGLM3/basic_demo/
# 网页版
streamlit run web_demo_streamlit.py --server.address=127.0.0.1
# 这条报错connect error,降低gradio版本
#python web_demo_gradio.py
pip install gradio==3.39
# 对话
python cli_demo.py
# 本地加载模型,启动demo
cd composite_demo/
streamlit run main.py --server.address=127.0.0.1
5、注意事项
conda的配置,将阿里云的源替换为清华的
#打开配置文件
vim /root/.condarc
#全部删除,替换
channels:
- defaults
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
show_channel_urls: True
#查看是否替换成功
conda config --show-sources
#conda新建空间
conda create -n chatglm3-demo python=3.10
#激活
conda activate chatglm3-demo
#退出conda
conda deactivate
运行cli_demo.py,大模型对话卡顿,是因为没有优先调用GPU
将
model = AutoModel.from_pretrained(MODEL_PATH, trust_remote_code=True).eval()
替换为
model = AutoModel.from_pretrained(MODEL_PATH, trust_remote_code=True, device_map="auto").eval()
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)