这会是一个关于 ChatGPT 的系列文章,主要记录老胡日常使用 ChatGPT 的思考和一些有趣的开源项目,然后这些信息我都会汇总到一个 ChatGPT 信息群(免费,目的是为了交流),有兴趣的朋友可以联系我进群 🥳。
目前开源的 LLM
大模型,要想比较流畅地进行部署体验,离不开 GPU
算力。本文介绍基于阿里云的机器学习平台 PAI
来免费体验一些开源大模型。
ChatGPT
注册申请文章:
ChatGPT 从注册到自建应用
基于 Azure OpenAI 免费注册使用 ChatGPT 教程
获取算力
直接打开阿里云免费活动页选择机器学习平台 PAI[1]:
直接点击立即试用,注意,新老用户都可以,所以放心申请。一般 PAI 功能涉及到存储,所以建议同时也申请
NAS
体验功能:

如果你需要引入 NAS
持久化数据就到控制台[2]新建即可,这里不再赘述。
新建空间
申请结束后直接新建一个工作空间[3]:

资源消耗在资源实例管理[4]查看。
创建 DSW
创建好空间,直接创建交互式建模(DWS)实例,这里我们需要注意的是只能选择可以抵扣算力的 GPU
:
ecs.gn7i-c8g1.2xlarge: A10
ecs.gn6v-c8g1.2xlarge: V100

镜像选择 pytorch:1.12-gpu-py39-cu113-ubuntu20.04
即可,创建完毕在**交互式建模(DSW)**选中创建的目标点击打开:

具体操作页面如下:

就是基于 **Jupyter Lab**
修改的界面,很好上手,接下来就让我们用这个免费的算力来体验一下各类开源 LLM
大模型吧 🥳。
关于使用阿里云也很贴心地出了教程[5]给我们上手使用:

上手 LLM
准备工作
接下来将以开源领域比较出名的几个 LLM
为例,跑起来体验一下,开始前做好一些准备工作:
# 安装 git-lfs
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
apt-get install git-lfs
ChatGLM-6B
下载项目:
https://github.com/THUDM/ChatGLM-6B.git
# 国内加速
git clone https://ghproxy.com/https://github.com/THUDM/ChatGLM-6B.git
# 安装依赖
pip install -r requirements.txt
加载模型:
mkdir -p /mnt/workspace/chatglm-6b
git clone https://huggingface.co/THUDM/chatglm-6b /mnt/workspace/chatglm-6b
cd /mnt/workspace/chatglm-6b
git lfs install
git lfs pull
若速度慢,官方[6]提供的手动下载模型文件方案也可参考:

运行项目,基于 transformers
快速使用:

ChatGLM-6B
提供了 cli&web&api
三种使用方式,使用前请将这三个文件全部修改下模型目录:
web_demo.py:设置
share=True
可以分享出去cli_demo.py
api.py
比如我演示环境模型目录下载位置是 /mnt/workspace/chatglm-6b
,改动后代码如下:
tokenizer = AutoTokenizer.from_pretrained("/mnt/workspace/chatglm-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("/mnt/workspace/chatglm-6b", trust_remote_code=True).half().cuda()
接下来启动运行对应脚本即可体验:
# 以终端为例
python cli_demo.py

MOSS
准备好项目和模型:
git clone https://github.com/OpenLMLab/MOSS.git
# 安装依赖
pip install -r requirements.txt
由于硬件问题,我们使用4bit
量化版本的moss-moon-003-sft
模型(默认):
mkdir -p /mnt/workspace/moss-moon-003-sft-int4
git clone https://huggingface.co/fnlp/moss-moon-003-sft-int4 /mnt/workspace/moss-moon-003-sft-int4
然后将moss_cli_demo.py
的 32-34
行代码:
model_path = args.model_name
if not os.path.exists(args.model_name):
model_path = snapshot_download(args.model_name)
改为:
# model_path = args.model_name
# if not os.path.exists(args.model_name):
# model_path = snapshot_download(args.model_name)
model_path = "/mnt/workspace/moss-moon-003-sft-int4"
然后执行:
python moss_cli_demo.py

如果想使用 web 交互版本:
python moss_web_demo_gradio.py

baichuan-7B
准备好项目和模型:
git clone https://github.com/baichuan-inc/baichuan-7B.git
# 国内加速
git clone https://ghproxy.com/https://github.com/baichuan-inc/baichuan-7B.git
# 安装依赖
pip install -r requirements.txt
# 下载模型
mkdir -p /mnt/workspace/baichuan-7b
git clone https://huggingface.co/baichuan-inc/baichuan-7B /mnt/workspace/baichuan-7b
cd /mnt/workspace/baichuan-7b
git lfs install
git lfs pull
运行项目,基于 transformers
快速使用:
pip install accelerate
只能说,勉强能跑:

想要体验对话能力?有大佬已经微调了对应版本,如 baichuan-7b-sft[7] :
mkdir -p /mnt/workspace/baichuan-7b-sft
mkdir -p /mnt/workspace/baichuan-7b-sft-offload-dir
git clone https://huggingface.co/hiyouga/baichuan-7b-sft /mnt/workspace/baichuan-7b-sft
cd /mnt/workspace/baichuan-7b-sft
git lfs install
git lfs pull
git clone https://github.com/hiyouga/LLaMA-Efficient-Tuning
python src/cli_demo.py \
--model_name_or_path /mnt/workspace/baichuan-7b \
--checkpoint_dir /mnt/workspace/baichuan-7b-sft \
--prompt_template ziya
执行结果:

说明
感谢阿里云的免费计划,整体体验下来感觉还是不错的,其实就相当于可选的 A10&V100 GPU
让你体验使用,不用的时候建议关掉哈。大家可以发挥想象力来使用,有什么问题欢迎沟通交流。
感谢你阅读到这里,如果此文对你有帮助,欢迎转发点赞。👬🏻 朋友,都看到这了,确定不关注一下么 👇
参考资料
[1]
机器学习平台PAI: https://free.aliyun.com/?product=9602825
[2]控制台: https://nasnext.console.aliyun.com/overview?spm=a2c4g.2261408.0.0.35993a02KpRU0s
[3]工作空间: https://pai.console.aliyun.com/?regionId=cn-shenzhen&scm=20140722.M_960469._.V_1&spm=5176.28008736#/workspace/create
[4]资源实例管理: https://usercenter2.aliyun.com/ri/summary?spm=a2c4g.2261127.0.0.1928229272eccf&commodityCode=
[5]教程: https://help.aliyun.com/document_detail/2261126.html?spm=5176.28008736.J_6443120770.d960469_1.42b03e4dtkYl8d&pipCode=learn&goodsId=960469&scm=20140722.M_960469._.V_1
[6]官方: https://github.com/THUDM/ChatGLM-6B
[7]baichuan-7b-sft: https://huggingface.co/hiyouga/baichuan-7b-sft