# BERT Base vs ViT-B/16

The same transformer applied to text and to images.

**ViT-B/16 has 23M fewer parameters than BERT Base: 4 layers added, 2 removed, 5 changed.**

Source: https://neurarch.com/diff/bert-base-vs-vit-b16.html

## Sides

| | BERT Base | ViT-B/16 |
|---|---|---|
| Layers | 9 | 11 |
| Parameters | 31M | 8.4M |
| Input | 1 × 512 | 3 × 224 × 224 |
| Output | 1 × 512 × 768 | 196 × 1000 |
| Forward-passes | yes | yes |
| Est. train cost | $0.197 | $0.105 |
| T4 16GB | fits | fits |
| A100 40GB | fits | fits |
| H100 80GB | fits | fits |

## Deltas (ViT-B/16 relative to BERT Base)

- Parameters: -23M (-72.9%)
- Layers: +2
- Added 4, removed 2, changed 5, unchanged 4

## Layer by layer

| # | Status | BERT Base | Params | Output | ViT-B/16 | Params | Output |
|---|---|---|---|---|---|---|---|
| 1 | changed (shape) | input_ids (Input) |  | 1 × 512 | image (Input) |  | 3 × 224 × 224 |
| 2 | removed | word_embed (Embedding) | 23M | 1 × 512 × 768 |  | |  |
| 3 | added |  | |  | patch_embed (Patch Embed) | 591K | 196 × 768 |
| 4 | changed (maxLen) | pos_embed (Positional Encoding) |  | 1 × 512 × 768 | pos_embed (Positional Encoding) |  | 196 × 768 |
| 5 | removed | embed_norm (Layer Norm) | 1.5K | 1 × 512 × 768 |  | |  |
| 6 | changed (p) | embed_drop (Dropout) |  | 1 × 512 × 768 | dropout (Dropout) |  | 196 × 768 |
| 7 | added |  | |  | norm_1 (Layer Norm) | 1.5K | 196 × 768 |
| 8 | same | self_attn (Multi Head Attention) | 2.4M | 1 × 512 × 768 | attn (Multi Head Attention) | 2.4M | 196 × 768 |
| 9 | added |  | |  | residual_1 (Add) |  | 196 × 768 |
| 10 | same | norm (Layer Norm) | 1.5K | 1 × 512 × 768 | norm_2 (Layer Norm) | 1.5K | 196 × 768 |
| 11 | changed (embedDim, hiddenDim) | dense (Feed Forward) | 4.7M | 1 × 512 × 768 | mlp (Feed Forward) | 4.7M | 196 × 768 |
| 12 | added |  | |  | residual_2 (Add) |  | 196 × 768 |
| 13 | same | norm (Layer Norm) | 1.5K | 1 × 512 × 768 | norm_final (Layer Norm) | 1.5K | 196 × 768 |
| 14 | changed (inFeatures, outFeatures) | dense (Linear) | 591K | 1 × 512 × 768 | head (Linear) |  | 196 × 1000 |
| 15 | same | cls_embedding (Output) |  | 1 × 512 × 768 | class_logits (Output) |  | 196 × 1000 |

## What this is not

- The two are priced at different declared inputs (1 × 512 against 3 × 224 × 224), so memory, cost and GPU fit are each right about their own model and are not a comparison between them. The layer and parameter deltas are unaffected.
- 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
- ViT-B/16: https://neurarch.com/templates/vit-b16/model.json
- Check a graph of your own: `POST https://www.neurarch.com/api/v1/plan`
