nanoT5: A PyTorch Framework for Pre-training and Fine-tuning T5-style Models with Limited Resources

Piotr NawrotarXiv 2023 · OpenReview

Abstract

State-of-the-art language models like T5 have revolutionized the NLP landscape, but their computational demands hinder a large portion of the research community. To address this challenge, we present nanoT5, a specially-optimized PyTorch framework for efficient pre-training and fine-tuning of T5 models. Drawing on insights from optimizer differences and prioritizing efficiency, nanoT5 allows a T5-Base model to be pre-trained on a single GPU in just 16 hours, without any loss in performance. With the introduction of this open-source framework, we hope to widen the accessibility to language modelling research and cater to the community's demand for more user-friendly T5 (Encoder-Decoder) implementations. Our contributions, including configurations, codebase, software/hardware insights, and pre-trained models, are available to the public, aiming to strike a balance between research accessibility and resource constraints in NLP.

Introduction

The T5 (Text-to-Text Transfer Transformer) model family revolutionized NLP by framing all tasks as text-to-text problems. However, the "barrier to entry" for training these models is notoriously high. The original T5 implementation relies heavily on Google’s TPU accelerators and massive datasets, making it difficult for academic researchers or small teams with standard GPU setups to experiment with or reproduce results. Furthermore, many existing T5 implementations are written in Jax or Flax, which are less ubiquitous than PyTorch. nanoT5 addresses this gap by providing a "nano-scale" recipe specifically tailored for the encoder-decoder architecture of T5, inspired by the accessibility of projects like Andrej Karpathy’s nanoGPT.

Methodology

The nanoT5 framework introduces several low-level and algorithmic optimizations to maximize performance on a single GPU:

  1. PyTorch 2.0 Integration: Utilizing torch.compile and mixed-precision training (BF16 and TF32) significantly reduces training time.
  2. Optimizer Innovation: The authors identify a middle ground between standard AdamW and memory-efficient Adafactor. They propose a variant of AdamW augmented with matrix-wise RMS (Root Mean Square) scaling, providing the stability of AdamW with the scaling benefits of Adafactor.
  3. Learning Rate Schedule: Replacing the traditional Inverse-Square-Root (ISR) schedule with a Cosine Learning Rate Schedule improves final model convergence.
  4. Concurrent Pipeline: Concurrent data downloading and preprocessing ensure the GPU is never idle while processing the 300GB+ C4 dataset.
Training efficiency gains through hardware-aware optimizations and PyTorch 2.0 features.

Key Results

The optimizations in nanoT5 lead to dramatic improvements in training speed and data efficiency.

Speed and Efficiency

A T5-Base model (248M parameters) can be pre-trained in approximately 16 hours on a single A100 GPU. As shown in the methodology section, the transition from FP32 to BF16 with PyTorch 2.0 compilation reduces the time per training step from ~4.10s to just ~0.56s, a nearly 8x speedup.

Performance and Convergence

Despite using 150x less data than the original T5 pre-training, nanoT5 achieves competitive results. On the C4 held-out set, it reached a negative log-likelihood (NLL) of 1.953, outperforming the Adafactor baseline (1.995). When fine-tuned on Super Natural-Instructions (SNI), the model's performance closely tracks established baselines, lagging by only 0.2 RougeL points.

SNI Rouge-L test score vs. pre-training hours, demonstrating that nanoT5 reaches performance levels comparable to original T5 checkpoints within 24 hours.

Insights and Discussion

A key finding is the massive data efficiency of the T5 architecture; reaching performance "akin to publicly-available checkpoints" with 150x less data suggests that original models may have been significantly over-trained relative to their parameter count. The "RMS Scaling" added to AdamW proved to be the "secret sauce" for stability and speed, overcoming the divergence issues often seen when training T5 with standard AdamW.

Limitations

The framework is sensitive to precision; FP16 consistently caused divergence, necessitating hardware that supports BF16 (e.g., NVIDIA Ampere architecture). Additionally, structural changes like Flash Attention or ALiBi positional embeddings were avoided to maintain a straightforward and stable baseline.

Conclusion

nanoT5 demonstrates that the encoder-decoder architecture can be made highly efficient and accessible to researchers with limited resources. By providing an open-source, PyTorch-native framework, the authors aim to democratize language modeling research. Future work will explore more diverse training objectives like UL2 to further enhance model versatility.

Source: nanoT5: A PyTorch Framework for Pre-training and Fine-tuning T5-style Models with Limited Resources (Nawrot, 2023).

Summary updated

Abstract

State-of-the-art language models like T5 have revolutionized the NLP landscape, but their computational demands hinder a large portion of the research community. To address this challenge, we present nanoT5, a specially-optimized PyTorch framework for efficient pre-training and fine-tuning of T5 models. Drawing on insights from optimizer differences and prioritizing efficiency, nanoT5 allows a T5-Base model to be pre-trained on a single GPU in just 16 hours, without any loss in performance. With the introduction of this open-source framework, we hope to widen the accessibility to language modelling research and cater to the community's demand for more user-friendly T5 (Encoder-Decoder) implementations. Our contributions, including configurations, codebase, software/hardware insights, and pre-trained models, are available to the public, aiming to strike a balance between research accessibility and resource constraints in NLP.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
C4 · T5-Base pre-trainingnanoT5 T5-Base (248M parameters)pre-training time16 hourspre-training · model=T5-Base · params=248M · hardware=single GPU
Source quote
L10: Recognizing this gap, we introduce nanoT5, a resource-efficient, open-source PyTorch framework designed for the pre-training and fine-tuning of T5 models. Inspired by pioneering efforts such as nanoGPT \cite{karpathy2021nanogpt} and Cramming \cite{Geiping2022CrammingTA}, nanoT5 uniquely concentrates on enhancing the training pipeline specifically for T5 encoder-decoder models. Our framework includes optimized configurations and scripts, enabling researchers to pre-train a T5-Base model with 248M parameters on a single GPU in just 16 hours. Every facet, from data preprocessing and model architecture to the learning rate schedule, has been tuned for both efficiency and adaptability. With nanoT5, users can seamlessly initiate model pre-training within minutes of accessing our GitHub repository.
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
C4 · Held-out set of C4AdamW baselinenegative log-likelihood1.953pre-training · optimizer=AdamW · learning-rate-schedule=cosine
Source quote
L107: AdamW │ 2.040 │ 1.953
C4 · Held-out set of C4Adafactor baselinenegative log-likelihood1.993pre-training · optimizer=Adafactor · learning-rate-schedule=cosine
Source quote
L105: Adafactor │ 1.995 │ 1.993
BibTeX
@misc{nawrot2023nanot,
  author = {Piotr Nawrot},
  title = {{nanoT5: A PyTorch Framework for Pre-training and Fine-tuning T5-style Models with Limited Resources}},
  year = {2023},
  eprint = {2309.02373},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2309.02373},
}

Loading related content...

Figure