> ## Documentation Index
> Fetch the complete documentation index at: https://training-docs.cerebras.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# T5

> Text-to-text transformer model trained on the C4 dataset using a denoising objective, capable of performing a wide range of NLP tasks in a unified format.

## Model Description

T5 (Text-To-Text Transfer Transformer) is a sequence-to-sequence model that frames all NLP tasks as text-to-text problems. Originally introduced by Raffel et al. in [Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer](https://arxiv.org/abs/1910.10683), this model enables a single architecture to be applied across translation, summarization, classification, question answering, and more.

This implementation follows the T5.1.1 variant, which focuses on self-supervised pretraining using the C4 dataset, excluding supervised datasets during pretraining. T5 modifies the standard Transformer block architecture by reordering normalization and residual connections, as illustrated below.

T5's key contributions include:

* Proposing a unified text-to-text format for all NLP tasks (Section 2.4)
* Comparing encoder-decoder vs. decoder-only variants (Section 3.2)
* Evaluating different training objectives including denoising and language modeling (Section 3.3)

## Code Structure

The code for this model is located in the `t5` directory and reuses generic components for interfacing with training scripts and configuration systems.

* [`configs/`](https://github.com/Cerebras/modelzoo/tree/main/src/cerebras/modelzoo/models/nlp/t5/configs): YAML configuration files specifying training and model hyperparameters.
* [`model.py`](https://github.com/Cerebras/modelzoo/blob/main/src/cerebras/modelzoo/models/nlp/t5/model.py): Wrapper for initializing and interfacing with the T5 model.
* [`t5_model.py`](https://github.com/Cerebras/modelzoo/blob/main/src/cerebras/modelzoo/models/nlp/t5/t5_model.py): Main model implementation including encoder-decoder structure and forward logic.
* [`utils.py`](https://github.com/Cerebras/modelzoo/blob/main/src/cerebras/modelzoo/models/nlp/t5/utils.py): Utility functions for config parsing and data handling.

## Available Configurations

| Configuration                                                                                                               | Description                                                          |
| --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [`t5_small.yaml`](https://github.com/Cerebras/modelzoo/blob/main/src/cerebras/modelzoo/models/nlp/t5/configs/t5_small.yaml) | T5-Small: `d_kv=64`, `num_heads=6`, `encoder_num_hidden_layers=8`.   |
| [`t5_base.yaml`](https://github.com/Cerebras/modelzoo/blob/main/src/cerebras/modelzoo/models/nlp/t5/configs/t5_base.yaml)   | T5-Base: `d_kv=64`, `num_heads=12`, `encoder_num_hidden_layers=12`.  |
| [`t5_3B.yaml`](https://github.com/Cerebras/modelzoo/blob/main/src/cerebras/modelzoo/models/nlp/t5/configs/t5_3B.yaml)       | T5-3B: `d_kv=128`, `num_heads=32`, `encoder_num_hidden_layers=24`.   |
| [`t5_11B.yaml`](https://github.com/Cerebras/modelzoo/blob/main/src/cerebras/modelzoo/models/nlp/t5/configs/t5_11B.yaml)     | T5-11B: `d_kv=128`, `num_heads=128`, `encoder_num_hidden_layers=24`. |

## Workflow

For example workflows using language models from the Cerebras Model Zoo, see our tutorials on [pretraining](../../../getting-started/pre-train-your-first-model) and [fine-tuning](../../../getting-started/fine-tune-your-first-model).

For a complete list of Cerebras ModelZoo CLI commands, see the [command reference](../../cli-overview).

## Implementation Notes

This implementation includes the following deviations from the original T5.1.1 spec:

1. **Optimizer**: Adafactor is not currently supported. We use AdamW, which may lead to slightly higher final loss.
2. **Normalization**: We use `LayerNorm` instead of the originally proposed `RMSNorm` due to hardware support constraints.

## References

* [Attention Is All You Need](https://arxiv.org/abs/1706.03762)
* [Exploring the Limits of Transfer Learning with a Unified Text-to-text Transformer](https://arxiv.org/abs/1910.10683)
* [T5v1.1 Released Checkpoints](https://github.com/google-research/text-to-text-transfer-transformer/blob/main/released_checkpoints.md#t511)
* [Adam Optimizer](https://arxiv.org/abs/1412.6980)
* [AdamW Optimizer](https://arxiv.org/abs/1711.05101)
* [Adafactor Optimizer](https://arxiv.org/abs/1804.04235)
* [RMSNorm](https://arxiv.org/abs/1910.07467)
* [LayerNorm](https://arxiv.org/abs/1607.06450v1)
* [An Empirical Study of Positional Encoding](https://arxiv.org/pdf/2010.04903.pdf)
