Switch Transformers is a Mixture of Experts (MoE) model trained on Masked Language Modeling (MLM) task. The model architecture is similar to the classic T5, but with the Feed Forward layers replaced by the Sparse MLP layers containing "experts" MLP. According to the
original paper
the model enables faster training (scaling properties) while being better than T5 on fine-tuned tasks.
As mentioned in the first few lines of the abstract :
we advance the current scale of language models by pre-training up to trillion parameter models on the “Colossal Clean Crawled Corpus”, and achieve a 4x speedup over the T5-XXL model.
Disclaimer
: Content from
this
model card has been written by the Hugging Face team, and parts of it were copy pasted from the
original paper
.
Note that these checkpoints has been trained on Masked-Language Modeling (MLM) task. Therefore the checkpoints are not "ready-to-use" for downstream tasks. You may want to check
FLAN-T5
for running fine-tuned weights or fine-tune your own MoE following
this notebook
Find below some example scripts on how to use the model in
transformers
:
Using the Pytorch model
Running the model on a CPU
Click to expand
from transformers import AutoTokenizer, SwitchTransformersConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-8")
model = SwitchTransformersConditionalGeneration.from_pretrained("google/switch-base-8")
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>
Running the model on a GPU
Click to expand
# pip install acceleratefrom transformers import AutoTokenizer, SwitchTransformersConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-8")
model = SwitchTransformersConditionalGeneration.from_pretrained("google/switch-base-8", 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>
Running the model on a GPU using different precisions
FP16
Click to expand
# pip install acceleratefrom transformers import AutoTokenizer, SwitchTransformersConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-8")
model = SwitchTransformersConditionalGeneration.from_pretrained("google/switch-base-8", 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
Click to expand
# pip install bitsandbytes acceleratefrom transformers import AutoTokenizer, SwitchTransformersConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("google/switch-base-8")
model = SwitchTransformersConditionalGeneration.from_pretrained("google/switch-base-8", 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>
The primary use is research on language models, including: research on zero-shot NLP tasks and in-context few-shot learning NLP tasks, such as reasoning, and question answering; advancing fairness and safety research, and understanding limitations of current large language models
These models are based on pretrained SwitchTransformers and are not fine-tuned. It is normal if they perform well on zero-shot tasks.
The model has been trained on TPU v3 or TPU v4 pods, using
t5x
codebase together with
jax
.
Evaluation
Testing Data, Factors & Metrics
The authors evaluated the model on various tasks and compared the results against T5. See the table below for some quantitative evaluation:
For full details, please check the
research paper
.
Results
For full results for Switch Transformers, see the
research paper
, Table 5.
Hardware Type:
Google Cloud TPU Pods - TPU v3 or TPU v4 | Number of chips ≥ 4.
Hours used:
More information needed
Cloud Provider:
GCP
Compute Region:
More information needed
Carbon Emitted:
More information needed
Citation
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}
}
Runs of ybelkada switch-base-8-xsum on huggingface.co
17
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About switch-base-8-xsum huggingface.co Model
switch-base-8-xsum huggingface.co is an AI model on huggingface.co that provides switch-base-8-xsum's model effect (), which can be used instantly with this ybelkada switch-base-8-xsum model. huggingface.co supports a free trial of the switch-base-8-xsum model, and also provides paid use of the switch-base-8-xsum. Support call switch-base-8-xsum model through api, including Node.js, Python, http.
switch-base-8-xsum huggingface.co is an online trial and call api platform, which integrates switch-base-8-xsum's modeling effects, including api services, and provides a free online trial of switch-base-8-xsum, you can try switch-base-8-xsum online for free by clicking the link below.
ybelkada switch-base-8-xsum online free url in huggingface.co:
switch-base-8-xsum is an open source model from GitHub that offers a free installation service, and any user can find switch-base-8-xsum on GitHub to install. At the same time, huggingface.co provides the effect of switch-base-8-xsum install, users can directly use switch-base-8-xsum installed effect in huggingface.co for debugging and trial. It also supports api for free installation.