
Hugging Face Blog
路 2 min read
Training a language model with 馃 Transformers using TensorFlow and TPUs
Introduction
TPU training is a useful skill to have: TPU pods are high-performance and extremely scalable, making it easy to train models at any scale from a few tens of millions of parameters up to truly enormous sizes: Google鈥檚 PaLM model (over 500 billion parameters!) was trained entirely on TPU pods.
We鈥檝e previously written a tutorial and a Colab example showing small-scale TPU training with TensorFlow and introducing the core concepts you need to understand to get your model working on TPU. This time, we鈥檙e going to step that up another level and train a masked language model from scratch using TensorFlow and TPU, including every step from training your tokenizer and preparing your dataset through to the final model training and uploading. This is the kind of task that you鈥檒l probably want a dedicated TPU node (or VM) for, rather than just Colab, and so that鈥檚 where we鈥檒l focus.
As in our Colab example, we鈥檙e taking advantage of TensorFlow's very clean TPU support via XLA and TPUStrategy. We鈥檒l also be benefiting from the fact that the majority of the TensorFlow models in 馃 Transformers are fully XLA-compatible. So surprisingly, little work is needed to get them to run on TPU.
Unlike our Colab example, however, this example is designed to be scalable and much closer to a realistic training run -- although we only use a BERT-sized model by default, the code could be expanded to a much larger model and a much more powerful TPU pod slice by changing a few configuration options.
Motivation
Why are we writing this guide now? After all, 馃 Transformers has had support for TensorFlow for several years now. But getting those models to train on TPUs has been a major pain point for the community. This is because:
- Many models weren鈥檛 XLA-compatible
- Data collators didn鈥檛 use native TF operations
What to expect
Getting the data and training a tokenizer
馃挕 It鈥檚 easy to use 馃 datasets to host your text datasets. Refer to this guide to learn more.
Original source
This story was published by Hugging Face Blog. SyncAI.news shows a preview; the complete article is on the publisher's site.
Read the full story on huggingface.co


