许可证:apache-2.0
标签:
- Composer
- MosaicML
- llm-foundry
- StreamingDatasets
数据集:
- allenai/c4
- mc4
- togethercomputer/RedPajama-Data-1T
- bigcode/the-stack-dedup
- allenai/s2orc
推理:false
MPT-30B
MPT-30B 是一款基于解码器架构的Transformer模型,从头开始在1万亿个英文文本和代码标记上进行预训练。该模型由 MosaicML 训练完成。
MPT-30B 属于 Mosaic 预训练 Transformer(MPT)模型系列,采用优化的Transformer架构,以实现高效的训练和推理。
MPT-30B 具备多项独特特性,使其区别于其他大型语言模型(LLM),包括:
- 支持8k标记的上下文窗口(可通过微调进一步扩展,参见 MPT-7B-StoryWriter)
- 通过 ALiBi 支持上下文长度外推
- 通过 FlashAttention 实现高效的推理和训练
得益于其预训练数据混合,该模型还具备强大的编码能力。MPT模型可通过标准HuggingFace流水线或NVIDIA的 FasterTransformer 高效部署。
MPT-30B的规模经过特别设计,便于在单GPU上部署——16位精度下需1块A100-80GB,8位精度下需1块A100-40GB。
该模型使用MosaicML的LLM代码库,代码存放于 llm-foundry仓库。由MosaicML的NLP团队在 MosaicML平台 上完成预训练、微调和推理。
模型特点
MPT-30B的独特之处在于:
基于MPT-30B的微调模型
以下模型基于MPT-30B微调:
模型日期
2023年6月22日
模型许可证
Apache-2.0
文档
使用方式
建议配合MosaicML llm-foundry仓库 进行训练和微调。
import transformers
model = transformers.AutoModelForCausalLM.from_pretrained(
'mosaicml/mpt-30b',
trust_remote_code=True
)
注意:此模型需在from_pretrained
方法中设置trust_remote_code=True
,因其采用自定义MPT
架构,尚未集成至HuggingFacetransformers
包。该架构包含FlashAttention、ALiBi、QK LayerNorm等训练优化特性。
如需启用FlashAttention的triton实现,可在GPU(cuda:0
)上以bfloat16
精度加载模型:
import torch
import transformers
name = 'mosaicml/mpt-30b'
config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
config.attn_config['attn_impl'] = 'triton'
config.init_device = 'cuda:0'
model = transformers.AutoModelForCausalLM.from_pretrained(
name,
config=config,
torch_dtype=torch.bfloat16,
trust_remote_code=True
)
模型初始训练序列长度为2048,后经额外预训练阶段适配至8192。通过ALiBi技术,用户可在微调/推理时进一步扩展最大序列长度,例如:
import transformers
name = 'mosaicml/mpt-30b'
config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
config.max_seq_len = 16384
model = transformers.AutoModelForCausalLM.from_pretrained(
name,
config=config,
trust_remote_code=True
)
模型使用与EleutherAI/gpt-neox-20b相同的MPT-30B分词器:
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('mosaicml/mpt-30b')
模型可用于文本生成任务。注意:在低精度下运行Torch模块时,建议使用torch.autocast上下文管理器。
from transformers import pipeline
with torch.autocast('cuda', dtype=torch.bfloat16):
inputs = tokenizer('纯素香蕉面包食谱:\n', return_tensors="pt").to('cuda')
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
with torch.autocast('cuda', dtype=torch.bfloat16):
print(
pipe('纯素香蕉面包食谱:\n',
max_new_tokens=100,
do_sample=True,
use_cache=True))
模型架构
采用改进的解码器架构Transformer,主要变更包括:
超参数 |
值 |
参数量 |
299.5亿 |
层数 |
48 |
注意力头数 |
64 |
模型维度 |
7168 |
词表大小 |
50432 |
序列长度 |
8192 |
训练数据
流式数据集
使用MosaicML StreamingDataset 库将数据存储在对象存储中,训练时高效流式传输至计算集群。该技术无需预先下载完整数据集,并支持从任意断点即时恢复训练。
数据混合
模型在以下混合数据上训练1万亿标记:
数据源 |
原始标记数 |
比例 |
有效标记数 |
训练轮次 |
mC4 3.1.0 英文(200+词) |
24179.9亿 |
33.50% |
3350亿 |
0.14 |
c4 英文 - SemDedup 80% |
1004.2亿 |
29.90% |
2990亿 |
2.98 |
RedPajama - CommonCrawl |
8784.5亿 |
8.50% |
850亿 |
0.097 |
The Stack - 选定语言 |
4637.8亿 |
10.00% |
1000亿 |
0.22 |
RedPajama - 维基百科 |
48.7亿 |
4.00% |
400亿 |
8.21 |
The Stack - Markdown |
1070.7亿 |
4.50% |
450亿 |
0.42 |
Semantic Scholar ORC |
489.5亿 |
3.30% |
330亿 |
0.67 |
RedPajama - 书籍 |
260.2亿 |
3.00% |
300亿 |
1.15 |
RedPajama - arXiv |
281.0亿 |
1.90% |
190亿 |
0.68 |
RedPajama - StackExchange |
205.4亿 |
1.40% |
140亿 |
0.68 |
每批次样本按上述比例从各数据源抽取,数据内部打乱后按需填充序列长度。为高效支持8k上下文,模型先以2k序列长度预训练1万亿标记,再以8k序列长度追加训练500亿标记。
分词采用EleutherAI/gpt-neox-20b分词器,其特点包括:
(1) 训练数据含代码(The Pile)
(2) 空格分隔一致(不同于GPT2分词器的前缀空格敏感问题)
(3) 包含重复空格标记,提升含大量空格的文本压缩率。
词表大小50432设为128的倍数(参考MEGATRON-LM)。
训练配置
模型分三阶段在MosaicML平台训练:
- 440块A100-40GB,批次大小1760
- 216块A100-40GB,批次大小1728
- 256块H100-80GB,批次大小512,8k上下文长度,500亿标记
训练采用FSDP分片数据并行和LION优化器。
局限性
以下内容改编自EleutherAI GPT-NeoX-20B
MPT-30B(基础版)不推荐未经微调直接部署,也不应未经防护措施和用户同意用于人机交互场景。
MPT-30B可能输出事实性错误,请勿依赖其生成准确信息。模型基于公开数据集训练,虽经严格清洗,仍可能产生低俗、偏见或冒犯性内容。
MosaicML平台
如需在MosaicML平台训练和部署自定义MPT或LLM,请点击注册。
免责声明
本模型许可证不构成法律建议。我们对第三方使用