Llama 3.1模型推理实战
1、环境准备
首先,我们需要确保我们的服务器具备足够的硬件配置来支持Llama 3.1模型的运行。我们选择的是一台配备有4090型号GPU(24G显存)的服务器,基础镜像信息如下:ubuntu 22.04、python 3.12、cuda 12.1、pytorch 2.3.0。
2、安装依赖
首先 pip 换源加速下载并安装依赖包
安装完成如下:
3、模型下载
使用 modelscope 中的 snapshot_download 函数下载模型。第一个参数为模型名称,参数 cache_dir 用于指定模型的下载路径。
在 /root/autodl-tmp 路径下新建 d.py 文件,并在其中输入以下内容:
如下:
运行 python /root/autodl-tmp/d.py 执行下载。需注意,模型大小约为 15GB,下载模型大概需要 20 分钟,请耐心等待。
4、模型推理
1)推理测试
执行成功如下:
查看响应结果
结果如下:
2)中文测试一
输出如下:
3)中文测试二
输出如下:
注意:如果推理报错如下
则需要升级transformers:
资源消耗如下:
文章最后
AI大模型作为人工智能领域的重要技术突破,正成为推动各行各业创新和转型的关键力量。抓住AI大模型的风口,掌握AI大模型的知识和技能将变得越来越重要。
学习AI大模型是一个系统的过程,需要从基础开始,逐步深入到更高级的技术。