MODEL EXPLORER / VISION MILESTONES
Turn an image into tokens
Where does an image become a sequence for a Transformer?
RECORDED NUMERICAL EXAMPLE
An image becomes a sequence of patches.
Recorded image-to-token conversion and class-token attention. A stride-four patch projection is equivalent to flattening each RGB patch and applying the same linear map. Learned positions preserve where each patch belongs.
Move a bright 4×4 patch in a synthetic 16×16 image. The attention map shows head 0's class-token weights to the sixteen patch tokens, excluding its self-weight. These are untrained weights and are not a saliency explanation or object detector.
Min 0 · Max 1
Recorded cell values
| Row / col | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 6 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 7 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 9 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 11 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 12 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 13 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 15 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Min 0.05044 · Max 0.06928
Recorded cell values
| Row / col | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| 0 | 0.06928 | 0.05044 | 0.05532 | 0.058 |
| 1 | 0.06014 | 0.05389 | 0.05786 | 0.06021 |
| 2 | 0.05923 | 0.05507 | 0.06103 | 0.06262 |
| 3 | 0.05101 | 0.05339 | 0.05474 | 0.0647 |
Each heatmap uses its own scale. Mint is positive, rust is negative, and the lightest color is zero. Table values are rounded to four significant digits.
Bars share one scale within this example. Values are rounded to four significant digits.
- Patch tokens
- 16
- Tokens including class token
- 17
- Class-token self-attention weight
- 0.07306
- Total class attention row weight
- 1
Verified by the local recipe
- Strided patch convolution equals independent flatten-and-linear projection
- Sixteen patch embeddings plus one class token form a seventeen-token sequence
- Without positions, patch permutation preserves the class output; fixed learned positions break this symmetry
- Changing one patch changes only its embedding, but global attention can change the class output
Download the source and run.py to reproduce these checks. Choosing an example here replays recorded values.
THE SAME MODEL, ON YOUR MACHINE
Pick up where
the graph leaves off.
Inspect patch projection, learned positions and a class token, then compare its attention across a synthetic image.
Use in VS Code ↗1. Save these files in one folder
2. Reproduce the example
Use Python 3.13 in a dedicated environment, matching the tested recipe. These commands are for macOS / Linux shells.
python3.13 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python run.pyExpected output: [1,3]
Input 1: [1,3,16,16] · float32 randn · CPU / eval · seed 0
3. Open the source in TensorViz
Install the preview, open this folder in local VS Code, and choose Open as Graph above TinyViT in model.py. Select your Python environment. Save before choosing Validate.
Installation and supported setup ↗
The recipe was run with Python 3.13.13 and Torch 2.7.1. This is an untrained example; a successful shape check does not measure accuracy.
ABOUT THIS EXAMPLE
Inspect patch projection, learned positions and a class token, then compare its attention across a synthetic image.
Architecture · 2020
Vision Transformer
A 16×16 RGB input becomes sixteen 4×4 patches with width 16, plus a class token. One pre-LN encoder, two attention heads, GELU MLP, learned positions and a linear three-class head.
Source, capture & limitations +
The paper title refers to one original patch-size configuration; this teaching model uses 4×4 patches to keep the example small. All weights are untrained. Attention maps are recorded probabilities, not saliency or evidence of recognition quality.
Original TensorViz teaching example. PyTorch provides the underlying operators.
No separate redistribution license has been declared for these project examples.
- Content revision
0d36b50d0b83ec26- Source SHA-256
3d8cc36b80819465f0cf328570d80777db7ff486981777d425ee16eaa9ced676- Captured
- 2026-09-17 · Python 3.13.13 / Torch 2.7.1
Reduced ViT CPU forward with independent patch-projection equivalence, permutation/position tests and patch-local versus global influence checks.
Read the model manifest ↗