Daniel Wang中文

How DeepSeek ViT works

1. RGB image

A screenshot of this site's homepage is the input, shown at 770 × 770 pixels with R, G and B channels.

Loading animation…

0:09

2. Normalization

Extract one real pixel as an RGB tuple. Map each component from 0~255 to −1~1 without changing the pixel's spatial position.

x′=x255−0.50.5x' = \frac{\frac{x}{255} - 0.5}{0.5}

Loading animation…

0:14

3. Patchify

14 × 14 pixels per patch form a 55 × 55 grid, preserving spatial order.

Loading animation…

0:05

4. Flatten each patch

Magnify one patch and flatten it row by row, channel by channel: 3 × 14 × 14 = 588 values.

Loading animation…

0:18

5. Patch embedding

Multiply a 1 × 588 input vector by a 588 × 1024 parameter matrix, then add bias to obtain a 1 × 1024 embedding. Each small square represents one floating point value.

Loading animation…

Only a subset of elements is drawn; brackets show the full dimensions.

0:16

6. Flatten the grid

Each of the 55 × 55 patches is one 1 × 1024 vector. Take the 3025 embeddings in row order, then display them as columns: token index horizontally and 1024 feature components vertically.

Loading animation…

Only a subset of elements is drawn; brackets show the full dimensions.

0:14

7. ViT layers

Input and output each contain 3025 vectors of 1024 dimensions. 32 Transformer layers update visual representations. In each attention layer, 2D-RoPE rotates Q/K using 2D positions; it is not an additive embedding.

Loading animation…

Visual representations: V∈R3025×1024V \in \mathbb{R}^{3025 \times 1024} (tokens shown as columns in the diagram)

Only a subset of elements is drawn; brackets show the full dimensions.

0:18

8. Pixel unshuffle

Zero-pad the right and bottom to 57 × 57. Gather each channel's 3 × 3 neighborhood into 361 vectors of 9216 dimensions.

Loading animation…

Only a subset of elements is drawn; brackets show the full dimensions.

0:14

9. Projector

Two MLP layers, 9216 → 5120 → 5120, with GELU between them, produce 361 visual tokens.

Loading animation…

Only a subset of elements is drawn; brackets show the full dimensions.

0:14

10. Enter the LLM

361 visual tokens form 19 rows. Row separators and boundary markers bring the image span to 382 positions, followed here by text.

Loading animation…

Only a subset of elements is drawn; brackets show the full dimensions.

0:14

Reference