大模型那么火,教你一键Modelarts玩转开源LlaMA(羊驼)大模型

本文分享自华为云社区《大模型那么火,教你一键Modelarts玩转开源LlaMA(羊驼)大模型》,作者:码上开花_Lancer 。

近日, LlaMA(羊驼)这个大模型再次冲上热搜!

LLaMA(Large Language Model Meta AI),由 Meta AI 发布的一个开放且高效的大型基础语言模型,共有 7B、13B、33B、65B(650 亿)四种版本。其数据集来源都是公开数据集,无任何定制数据集,保证了其工作与开源兼容和可复现,整个训练数据集在 token 化之后大约包含 1.4T 的 token。关于模型性能,LLaMA 的性能非常优异:具有 130 亿参数的 LLaMA 模型「在大多数基准上」可以胜过 GPT-3( 参数量达 1750 亿),而且可以在单块 V100 GPU 上运行;而最大的 650 亿参数的 LLaMA 模型可以媲美谷歌的 Chinchilla-70B 和 PaLM-540B。

上篇文章有介绍了LLaMA 所采用的Transformer 结构和细节,与之前所介绍的Transformer架构不同的地方包括采用了前置层归一化(Pre-normalization)并使用RMSNorm 归一化函数(Normalizing Function)、激活函数更换为SwiGLU,并使用了旋转位置嵌入(RoP),整体Transformer架构与GPT-2 类似,如图1.1所示。

图1.1 GPT-2 模型结构

关于训练集,其来源都是公开数据集,无任何定制数据集,保证了其工作与开源兼容和可复现。整个训练数据集在 token 化之后大约包含 1.4T 的 token。其中,LLaMA-65B 和 LLaMA-33B 是在 1.4万亿个 token 上训练的,而最小的模型 LLaMA-7B 是在 1万亿个 token 上训练的。LLaMA 优势在于其只使用公开可用的数据,这可以保证论文的工作与开源兼容和可复现。之前的大模型要么使用了不公开的数据集去训练从而达到了 state-of-the-art,如 Chinchilla、PaLM 或 GPT-3;要么使用了公开数据集,但模型效果不是最佳无法和 PaLM-62B 或 Chinchilla 相竞争,如 OPT、GPT-NeoX、BLOOM 和 GLM。

和 GPT 系列一样,LLaMA 模型也是 Decoder-only 架构,但结合前人的工作做了一些改进,比如:

  • Pre-normalization [GPT3]. 为了提高训练稳定性,LLaMA 对每个 transformer 子层的输入进行归一化,使用 RMSNorm 归一化函数,Pre-normalization 由Zhang和Sennrich(2019)引入。
  • SwiGLU 激活函数 [PaLM]. 将 ReLU 非线性替换为 SwiGLU 激活函数,且使用2/3*4D而不是 PaLM 论文中的 4d,SwiGLU 由 Shazeer(2020)引入以提高性能。
  • Rotary Embeddings [GPTNeo]. 模型的输入不再使用 positional embeddings,而是在网络的每一层添加了 positional embeddings (RoPE),RoPE 方法由Su等人(2021)引入。

不同模型的超参数详细信息在表2中给出,具体可以去看看我上篇文章,

具体怎么在华为云的ModelArts上玩转LLAMA开源大模型呢?

前期准备:

1.登录华为云官方账号

点击右上角"控制台",搜索栏输入"ModelArts"

点击"AI Gallery",选择"北京四"区域,

点击"资产集市--Notebook",输入"Mindformers应用之LLaMA_7B推理应用"

点击"Run in ModelArts",进入,

1. 安装MindFormers开发套件

复制代码
%cd /home/ma-user/work
!git clone -b r0.6 https://gitee.com/mindspore/mindformers.git
Cloning into 'mindformers'...
 
remote: Enumerating objects: 21732, done.
 
remote: Counting objects: 100% (437/437), done.
 
remote: Compressing objects: 100% (330/330), done.
 
remote: Total 21732 (delta 262), reused 190 (delta 107), pack-reused 21295
 
Receiving objects: 100% (21732/21732), 37.74 MiB | 3.73 MiB/s, done.

编译代码

复制代码
%cd mindformers

!bash build.sh

%cd ..

/home/ma-user/work/mindformers

---------------- MindFormers: build start ----------------

running bdist_wheel

running build

running build_py

creating build/lib/mindformers

copying mindformers/__init__.py -> build/lib/mindformers

copying mindformers/auto_class.py -> build/lib/mindformers

copying mindformers/mindformer_book.py -> build/lib/mindformers

creating build/lib/mindformers/core

copying mindformers/core/__init__.py -> build/lib/mindformers/core

copying mindformers/core/clip_grad.py -> build/lib/mindformers/core

copying mindformers/core/parallel_config.py -> build/lib/mindformers/core

creating build/lib/mindformers/dataset

........

2.下载LLaMA模型和tokenizer

复制代码
%cd /home/ma-user/work/mindformers

import moxing as mox

mox.file.copy_parallel('obs://modelarts-labs-bj4-v2/case_zoo/Mindfomer_LLaMA/', 'checkpoint_download/llama')

3.推理-使用pipeline接口开启快速推理

复制代码
from mindformers.pipeline import pipeline

pipeline_task = pipeline("text_generation", model='llama_7b', max_length=20)

pipeline_result = pipeline_task("I love Beijing, because", top_k=3)

print(pipeline_result)
  • 当我输入提示词:
复制代码
text_generation_text': I love Beijing, because

通过LLaMA_7B模型推理可以快速输出:

复制代码
['I love Beijing, because it is a city that is constantly changing.\nI love the city']

赶紧来点击试一试,体验下自己写代码调用LLAMA_7B开源大模型的魅力吧!!

点击关注,第一时间了解华为云新鲜技术~

相关推荐
try2find21 小时前
安装llama-cpp-python踩坑记
开发语言·python·llama
西西弗Sisyphus1 天前
LLaMA-Factory 单卡后训练微调Qwen3完整脚本
微调·llama·llama-factory·后训练
顾道长生'1 天前
(Arxiv-2024)自回归模型优于扩散:Llama用于可扩展的图像生成
计算机视觉·数据挖掘·llama·自回归模型·多模态生成与理解
csdndddsd1 天前
华为云Flexus+DeepSeek征文 | 对接华为云ModelArts Studio大模型:AI赋能投资理财分析与决策
华为云modelarts·华为云flexus·ai金融系统·ai投资决策·ai赋能投资决策·ai量化交易·ai风险管理
Zhijun.li@Studio11 天前
【LLaMA-Factory 实战系列】二、WebUI 篇 - Qwen2.5-VL 多模态模型 LoRA 微调保姆级教程
人工智能·自然语言处理·llama·多模态大模型
linlinlove211 天前
华为云Flexus+DeepSeek征文 | AingDesk 对接华为云 ModelArts Studio 全流程教程与性能测评对比
华为云modelarts·华为云flexus·aingdesk对接华为云·aingdesk智能客服系统·华为云接入deepseek教程·开源ai客户端工具·华为云deepseek模型安装
1213411 天前
LLM:重构数字世界的“智能操作系统”
gpt·aigc·ai编程·llama·gpu算力
冷雨夜中漫步19 天前
Java中如何使用lambda表达式分类groupby
java·开发语言·windows·llama
扫地的小何尚21 天前
全新NVIDIA Llama Nemotron Nano视觉语言模型在OCR基准测试中准确率夺冠
c++·人工智能·语言模型·机器人·ocr·llama·gpu
CFAteam21 天前
DeepSeek AI功能演示:如何生成Verilog脚本
人工智能·ai·fpga开发·llama