Skip to main content
Open In Colab The LLaVA deep dive described how a vision language model is assembled: an image encoder produces patch features, a connector turns them into tokens of the language model, and the language model reads them together with the text. This section measures two things that the architecture diagram does not show. The first is cost: how many tokens an image becomes, and how that number grows with the image size. The second is reliability: how to score a model’s answers, and how often a model claims to see objects that are not in the image. The measurements use SmolVLM2-500M, the model fine-tuned in the SmolVLM lab. It is small enough to run on one consumer GPU, and the same questions apply to every model of this kind.

Visual tokens

A language model reads a sequence of tokens, and an image has to become part of that sequence. In LLaVA-1.5 the image encoder is a ViT with 14×1414 \times 14 patches on a 336×336336 \times 336 input, so it returns 24×24=57624 \times 24 = 576 patch features, and an MLP maps each one to a token: every image costs 576 tokens, the length of a page of text. Two choices change that number. Higher resolution helps the model read small text and see small objects, but the number of patches grows with the square of the side length. Merging neighboring patches before they enter the language model reduces the count. SmolVLM2 uses both. Its SigLIP encoder takes 512×512512 \times 512 inputs with 16×1616 \times 16 patches, giving 32×32=102432 \times 32 = 1024 patch features. The connector merges each 4×44 \times 4 block of features into one vector (pixel shuffle) and projects it, so a 512×512512 \times 512 input becomes 64 tokens. The processor first resizes every image so that its longer side is longest_edge pixels, 2048 by default, then cuts it into 512×512512 \times 512 tiles. Each tile becomes 64 tokens, and a downscaled copy of the whole image adds 64 more, so that the model sees both the detail and the overall layout. The size of the original image therefore does not matter; the setting longest_edge does. The cell builds the same prompt for one photo at four values of longest_edge, and once with splitting turned off, counts the <image> tokens in the input, and times the prefill: the forward pass over the prompt that has to finish before the first answer token appears.
The number of image tokens follows the tile grid. At longest_edge = 512 the whole photo fits in one tile and becomes 64 tokens. At 1024 the 640×427640 \times 427 photo is resized to 1024×6831024 \times 683 pixels and cut into 2×22 \times 2 tiles, which with the global view gives 5×64=3205 \times 64 = 320 tokens. At 1536 it is 3×23 \times 2 tiles and 448 tokens, and at the default of 2048 it is 4×34 \times 3 tiles and 832 tokens, about ten times the length of the text of the prompt. With splitting turned off, only the downscaled whole image is kept, 64 tokens. The prefill time grows much less than the token count, from 30 ms to 42.5 ms, because one short prompt on a large GPU leaves most of the GPU idle. With batches of images, longer conversations or a smaller GPU, the extra tokens cost proportionally more time and memory.

Scoring answers

A model answers in free text, and the score depends on how that text is compared with the reference. Three methods are common. Exact match compares the answer, after lower-casing and removing punctuation and articles, with the reference. It is strict: “two dogs” against the reference “2” counts as wrong. The VQA benchmarks soften it by collecting ten human answers per question and giving full credit when at least three annotators gave the model’s answer, acc=min⁡(#matching humans/3, 1)\text{acc} = \min(\#\text{matching humans}/3,\ 1). Benchmarks with multiple-choice questions, such as MMBench and MMMU, avoid the problem by asking for a letter. For open answers such as descriptions, a second, larger model can act as a judge and grade the answer against the reference. This scales, but the judge has its own errors and biases, and its scores are only comparable when the same judge and prompt are used. The training loss is not one of these measures. The SmolVLM lab reached 98% token accuracy on its validation set, because most tokens of each answer are the fixed JSON field names, which says little about whether the listed food items are right. Assignment 3 measures normalized exact match per question and classifies each failure, which is the kind of measurement the loss cannot replace.

Object hallucination

A vision language model hallucinates an object when it describes or confirms an object that is not in the image. The language model has learned which objects usually appear together, and that prior can outweigh the visual evidence: a model shown a dining table may report a fork because tables usually have forks. POPE (Polling-based Object Probing Evaluation) measures this with yes/no questions of the form Is there a \{object\} in the image? on COCO photos (arXiv:2305.10355). Half of the questions name an object that is in the image, and the answer is “yes”. The other half name an absent object, chosen in three ways, which gives three test sets of 3,000 questions each:
  • random: any COCO object category that is not in the image;
  • popular: the categories that appear most often in COCO overall;
  • adversarial: the categories that most often appear together with the objects that are in the image.
The adversarial set tests the language prior directly. If the model answers from co-occurrence instead of from the image, it fails most there. Besides accuracy, POPE reports precision, recall and F1 with “yes” as the positive class, and the fraction of “yes” answers. A model that is biased toward agreeing answers “yes” more than half of the time. The cell asks SmolVLM2 the first 500 questions of each set, with ” Answer yes or no.” appended, and reads the first word of the answer.
Output from cell 6 SmolVLM2-500M answers “yes” to 93% of the random questions and to 96% of the popular and adversarial ones. Its recall is therefore almost perfect (0.99): it rarely denies an object that is there. Its precision is barely above the 0.5 of a coin flip, so a “yes” carries almost no information, and the accuracy stays between 53% and 56%. The parsing is not the cause. The raw answers above show the model writing “Yes.” for the backpack, the car and the dog that are not in the photo, and batched generation agrees with one question at a time on 31 of 32 questions. In the figure, the model confirms a car and a backpack on a photo of a snowboarder alone on an empty slope. With a bias this strong, the three sets barely differ: accuracy drops from 56.2% on the random set to 52.8% on the other two, because the model says “yes” to almost everything regardless of which object is asked about. A model that always agrees would score 50% on every set. POPE is most informative for models whose “yes” ratio is near one half, where the gap between the random and the adversarial set measures how much the answers depend on the language prior.

Exercises

  1. Repeat the POPE measurement with SmolVLM2-256M and with the model you fine-tuned in the SmolVLM lab. Does fine-tuning on food photos change the hallucination rate on COCO?
  2. Run POPE with image splitting turned off. Does the lower number of image tokens change the accuracy on any of the three sets?
  3. Change the question to Is there a \{object\} in the image? Answer yes only if you are sure. How do precision, recall and the yes ratio move?
  4. Write a scorer for the food extraction task of the SmolVLM lab that reports, per image, whether the JSON parses, and the precision and recall of the listed food items against the label.

Key references

Li et al. introduced POPE and showed that object hallucination in vision language models follows the co-occurrence statistics of their training data (arXiv:2305.10355). Liu et al. describe the LLaVA-1.5 connector and its 576 visual tokens (Liu et al., 2023).

References

  • Liu, H., Li, C., Li, Y., Lee, Y. (2023). Improved baselines with visual instruction tuning. arXiv [cs.CV].

Found an error on this page? Report an issue.