模型:
google/switch-base-64
Switch Transformers 是一个基于混合专家 (MoE) 模型,以掩码语言建模(MLM)任务进行训练。这个模型的架构类似于经典的T5模型,但是将前馈层替换为包含“专家”MLP的稀疏MLP层。根据 original paper 所说,该模型在训练速度(可扩展的特性)上比T5更快,并在微调任务上具有更好的表现。正如摘要中的前几句所说:
我们通过在“巨大的干净爬行语料库”上预训练万亿参数模型,实现了对T5-XXL模型的4倍加速。
免责声明:该模型卡片的内容由Hugging Face团队撰写,其中的部分内容来自于 original paper 的复制粘贴。
请注意,这些检查点是在掩码语言建模(MLM)任务上训练的。因此,这些检查点不是“即用型”的用于下游任务。您可能希望查看 FLAN-T5 以运行经过微调的权重,或按照 this notebook 自行微调自己的混合专家模型。
下面是如何在 transformers 中使用模型的一些示例脚本:
from transformers import AutoTokenizer, SwitchTransformersForConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-64")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-64")
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-64")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-64", 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-64")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-64", 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-64")
model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-64", 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}
}