Zero Labs
Industry News / AI

How Vision-Language Models Actually See Images: Inside ViT, CLIP, SigLIP & 3D M-RoPE

Source · Towards AI By Latent AI Labs

From the publisher’s feed, collected in the ZeroLabs newsroom.

Why an “iPod” sticker fools OpenAI CLIP (64.5%) while Qwen2.5-VL reads it cleanly — measured layer by layer on a 96 GB Blackwell GPU.By Latent AI Labs (@LatentAILabs)TL;DR — How Do Vision-Language Models (VLMs) Actually See Images?Modern Vision-Language Models (such as Qwen2.5-VL, GPT-4o, and Claude 3.5 Sonnet) process images in three stages:1. Vision Transformer (ViT) Patch Slicer & 2×2 Spatial Patch Merger: A 560 × 560 RGB photograph (940,800 floats) is sliced by a 14 × 14 pixel grid into 40 × 40 = 1,600 patches, projected into 1,280-dimensional vectors, refined through 28 local-window ViT layers (112 × 112 px) and 4 global full-attention layers (Layers 7, 15, 23, 31), and compressed 4-into-1 by a 2×2 Spatial Patch Merger into 400 Visual Word tokens (2,048-D) — cutting LLM self-attention pairs 16× (2.56M → 160K).2. Dual Spatial Compass (2D ViT RoPE + 3D M-RoPE [16t, 24h, 24w]): Each attention head splits its 64 rotary position frequency pairs into 16 Time (t), 24 Height (h / Row y), and 24 Width (w / Column x) dials so a 1D language model natively understands 2D aspect ratios (NaViT) and 3D video timelines.3. Cross-Modal Attention & Visual Contrastive Decoding (VCD): In Layers 17–28, cross-modal grounding heads concentrate up to 96.8%–99.8% of their visual attention onto the target object quadrant, while Visual Contrastive Decoding (VCD) subtracts noisy-image language priors (ℓ_VCD = (1+α)ℓ(v) − αℓ(v')) to reduce object hallucinations by 41.5%.In 2021, Gabriel Goh and colleagues at OpenAI demonstrated a famous vulnerability in computer vision known as a typographic attack: stick a paper label reading “iPod” onto a green Granny Smith apple, and OpenAI’s CLIP classifies the piece of fruit as an electronic music player.We rebuilt that experiment with a synthetic studio photograph of a green apple and a digital label, and ran it through OpenAI CLIP (openai/clip-vit-base-patch32), Google SigLIP (google/siglip-base-patch16-224), and Alibaba Qwen2.5-VL-3B-Instruct on a 96 GB NVIDIA RTX PRO 6000 Blackwell GPU:Clean Green Apple: CLIP predicts “a photo of a green Granny Smith apple” at 100.00% (cosine = 0.3302), with 0.00% for "a photo of an iPod electronic music player" (cosine = 0.2033).Apple + "iPod" Label: "Green Apple" drops to 35.47% (cosine = 0.2641), and "iPod" takes first place at 64.51% (cosine = 0.2701).Apple + "Pizza" Label: "Green Apple" drops to 19.86% (cosine = 0.2591), and "Pizza" takes first place at 80.07% (cosine = 0.2730).Figure 1: GPU measurement of the "iPod" typographic attack on OpenAI CLIP (64.51% iPod) vs. Qwen2.5-VL-3B on a 96 GB NVIDIA RTX PRO 6000 Blackwell GPU. Image by the author; source apple photo AI-generated with a digital label.Yet when we feed those exact same labeled photographs into a modern 3-billion-parameter Vision-Language Model (Qwen2.5-VL-3B-Instruct) and ask what object is in the photo and what word is printed on the sticker, it separates the physical fruit from the text:On the "iPod" apple (1,342.7 ms cold start): "This is an apple, and the word written on the paper sticker is 'iPod.'"On the "Pizza" apple (240.7 ms warm inference): "This is an apple with a paper sticker that says 'Pizza.'"Even more intriguing: that same Vision-Language Model reads a 4-digit security code (PIN: 4829) off a wide 1120 × 280 shipping manifest accurately, yet looks at a clean geometric diagram of 15 overlapping circles and counts "12".Why does a printed word hijack CLIP? How does a 1D language model — built to predict the next token in a sequence — represent 2D photographs and 3D video? And why does a model that can read fine print fail to count 15 rings?We hooked directly into Qwen2.5-VL-3B’s 32-layer Vision Transformer (ViT) and 36-layer Language Model on our Blackwell GPU to measure the tensors, cosine similarities, positional IDs, and attention weights layer by layer (watch the companion 25-minute animated video on YouTube here).https://medium.com/media/3d3907e7090805703a8975dee4fce162/hrefFigure 2: How the Vision Transformer slices a 560×560px photograph by a 14×14px grid into 40×40 = 1,600 patches. Image by the author.Experiment 0. Why Does an “iPod” Sticker Fool CLIP? (The ×100.0 Temperature Multiplier)Direct Answer: OpenAI CLIP compresses an entire image into a single 512-dimensional vector and multiplies raw image-text cosine similarities by a learned temperature scale of 100.0 (exp(4.6052)) before applying Softmax. Because written text in web images strongly predicts captions, OCR features from the "iPod" sticker nudge the "iPod" cosine just +0.0060 above "Green Apple" (0.2701 vs. 0.2641), which the ×100.0 Softmax amplifies into a 64.51% vs. 35.47% victory.Here are the exact cosine similarities (cos(θ) = (I · T) / (‖I‖ ‖T‖)) and Softmax probabilities recorded on our GPU for apple_ipod.jpg across all five candidate prompts:1. "a photo of an iPod electronic music player"Cosine: 0.2701 → Scaled Logit (100 × cos): 27.01 → Softmax Probability: 64.51%2. "a photo of a green Granny Smith apple"Cosine: 0.2641 → Scaled Logit (100 × cos): 26.41 → Softmax Probability: 35.47%3. "a photo of an analog wall clock"Cosine: 0.1849 → Scaled Logit (100 × cos): 18.49 → Softmax Probability: 0.01%4. "a photo of a slice of pizza"Cosine: 0.1718 → Scaled Logit (100 × cos): 17.18 → Softmax Probability: 0.00%5. "a photo of a red fox in the snow"Cosine: 0.1106 → Scaled Logit (100 × cos): 11.06 → Softmax Probability: 0.00%P(iPod) = exp(27.01) / (exp(27.01) + exp(26.41) + ...) ≈ 1 / (1 + exp(-0.60)) = 64.57% (64.51% exact across all 5 prompts using unrounded GPU logits)Because CLIP pools the entire photograph into one 512-D vector, features representing green apple skin and OCR features representing the letters i-P-o-d compete inside one shared bottleneck (Goh et al., Distill 2021).You can reproduce this measurement in PyTorch:import torchfrom PIL import Imagefrom transformers import CLIPModel, CLIPProcessormodel = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").eval()proc = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")prompts = [ "a photo of a green Granny Smith apple", "a photo of an iPod electronic music player", "a photo of a slice of pizza", "a photo of an analog wall clock", "a photo of a red fox in the snow",]inp = proc( text=prompts, images=Image.open("apple_ipod.jpg"), return_tensors="pt", padding=True,)with torch.no_grad(): out = model(**inp)cos = out.logits_per_image / model.logit_scale.exp() # [0.2641, 0.2701, ...]probs = out.logits_per_image.softmax(dim=-1) * 100 # [35.47%, 64.51%, ...]A modern Vision-Language Model (VLM) avoids this single-vector bottleneck by keeping the image as hundreds of spatial patch tokens, allowing the language model to attend separately to the fruit and to the sticker.1. How Does a Vision Transformer (ViT) Turn Pixels into Patch Tokens?Direct Answer: A Vision Transformer (ViT) divides an image of resolution H × W by a fixed patch size P × P (14 × 14 pixels in Qwen2.5-VL) to produce a grid of (H/P) × (W/P) spatial patches. For a 560 × 560 image, 560 ÷ 14 = 40, yielding 40 × 40 = 1,600 patches (the sequence length N). A learned linear projection maps the raw RGB pixel values inside each patch into a 1,280-dimensional embedding vector (the feature dimension D), creating a [1,600 × 1,280] ViT input tensor.In classical digital image processing, computer vision slid local 3×3 filters (such as adaptive or Sobel edge filters) across an image pixel by pixel. In 2020, Alexey Dosovitskiy et al. ("An Image is Worth 16×16 Words", ICLR 2021) replaced convolutional hierarchies by slicing an image into non-overlapping patches and projecting each patch into a Transformer token.We hooked into the Vision Transformer (vlm.visual) inside Qwen2.5-VL-3B-Instruct on our GPU as it processed a 560 × 560 RGB image (940,800 float values; center pixel (280, 280) = RGB [147, 132, 157], orange fur (140, 220) = [149, 106, 72], snow (480, 280) = [180, 195, 224]):1. The 14×14 Spatial Grid (560 ÷ 14 = 40):Qwen2.5-VL uses a 14 × 14 pixel patch size. Dividing 560 px ÷ 14 px gives 40 patches across and 40 patches down, or 40 × 40 = 1,600 spatial patches (image_grid_thw = [[1, 40, 40]]).2. Patch Unrolling (588 Spatial RGB Values / 1,176 with Temporal Duplication):A single 14 × 14 RGB square holds 14 × 14 × 3 = 588 pixel values. Under the hood, because Qwen2.5-VL uses a unified 3D patchifier (Conv3d with temporal_patch_size = 2) for both photos and video, a static photograph is duplicated across 2 temporal frames so each tube input has 2 × 14 × 14 × 3 = 1,176 values (pixel_values.shape = [1600, 1176]).3. Linear Patch Projection (→ 1,280-D):The learned projection matrix maps each patch into a 1,280-dimensional visual embedding vector. Keep the two dimensions distinct: 1,600 is the number of patches N in the 40 × 40 grid, while 1,280 is the feature vector length D inside each single patch, forming the [1,600 × 1,280] ViT tensor (L2 norm = 417.01).Figure 3: Multiplying each patch by the learned projection matrix produces a 1,280-D vector; stacking all 1,600 patches forms the [1,600 × 1,280] ViT tensor. Image by the author.2. How Do Patches Talk? Windowed vs. Global ViT Attention ([7, 15, 23, 31])Direct Answer: Running full self-attention across 1,600 patches on all 32 ViT layers would require 1,600² = 2.56 million pairs per layer. To keep compute linear in image size, Qwen2.5-VL restricts 28 of its 32 ViT layers to local 112 × 112 pixel windows (8 × 8 = 64 patches per window) and runs full global self-attention only at 4 checkpoint layers (Layers 7, 15, 23, and 31, 0-indexed).28 Windowed Attention Layers (112 × 112 px Local Windows):Patches only attend within their local 8 × 8 patch neighborhood (64 patches). Because window size is fixed, compute scales linearly O(N) with pixel count.4 Global Full-Attention Checkpoints (0-indexed Layers 7, 15, 23, 31):At every 8th layer (fullatt_block_indexes = [7, 15, 23, 31]), window walls are removed and all 1,600 patches attend across the entire image (2.56M pairs), integrating global scene geometry.Figure 4: Windowed vs. Global ViT attention layers and pairwise cosine similarity distribution of the resulting visual tokens. Image by the author.Across the 400 merged visual tokens exiting the vision tower ([400, 2048], including the diagonal), we measured the pairwise cosine similarity distribution:10th percentile (p10): 0.1398 (82.0° apart)Median pair (p50): 0.2886 (73.2° apart)90th percentile (p90): 0.5567 (56.2° apart)99th percentile (p99): 0.8225 (34.7° tight cluster)3. CLIP Softmax vs. Google SigLIP Sigmoid: How Vision Models Align with TextDirect Answer: OpenAI CLIP aligns images and text using a batch Softmax (InfoNCE) loss (Softmax(100 · I_i · T_j)), which requires normalizing across every negative example in the batch. Google SigLIP (Zhai et al., ICCV 2023) replaces the batch Softmax with an independent pairwise Sigmoid (1 / (1 + exp(-117.33 · I_i · T_j + 12.93))), turning every (Image_i, Text_j) pair into a standalone binary classification problem with zero global batch normalization.We evaluated both openai/clip-vit-base-patch32 and google/siglip-base-patch16-224 across 5 studio images (Green Apple, 10:10 Clock, Red Fox, Plate & Knife, Vault Receipt) and their 5 matching captions on our GPU (m3_clip_vs_siglip_5x5):Figure 5: Contrastive image-text alignment in CLIP vs. Google SigLIP's independent pairwise sigmoid equation. Image by the author.Measured GPU Comparison: OpenAI CLIP vs. Google SigLIPScoring Equation & Learned Parameters:• OpenAI CLIP (ViT-B/32): Softmax(100.0 · I_i · T_j) (scale = 100.0, no bias)• Google SigLIP (ViT-B/16-224): 1 / (1 + exp(-117.33 · I_i · T_j + 12.93)) (scale = 117.33, bias = -12.93)5×5 Diagonal Cosine Similarities (Apple, Clock, Fox, Plate, Receipt):• OpenAI CLIP: 0.3464, 0.3507, 0.3344, 0.3023, 0.2723• Google SigLIP: 0.1111, 0.0687, 0.1633, 0.1591, 0.14145×5 Diagonal Match Probabilities:• OpenAI CLIP (Softmax over 5 captions): 100.0%, 100.0%, 100.0%, 100.0%, 99.99% (max off-diagonal: 0.01%)• Google SigLIP (Independent Sigmoid): 52.44% (Apple; 97.57% on "Granny Smith" prompt), 0.84% (Clock), 99.83% (Fox), 99.72% (Plate), 97.47% (Receipt) — and 0.00% across all 20 off-diagonal cells!Typographic Attack Robustness:• On "iPod" Apple: CLIP flips to 64.51% iPod (35.47% Apple). SigLIP predicts 40.29% Apple vs. 0.97% iPod.• On "Pizza" Apple: CLIP flips to 80.07% Pizza (19.86% Apple). SigLIP predicts 18.07% Apple vs. 3.13% Pizza.Two key engineering takeaways emerge from these numbers:Why SigLIP Resisted the "iPod" and "Pizza" Labels: Even if we convert SigLIP's raw logits back into a Softmax over the candidate labels, "Green Apple" still wins at ~98.6% — showing that SigLIP's robustness comes from its learned ViT-B/16 representations and WebLI training recipe rather than the sigmoid readout alone.Why SigLIP Scored the 10:10 Clock Caption at 0.84%: Because SigLIP learns a strong negative bias (-12.93) so non-matching pairs default to 0.00%, an image-text pair must exceed a cosine threshold of 12.93 / 117.33 = 0.1102 to cross 50% probability. On our descriptive clock caption, SigLIP's cosine was 0.0687 (still the highest in its row, well above all off-diagonals at ≤ 0.004), which maps to 0.84% under the uncalibrated sigmoid threshold.4. How Does the 2×2 Spatial Patch Merger Cut LLM Attention by 16×?Direct Answer: Feeding all 1,600 ViT patches directly into a 36-layer language model would require 1,600² = 2,560,000 self-attention pairs per layer. To compress the visual sequence before Layer 0 of the LLM, Qwen2.5-VL uses a 2×2 Spatial Patch Merger (vlm.visual.merger) that concatenates every 2 × 2 block of adjacent 14 × 14 px patches (4 × 1,280 = 5,120-D) and projects it through a 2-layer MLP into a single 2,048-D Visual Word token. This reduces token count 4× (1,600 → 400) and cuts quadratic self-attention compute 4² = 16× (2.56M → 160K pairs).Figure 6: The 2×2 Spatial Patch Merger concatenates each 2×2 block of 14×14px patches into a 5,120-D vector and projects it through a 2-layer MLP into one 2,048-D Visual Word token. Image by the author.Concatenate 2×2 Spatial Neighbors (4 → 1):Four adjacent 14 × 14 px patches covering a 28 × 28 px square are normalized with RMSNorm and concatenated into a 5,120-dimensional vector.2-Layer MLP Projection (5,120-D → 2,048-D):A 2-layer MLP (Linear(5120 → 5120) → GELU → Linear(5120 → 2048)) maps each 5,120-D block into the exact 2,048-dimensional embedding space of the Qwen2.5-3B language model.You can inspect these exact tensor shapes in 10 lines of Python:from transformers import AutoConfigcfg = AutoConfig.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct")v = cfg.vision_configprint(v.patch_size, v.temporal_patch_size, v.spatial_merge_size)# -> 14 2 2print(v.window_size, v.fullatt_block_indexes, v.hidden_size, v.out_hidden_size)# -> 112 [7, 15, 23, 31] 1280 2048feats = {}vlm.visual.merger.register_forward_hook( lambda m, inp, out: feats.update(pre=inp[0].shape, post=out.shape))# 560x560 image -> pre: [1600, 1280], post: [400, 2048]5. Native Dynamic Resolution (NaViT) vs. Downscaled Square InputDirect Answer: Early vision models forced every image into a fixed 224 × 224 square, distorting aspect ratios and blurring small text. Native Dynamic Resolution (Patch n' Pack / NaViT, Dehghani et al., NeurIPS 2023) slices images at their native aspect ratio and pixel resolution (rounded to multiples of 28 px), preserving fine OCR details on wide banners and tall documents.We tested a wide 1120 × 280 (4:1 aspect ratio) shipping manifest containing tensors_bf16 = 96.0 GB and VAULT PIN: 4829 on our GPU (m4_dynamic_resolution_ocr) under two regimes:Figure 7: Downscaling a 1120×280 manifest into a 140×140 square (25 visual tokens) blurs the digits into "4857", whereas Native Dynamic Resolution (80×20 raw patches → 400 visual tokens) reads "4829" and "96.0 GB". Image by the author.Regime 1 — Downscaled Square (140 × 140 px, 1:1 aspect ratio, 16× fewer pixels):Produces 10 × 10 = 100 raw patches → 25 merged visual tokens (5 × 5) in 452.2 ms.VLM Output: "The exact 4-digit VAULT PIN printed in the bottom right box is 4857. The tensors_bf16 value is 2." (Incorrect — fine digits blurred!)Regime 2 — Native Dynamic Resolution (1120 × 280 px, 4:1 original aspect ratio):Produces 80 × 20 = 1,600 raw patches → 400 merged visual tokens (40 × 10) in 570.9 ms.VLM Output: "The exact 4-digit VAULT PIN printed in the bottom right box is 4829. The tensors_bf16 value is 96.0 GB." (Exact match!)(Methodology note: shrinking 1120 × 280 to 140 × 140 reduces pixel count by 16× alongside the 4:1 → 1:1 aspect crush, showing why allocating 400 native-aspect tokens is critical for document OCR.)6. How Does a 1D Language Model Understand 2D Space? (3D M-RoPE [16, 24, 24])Direct Answer: Standard Rotary Position Embedding (RoPE) encodes a single 1D sequence index m across all 64 complex frequency pairs of an attention head (head_dim = 128). 3D Multimodal RoPE (M-RoPE) partitions those 64 frequency pairs into three independent coordinate sections — 16 pairs for Time (t), 24 pairs for Height (h / Row y), and 24 pairs for Width (w / Column x) (16 + 24 + 24 = 64 pairs) — stamping every visual token with its exact 3D (t, h, w) coordinate.3D M-RoPE Partition Inside Every Attention Head (head_dim = 128 -> 64 pairs)────────────────────────────────────────────────────────────────────────────mrope_section = [ 16 pairs (32D) , 24 pairs (48D) , 24 pairs (48D) ] └── TIME (t) ──┘ └─ HEIGHT (h) ─┘ └─ WIDTH (w) ──┘We hooked into vlm.model.get_rope_index (position_ids of shape [3, 1, seq_len]) on our GPU (m5_mrope_3d_coordinates) and recorded the exact position IDs for text vs. image tokens:Figure 8: Live GPU trace of the [3, 1, N] M-RoPE position_ids tensor and the Dual Spatial Compass (2D RoPE inside the 32-layer ViT + 3D M-RoPE inside the 36-layer LLM). Image by the author.1D Text Prompt Tokens (Tokens 0..4):All three coordinates step together (t = h = w = [0, 1, 2, 3, 4]), making M-RoPE mathematically identical to standard 1D RoPE on text.2D Image Tokens (Starting at position 15, Row 0, Cols 0..7):• time_t = [15, 15, 15, 15, 15, 15, 15, 15] (frozen across the entire static photograph)• height_h = [15, 15, 15, 15, 15, 15, 15, 15] (frozen at 15 across Row 0; increments to 16 on Row 1, up to 34 on Row 19)• width_w = [15, 16, 17, 18, 19, 20, 21, 22] (increments left-to-right across the columns of Row 0)A Surprising Null Result: Why Flipping Only the LLM’s M-RoPE Didn’t Swap the ImageWhat happens if we leave the 400 visual token vectors untouched, but intercept vlm.model.get_rope_index in-flight and invert the LLM's Height and Width position IDs (h ← 49 - h, w ← 49 - w) on our 4-quadrant composite image (Top-Left: Apple, Top-Right: Clock, Bottom-Left: Fox, Bottom-Right: Plate & Knife)?We expected the LLM’s spatial answers to swap completely. They didn’t:Normal M-RoPE: “In the top-left corner of the image, there is an apple. In the bottom-right corner, there is a plate with a knife next to it.”Inverted LLM M-RoPE (h, w flipped): "In the top-left corner of the image, there is an apple. In the bottom-right corner, there is a knife." (Flipping width_w alone also left "top-left: apple, top-right: clock" unchanged!)Why didn’t inverting the LLM’s 3D M-RoPE move the apple to the bottom-right?Because as shown in Figure 8, Qwen2.5-VL actually uses a Dual Spatial Compass:Before the tokens ever reach the LLM, the 32-layer Vision Transformer (vlm.visual.rotary_pos_emb) applies its own 2D RoPE across all 4 global full-attention layers ([7, 15, 23, 31]).Those 4 global ViT layers bake each patch’s 2D quadrant context directly into the 2,048-D feature vectors, and the tokens enter the LLM in raster-scan order (v_001 ... v_400). Flipping only the LLM's M-RoPE position IDs after the ViT has already encoded spatial position creates a slight feature conflict ("plate with a knife" → "a knife"), but the ViT's baked-in spatial features still dominate!7. Cross-Modal Attention: Where Noun Tokens Look Across the 36 LLM LayersDirect Answer: In Qwen2.5-VL-3B’s 36-layer language model (576 total attention heads), middle-to-upper layers (Layers 17–28) contain heads that route visual information from specific image regions to corresponding text nouns, focusing up to 96.8%–99.8% of their visual attention mass onto the target object's quadrant during teacher-forced evaluation.Using attn_implementation="eager" on our 4-quadrant composite image (m6_cross_modal_grounding), we ran a teacher-forced forward pass naming each quadrant's object ("...top-left is a green apple, top-right is a wall clock, bottom-left is a red fox, and bottom-right is a dinner plate") and searched across Layers 14–29 (256 heads, 0-indexed) for the heads that concentrated the highest share of their visual attention onto each noun's target 10 × 10 quadrant (25% of the image area):Figure 9: Cross-modal attention heatmaps from the highest-scoring heads in Layers 17–28 of Qwen2.5-VL-3B on our 4-quadrant test image. Image by the author."apple" (Token #462, Top-Left Quadrant):Peak Head: Layer 17 · Head 10 (99.76% of visual attention on Top-Left) · Filtered Ensemble (>45% heads): 78.70%"clock" (Token #469, Top-Right Quadrant):Peak Head: Layer 21 · Head 14 (96.78% of visual attention on Top-Right) · Filtered Ensemble (>45% heads): 73.76%"fox" (Token #476, Bottom-Left Quadrant):Peak Head: Layer 27 · Head 1 (98.96% of visual attention on Bottom-Left) · Filtered Ensemble (>45% heads): 83.15%"plate" (Token #484, Bottom-Right Quadrant):Peak Head: Layer 28 · Head 10 (99.29% of visual attention on Bottom-Right) · Filtered Ensemble (>45% heads): 83.10%(Methodology note: Because these peak heads are selected as the maximum across 256 middle-layer heads on a teacher-forced sentence that names each corner prior to the noun, and the ensemble averages heads already exceeding a 45% target-quadrant share, these heatmaps represent upper-bound spatial localization in Layers 17–28.)8. Attention Sinks & Visual Token Sparsity Across All 36 LayersDirect Answer: Averaging attention across all 16 heads per layer from Layer 0 to Layer 35 (m7_36layer_attention_telemetry) shows that visual tokens receive only 2.5% to 31.2% of total attention per layer (peaking at 31.18% on Layer 21), while text and initial Attention Sink tokens (Tokens 0..3) absorb the rest. Within the visual attention distribution in Layers 17–35, the top 15% of visual tokens (60 of 400 patches) capture 55.9% to 81.15% of all visual attention mass (peaking at 81.15% on Layer 27).Figure 10: Measured 36-layer attention allocation across text tokens, initial sink tokens, and visual tokens in Qwen2.5-VL-3B. Image by the author.Layers 0–2 (Prompt Text Parsing):89.54% to 94.65% of attention stays on the text tokens, while visual tokens receive only 4.17% to 8.14% and the first 4 sink tokens receive 1.18% to 2.32%.Layers 3–9 (Attention Sink Parking):Just as in text LLMs (Episode 3), 56.36% to 69.41% of total attention mass parks on the first 4 tokens of the sequence (peaking at 69.41% on Layer 5), while visual tokens receive only 2.47% to 5.12%.Layers 17–33 (Visual Readout & Sparsity):Visual attention rises to 31.18% on Layer 21 (24.37% on Layer 27). Across Layers 17–35, the top 15% of visual tokens (60 out of 400 patches) hold 55.9% to 81.15% of all visual attention mass (vs. 15.0% if uniform), explaining why token-pruning methods like FastV can drop low-attention background tokens in upper layers with minimal accuracy loss.9. Why VLMs Miscount Overlapping Objects & How Visual Contrastive Decoding (VCD) WorksA. Why Does Qwen2.5-VL Count “12” When Shown 15 Overlapping Circles?We fed three 504 × 504 geometric diagrams of overlapping colored rings (36 × 36 raw patches → 18 × 18 = 324 merged visual tokens) into Qwen2.5-VL-3B-Instruct (m8_counting_and_vcd_hallucination):Figure 11: Qwen2.5-VL-3B counts N=4 circles correctly ("4"), but answers "6" for N=8 and "12" for N=15. Image by the author.N = 4 Circles (86.7 ms): VLM outputs "4" (Correct).N = 8 Circles (83.6 ms): VLM outputs "6" (Under-counts by 2).N = 15 Circles (96.9 ms): VLM outputs "12" (Under-counts by 3).A plausible architectural contributor to this failure is the 2×2 Spatial Patch Merger from Section 4: when 15 rings pass through a tight central rosette, multiple ring intersections fall inside the same 28 × 28 px merged token and are mixed by the MLP before the language model begins counting.B. How Visual Contrastive Decoding (VCD) Suppresses Language PriorsIn English text corpora, “a white dinner plate and a silver knife” frequently co-occurs with “fork”. How strongly does that language prior pull a VLM toward "Yes" when asked whether a fork is present on a table that only has a plate and a knife?In 2024, Sicong Leng et al. (CVPR 2024) proposed Visual Contrastive Decoding (VCD) — the mathematical twin for VLMs of Classifier-Free Guidance (CFG) in image diffusion (Episode 4). VCD runs two forward passes: one on the clean image v, and a second on a noise-corrupted version v' to measure the model's blind language prior, then contrasts their logits:ℓ_VCD(y) = (1 + α) · ℓ(y | v, x) − α · ℓ(y | v', x) (with α = 1.0)Figure 12: Visual Contrastive Decoding (VCD) logit and probability shifts measured on Qwen2.5-VL-3B on our Blackwell GPU. Image by the author.Here are the exact bfloat16 next-token logits for "Yes" vs. "No" (and their binary Softmax probabilities renormalized over {Yes, No}) measured on our GPU (m8_counting_and_vcd_hallucination):1. Heavily Noised Image v' (12% image + 88% Gaussian noise — Language Prior):logit("Yes") = 25.750 · logit("No") = 26.625 → P("Yes, fork") = 29.42% (P("No") = 70.58%)2. Degraded Image (22% image + 78% Gaussian noise — Standard Decoding):logit("Yes") = 25.625 · logit("No") = 27.125 → P("Yes, fork") = 18.24% (P("No") = 81.76%)3. Degraded Image (+ VCD α = 1.0, 2 · ℓ(v_deg) − ℓ(v')):logit("Yes") = 25.500 · logit("No") = 27.625 → P("Yes, fork") = 10.67% (-41.5% reduction; P("No") = 89.33%)4. Clean Studio Image v (Standard Decoding):logit("Yes") = 25.250 · logit("No") = 29.625 → P("Yes, fork") = 1.24% (P("No") = 98.76%)5. Clean Studio Image v (+ VCD α = 1.0, 2 · ℓ(v) − ℓ(v')):logit("Yes") = 24.750 · logit("No") = 32.625 → P("Yes, fork") = 0.04% (~30× reduction; P("No") = 99.96%)Look at the exact logit arithmetic (2 · ℓ(v) − ℓ(v')):Even though greedy decoding (argmax) already answers "No" across all conditions (logit("No") > logit("Yes")), corrupting the image with 88% noise (v') causes the binary probability P("Yes, fork") to jump 23.7× from 1.24% to 29.42% — directly quantifying the language prior pull.Subtracting those noisy logits (2 × 25.625 − 25.750 = 25.500 and 2 × 27.125 − 26.625 = 27.625) reduces P("Yes, fork") on the degraded image from 18.24% to 10.67% and raises P("No fork") on the clean image from 98.76% to 99.96%.Here is the 6-line PyTorch implementation of VCD:alpha = 1.0l_v = vlm(**inputs_clean).logits[0, -1].float() # ℓ(y | v, x)l_vp = vlm(**inputs_noisy).logits[0, -1].float() # ℓ(y | v', x)l_vcd = (1.0 + alpha) * l_v - alpha * l_vp # VCD logitsyes_id, no_id = ( processor.tokenizer.encode(w, add_special_tokens=False)[0] for w in ("Yes", "No"))probs_yes_no = torch.softmax(l_vcd[[yes_id, no_id]], dim=0)# Note: Leng et al. (CVPR 2024) also apply an adaptive plausibility mask.10. From Photos to Video & Practical Takeaways for ML EngineersWhen Qwen2.5-VL switches from a static photo to a video clip, two things happen:Conv3d [2, 14, 14] Temporal Tubes: Rather than duplicating a single photo, the Conv3d patchifier pairs 2 consecutive video frames into each 2 × 14 × 14 tube, halving the token count across time.Absolute-Time M-RoPE (second_per_grid_t): The 16 Time (t) rotary frequency pairs in mrope_section = [16, 24, 24] advance in proportion to real-world timestamps (second_per_grid_t × tokens_per_second), so a 2-second interval receives the same temporal rotation angle regardless of the video's sampling frame rate.Figure 13: Three-stage Vision-Language Model recap and preview of Episode 6 (How Video Generation AI Actually Works). Image by the author.4 Rules When Building with Vision-Language Models in ProductionPreserve Native Aspect Ratio & Resolution for OCR: Downsampling a 1120 × 280 receipt to 25 tokens flipped 4829 into 4857. Set min_pixels and max_pixels in AutoProcessor appropriately for document tasks.Don’t Trust Direct VLM Object Counts Above ~5 Overlapping Items: Because the 2×2 Spatial Patch Merger compresses 28 × 28 px regions into single tokens before the LLM, dense overlapping objects (N = 8 or 15 circles) should be routed through an explicit detection/segmentation tool or tiled crops.Treat Text Inside Images as an Untrusted Prompt-Injection Surface: VLMs read text inside images accurately — which fixes CLIP’s "iPod" classification bug, but creates a visual prompt injection vector where adversarial instructions printed on an object enter the LLM's context window.Use Contrastive Decoding Selectively: VCD widens the margin against language-prior hallucinations (98.76% → 99.96%), at the cost of 2× inference compute (two forward passes per token).Frequently Asked Questions (FAQ)1. Why does an “iPod” sticker on an apple fool OpenAI CLIP?OpenAI CLIP compresses an entire image into a single 512-dimensional vector and multiplies image-text cosine similarities by a learned temperature of 100.0 before Softmax. Multimodal neurons inside CLIP respond strongly to printed text, pushing the "iPod" cosine (0.2701) slightly above "Green Apple" (0.2641), which the ×100.0 Softmax turns into a 64.51% iPod prediction.2. Why are there 1,600 patches of 1,280 dimensions in Qwen2.5-VL?On a 560 × 560 pixel image sliced with a 14 × 14 pixel patch size, 560 ÷ 14 = 40 patches per side, giving 40 × 40 = 1,600 patches (sequence length N). Each patch is projected into a 1,280-dimensional feature vector (D), forming a [1,600 × 1,280] tensor before the 2×2 Spatial Patch Merger compresses it 4× into 400 tokens of 2,048 dimensions.3. How does 3D M-RoPE ([16, 24, 24]) work in Qwen2.5-VL?Each attention head in Qwen2.5-VL (head_dim = 128, or 64 rotary frequency pairs) splits its 64 frequency pairs into 16 pairs for Time (t), 24 pairs for Height (h, Row y), and 24 pairs for Width (w, Column x). For 1D text tokens, t = h = w; for 2D images, t stays constant while h and w track row and column coordinates; for 3D video, t advances with real timestamps.4. What is Visual Contrastive Decoding (VCD)?Visual Contrastive Decoding (Leng et al., CVPR 2024) reduces object hallucinations in Vision-Language Models by subtracting the next-token logits of a noise-corrupted image v' from the logits of the clean image v: ℓ_VCD(y) = (1 + α)ℓ(y | v, x) − αℓ(y | v', x). This suppresses answers driven purely by English word co-occurrence priors (such as assuming a fork is next to a plate and knife).How We Measured (Reproducibility & Disclosure Box)Hardware: NVIDIA RTX PRO 6000 Blackwell Server Edition (96.0 GB VRAM, bfloat16 for Qwen2.5-VL-3B, float32 for CLIP / SigLIP).Models: openai/clip-vit-base-patch32, google/siglip-base-patch16-224, and Qwen/Qwen2.5-VL-3B-Instruct via HuggingFace transformers.Protocol: All VLM generations use deterministic greedy decoding (do_sample=False, n = 1 run per condition). Attention telemetry in Sections 7–8 was captured with attn_implementation="eager" on a single teacher-forced pass. All test images (apple_clean.jpg, apple_ipod.jpg, apple_pizza.jpg, fox_clean.jpg, clock_1010.jpg, plate_knife_no_fork.jpg, wide_receipt_pin.jpg) are synthetic studio renders generated for controlled testing.Watch the Full Video & Explore the SeriesCompanion Episode 5 Video on YouTube: Why Does an “iPod” Sticker Fool AI? How Vision-Language Models Actually See ImagesEpisode 1: “Strawberry Has 2 R’s?” — How ChatGPT Actually Works (Medium Article)Episode 2: Why AI Says “Wait” — How Thinking Models Actually Work (Medium Article)Episode 3: How AI Reads a Whole Book at Once — Long Context, KV-Cache & The New Tower (Medium Article)Episode 4: Every Clock Says 10:10? How AI Actually Generates Images — Diffusion & Flow Matching (Medium Article)ReferencesDosovitskiy et al. (ICLR 2021) — “An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale” (arXiv:2010.11929)Radford et al. (OpenAI, ICML 2021) — “Learning Transferable Visual Models From Natural Language Supervision (CLIP)” (arXiv:2103.00020)Goh et al. (OpenAI, Distill 2021) — “Multimodal Neurons in Artificial Neural Networks”Zhai et al. (Google Research, ICCV 2023) — “Sigmoid Loss for Language Image Pre-Training (SigLIP)” (arXiv:2303.15343)Dehghani et al. (Google DeepMind, NeurIPS 2023) — “Patch n’ Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolution” (arXiv:2307.06304)Bai et al. (Qwen Team, 2025) — “Qwen2.5-VL Technical Report” (arXiv:2502.13923)Leng et al. (CVPR 2024) — “Mitigating Object Hallucinations in Large Vision-Language Models through Visual Contrastive Decoding (VCD)” (arXiv:2311.16922)How Vision-Language Models Actually See Images: Inside ViT, CLIP, SigLIP & 3D M-RoPE was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.