Comparisons / BERT Base vs ViT-B/16
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.
BERT Base
- Layers
- 9
- Parameters
- 31M
- Input
- 1 × 512
- Output
- 1 × 512 × 768
- Forward-passes
- yes
- Est. train cost
- $0.197
ViT-B/16
- Layers
- 11
- Parameters
- 8.4M
- Input
- 3 × 224 × 224
- Output
- 196 × 1000
- Forward-passes
- yes
- Est. train cost
- $0.105
The deltas
Every number is ViT-B/16 relative to BERT Base.
Which GPUs each one fits
Each side is measured at its own declared input (1 × 512 against 3 × 224 × 224). Both columns are right about their own model; the difference between them is not a fact about the designs.
| GPU | BERT Base | ViT-B/16 |
|---|---|---|
| T4 16GB | fits | fits |
| A100 40GB | fits | fits |
| H100 80GB | fits | fits |
Layer by layer
Aligned in topological order. 4 of 15 rows are the same layer with the same parameters.
Hide all 15 rows
| BERT Base | ViT-B/16 | ||||||
|---|---|---|---|---|---|---|---|
| Layer | Params | Output | Layer | 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.
Take it further
Open either graph in the editor, change it, and check it again: BERT Base · ViT-B/16
Compare any two models of your own, including anything on Hugging Face: the comparison tool.
Machine-readable: this page as markdown ·
the pair index ·
POST https://www.neurarch.com/api/v1/plan for a graph of your own.