模型:
google/switch-base-256
Switch Transformers 是一个在遮蔽语言建模(MLM)任务上训练的专家组合 (MoE) 模型。模型架构类似于经典的 T5,但是通过包含“专家” MLP 的稀疏 MLP 替换了前馈层。根据 original paper ,该模型在更好地执行微调任务的同时,实现了更快的训练(扩展性能)。正如摘要的前几行所提到的:
通过在“巨大干净抓取语料库”上预训练万亿参数模型,我们扩展了当前的语言模型规模,并实现了对 T5-XXL 模型的四倍加速。
免责声明:模型卡的内容是由 Hugging Face 团队编写的,其中部分内容是从 original paper 复制粘贴过来的。
请注意,这些检查点是在遮蔽语言建模(MLM)任务上进行训练的。因此,这些检查点不是“立即可用”于下游任务。您可以查看 FLAN-T5 以运行经过微调的权重,或根据 this notebook 自行微调自己的 MoE。
以下是一些如何在 transformers 中使用模型的示例脚本:
from transformers import AutoTokenizer, SwitchTransformersForConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-256")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-256")
input_text = "A <extra_id_0> walks into a bar a orders a <extra_id_1> with <extra_id_2> pinch of <extra_id_3>."
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))
>>> <pad> <extra_id_0> man<extra_id_1> beer<extra_id_2> a<extra_id_3> salt<extra_id_4>.</s>
# pip install accelerate
from transformers import AutoTokenizer, SwitchTransformersForConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-256")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-256", device_map="auto")
input_text = "A <extra_id_0> walks into a bar a orders a <extra_id_1> with <extra_id_2> pinch of <extra_id_3>."
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(0)
outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))
>>> <pad> <extra_id_0> man<extra_id_1> beer<extra_id_2> a<extra_id_3> salt<extra_id_4>.</s>
# pip install accelerate
from transformers import AutoTokenizer, SwitchTransformersForConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-256")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-256", device_map="auto", torch_dtype=torch.float16)
input_text = "A <extra_id_0> walks into a bar a orders a <extra_id_1> with <extra_id_2> pinch of <extra_id_3>."
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(0)
outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))
>>> <pad> <extra_id_0> man<extra_id_1> beer<extra_id_2> a<extra_id_3> salt<extra_id_4>.</s>
INT8 点击展开 # pip install bitsandbytes accelerate
from transformers import AutoTokenizer, SwitchTransformersForConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-256")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-256", device_map="auto")
input_text = "A <extra_id_0> walks into a bar a orders a <extra_id_1> with <extra_id_2> pinch of <extra_id_3>."
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(0)
outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))
>>> <pad> <extra_id_0> man<extra_id_1> beer<extra_id_2> a<extra_id_3> salt<extra_id_4>.</s>
详细信息请参见 research paper 。
需要更多信息。
需要更多信息。
需要更多信息。
需要更多信息。
需要更多信息。
该模型在“巨大干净抓取语料库”(C4 数据集)上进行了遮蔽语言建模任务的训练,遵循与 T5 相同的过程。
根据 original paper 的模型卡,该模型使用 TPU v3 或 TPU v4 pods,在 t5x 代码库和 jax 的共同支持下进行了训练。
作者在多个任务上评估了模型,并将结果与 T5 进行了比较。请参阅下表以了解一些定量评估结果:
。有关完整详细信息,请查阅
research paper
。
有关 Switch Transformers 的完整结果,请参见 research paper ,表格 5。
可以使用 Machine Learning Impact calculator 来估计碳排放量,该工具在 Lacoste et al. (2019) 中介绍。
BibTeX:
@misc{https://doi.org/10.48550/arxiv.2101.03961,
doi = {10.48550/ARXIV.2101.03961},
url = {https://arxiv.org/abs/2101.03961},
author = {Fedus, William and Zoph, Barret and Shazeer, Noam},
keywords = {Machine Learning (cs.LG), Artificial Intelligence (cs.AI), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity},
publisher = {arXiv},
year = {2021},
copyright = {arXiv.org perpetual, non-exclusive license}
}