我正在参加「掘金·启航计划」
目前开源的
LLM大模型,要想比较流畅地进行部署体验,离不开GPU算力。本文介绍基于阿里云的机器学习平台PAI来免费体验一些开源大模型。
获取算力
直接打开阿里云免费活动页选择机器学习平台PAI:

NAS 体验功能:

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

资源消耗在资源实例管理查看。
创建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 大模型吧🥳。
关于使用阿里云也很贴心地出了教程给我们上手使用:

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

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

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

MOSS
准备好项目和模型:
shell复制代码git clone https://github.com/OpenLMLab/MOSS.git
# 安装依赖
pip install -r requirements.txt
由于硬件问题,我们使用4bit量化版本的moss-moon-003-sft模型(默认):
shell复制代码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 行代码:
shell复制代码model_path = args.model_name if not os.path.exists(args.model_name): model_path = snapshot_download(args.model_name)
改为:
shell复制代码# 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"
然后执行:
shell复制代码python moss_cli_demo.py

如果想使用 web 交互版本:
shell复制代码python moss_web_demo_gradio.py

baichuan-7B
准备好项目和模型:
shell复制代码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 快速使用:
shell复制代码pip install accelerate
只能说,勉强能跑:

想要体验对话能力?有大佬已经微调了对应版本,如 baichuan-7b-sft :
shell复制代码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 让你体验使用,大家可以发挥想象力来使用,有什么问题欢迎沟通交流。
感谢你阅读到这里,如果此文对你有帮助,欢迎转发点赞。👬🏻 朋友,都看到这了,确定不关注一下么 👇
















![[Release] Tree Of Savior](https://www.nicekj.com/wp-content/uploads/replace/4f98107ca1ebd891ea38f390f1226e45.png)



![[一键安装] 手游-天道情缘](https://www.nicekj.com/wp-content/uploads/replace/b441383e0c7eb3e52c9980e11498e137.png)
![[一键安装] 霸王大陆EP8-5.0 虚拟机+源码+大背包+商城-最新整理](https://www.nicekj.com/wp-content/uploads/thumb/replace/fill_w372_h231_g0_mark_0d204bcf457d56afaeacf1e97e86ee45.png)

![[一键安装] 龙之谷手游飓风龙单机版一键端 完整GM后台局域网](https://www.nicekj.com/wp-content/uploads/thumb/replace/fill_w372_h231_g0_mark_77ae8bb495cba3dd592ef131cc7aea5f.jpeg)






