模型:
google/switch-base-32
Switch Transformers是基于层次编码模型的混合专家模型,是在掩码语言模型(MLM)任务上进行训练。该模型的架构类似于经典的T5,但将前馈层替换为包含“专家”MLP的稀疏MLP层。根据摘要的前几行所述:
我们通过在“Colossal Clean Crawled Corpus”上训练万亿参数模型,提高了当前语言模型的规模,并实现了比T5-XXL模型快4倍的训练速度。
免责声明:此模型卡内容由Hugging Face团队编写,其中部分内容是从 original paper 复制粘贴而来的。
请注意,这些检查点是在遮蔽语言建模(MLM)任务上进行训练的。因此,这些检查点不适用于下游任务。您可以查看FLAN-T5以运行微调后的权重,或根据 this notebook 自行微调您自己的MoE。
以下是使用transformers库中的模型的示例脚本:
from transformers import AutoTokenizer, SwitchTransformersForConditionalGeneration tokenizer = AutoTokenizer.from_pretrained("google/switch-base-32") model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-32") 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-32") model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-32", 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-32") model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-32", 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-32") model = SwitchTransformersForConditionalGeneration.from_pretrained("google/switch-base-32", 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 。
需要更多信息。
需要更多信息。
需要更多信息。
需要更多信息。
需要更多信息。
该模型是在Colossal Clean Crawled Corpus(C4)数据集上进行遮蔽语言建模任务训练的,遵循与T5相同的过程。
根据 original paper 的模型卡,模型是在TPU v3或TPU v4 Pod上使用 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} }