# BERT Base vs T5 Small

Encoder-only against encoder-decoder.

**T5 Small has 26M more parameters than BERT Base: 14 layers added, 2 removed, 8 changed.**

Source: https://neurarch.com/diff/bert-base-vs-t5-small.html

## Sides

| | BERT Base | T5 Small |
|---|---|---|
| Layers | 9 | 20 |
| Parameters | 31M | 57M |
| Input | 1 × 512 | 1 × 512 |
| Output | 1 × 512 × 768 | 1 × 128 × 32128 |
| Forward-passes | yes | yes |
| Est. train cost | $0.197 | $0.207 |
| T4 16GB | fits | fits |
| A100 40GB | fits | fits |
| H100 80GB | fits | fits |

## Deltas (T5 Small relative to BERT Base)

- Parameters: +26M (+82.3%)
- Layers: +11
- Added 14, removed 2, changed 8, unchanged 1

## Layer by layer

| # | Status | BERT Base | Params | Output | T5 Small | Params | Output |
|---|---|---|---|---|---|---|---|
| 1 | added |  | |  | encoder_ids (Input) |  | 1 × 512 |
| 2 | changed (shape) | input_ids (Input) |  | 1 × 512 | decoder_ids (Input) |  | 1 × 128 |
| 3 | changed (numEmbeddings, embeddingDim) | word_embed (Embedding) | 23M | 1 × 512 × 768 | shared_embed (Embedding) | 16M | 1 × 512 × 512 |
| 4 | removed | pos_embed (Positional Encoding) |  | 1 × 512 × 768 |  | |  |
| 5 | added |  | |  | dec_embed (Embedding) | 16M | 1 × 128 × 512 |
| 6 | added |  | |  | enc_norm (Rms Norm) | 512 | 1 × 512 × 512 |
| 7 | added |  | |  | dec_sa_norm (Rms Norm) | 512 | 1 × 128 × 512 |
| 8 | added |  | |  | enc_self_attn (Multi Head Attention) | 1.1M | 1 × 512 × 512 |
| 9 | added |  | |  | dec_self_attn (Causal Attention) | 1.0M | 1 × 128 × 512 |
| 10 | added |  | |  | enc_residual (Add) |  | 1 × 512 × 512 |
| 11 | added |  | |  | dec_sa_residual (Add) |  | 1 × 128 × 512 |
| 12 | added |  | |  | enc_ffn_norm (Rms Norm) | 512 | 1 × 512 × 512 |
| 13 | added |  | |  | dec_ca_norm (Rms Norm) | 512 | 1 × 128 × 512 |
| 14 | added |  | |  | enc_ffn (Feed Forward) | 2.1M | 1 × 512 × 512 |
| 15 | added |  | |  | enc_ffn_residual (Add) |  | 1 × 512 × 512 |
| 16 | changed (normalizedShape) | embed_norm (Layer Norm) | 1.5K | 1 × 512 × 768 | enc_out_norm (Layer Norm) | 1.0K | 1 × 512 × 512 |
| 17 | removed | embed_drop (Dropout) |  | 1 × 512 × 768 |  | |  |
| 18 | changed (embedDim, numHeads) | self_attn (Multi Head Attention) | 2.4M | 1 × 512 × 768 | cross_attn (Multi Head Attention) | 1.1M | 1 × 128 × 512 |
| 19 | added |  | |  | dec_ca_residual (Add) |  | 1 × 128 × 512 |
| 20 | changed (type, normalizedShape) | norm (Layer Norm) | 1.5K | 1 × 512 × 768 | dec_ffn_norm (Rms Norm) | 512 | 1 × 128 × 512 |
| 21 | changed (embedDim, ffDim) | dense (Feed Forward) | 4.7M | 1 × 512 × 768 | dec_ffn (Feed Forward) | 2.1M | 1 × 128 × 512 |
| 22 | added |  | |  | dec_ffn_residual (Add) |  | 1 × 128 × 512 |
| 23 | changed (normalizedShape) | norm (Layer Norm) | 1.5K | 1 × 512 × 768 | dec_out_norm (Layer Norm) | 1.0K | 1 × 128 × 512 |
| 24 | changed (inFeatures, outFeatures) | dense (Linear) | 591K | 1 × 512 × 768 | lm_head (Linear) |  | 1 × 128 × 32128 |
| 25 | same | cls_embedding (Output) |  | 1 × 512 × 768 | logits (Output) |  | 1 × 128 × 32128 |

## What this is not

- Parameter counts are derived from the graph, not read from a checkpoint. They are exact for a graph that is fully specified and approximate for one that is not.
- Cost and GPU fit are estimates from the graph under one set of assumptions, not measurements of a run.

## Graphs

- BERT Base: https://neurarch.com/templates/bert-base/model.json
- T5 Small: https://neurarch.com/templates/t5-small/model.json
- Check a graph of your own: `POST https://www.neurarch.com/api/v1/plan`
