Back to paper library
Paper notesarXiv 2023ECCV 2024

Vary

A Pair of Reading Glasses

Original paper

Vary: Scaling up the Vision Vocabulary for Large Vision-Language Models

Paper authors

Haoran Wei · Lingyu Kong · Jinyue Chen …

Show all 9 authors

Haoran Wei · Lingyu Kong · Jinyue Chen · Liang Zhao · Zheng Ge · Jinrong Yang · Jianjian Sun · Chunrui Han · Xiangyu Zhang

Publication
ECCV 2024Conference
First submitted to arXiv
arXiv:2312.06109
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{documentunderstandingvary2023,
  title = {{Vary: Scaling up the Vision Vocabulary for Large Vision-Language Models}},
  author = {Haoran Wei and Lingyu Kong and Jinyue Chen and Liang Zhao and Zheng Ge and Jinrong Yang and Jianjian Sun and Chunrui Han and Xiangyu Zhang},
  year = {2023},
  eprint = {2312.06109},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.06109}
}
On this page

At the time, getting a large vision-language model to copy out a screenshot of a paper page word for word was hard. It might recognize the big type of the title, but the small body text, tables, and formulas were hit or miss, and Chinese pages were harder still.

The models' language ability was fine; the problem was their “eyes.” In the large vision-language models (LVLMs) of the time, whether BLIP-2, MiniGPT-4, LLaVA, or Qwen-VL, the image encoder in front of the language model was almost always CLIP's ViT. CLIP was trained with contrastive learning on 400 million web image-caption pairs and is good at recognizing cats, dogs, and street scenes; but a page crammed with small text is like a foreign language to it.

Haoran Wei and colleagues at MEGVII compare this to a text vocabulary. When an English LLM learns Chinese, the first step is usually to extend the tokenizer's vocabulary; otherwise a single Chinese character gets split into several meaningless bytes. They argue the visual branch is the same: if CLIP's “vision vocabulary” isn't enough, add a new one. That is where this paper's Vary comes from.

Haoran Wei later went on to publish GOT as first author, as well as DeepSeek's DeepSeek-OCR and DeepSeek-OCR 2. Several designs in those OCR model notes on this site trace back to this paper.

Defining the Problem

First, take an LVLM apart. An image comes in, passes through a vision encoder to become a sequence of image tokens, then through an “input embedding layer” that projects it to the language model's dimension, and is concatenated with the text tokens and fed into the LLM.

The authors observe that the input embedding layers vary widely from model to model. BLIP-2 uses a Q-Former, Qwen-VL uses cross-attention, and LLaVA uses just a single linear layer. But the vision encoder itself is nearly always the same CLIP ViT. The authors call this encoder the LVLM's “vision vocabulary” and argue that it is the bottleneck.

Specifically, CLIP struggles with three kinds of input: high-resolution images, non-English text, and documents and charts. The input is shrunk to 224×224224 \times 224 and the output is fixed at 256 tokens, so a page dense with text is hard to fit into those 256 tokens; the authors even use the term “out-of-vocabulary.”

Then why not just unfreeze CLIP and keep training it on document data? That's what mPLUG-Owl and Qwen-VL do. The authors give three reasons against it:

  1. Further training may overwrite CLIP's original knowledge, washing out its ability to recognize cats and dogs.
  2. Updating the vision encoder together with a 7B LLM attached is very inefficient.
  3. LLMs memorize too well: after a few epochs on the same data they have it by heart, so the vision encoder can't learn properly just by “seeing it a few more times.”

So what the authors want is a new vision vocabulary. It specializes in documents and charts, can be trained without dragging along a 7B language model, and once trained is used alongside CLIP, with neither overwriting the other.

Solving the Problem

Original Figure 2: the top half is Vary-tiny. On the left, artificially made document and chart images pass through the trainable new vocabulary network (3×1024×1024 input, 256×1024 output) and a linear input embedding layer into a trainable OPT125M, which outputs dense OCR results for documents or a python dictionary for charts; above, a negative natural image takes the same path and outputs “This is an nature image.” The bottom half is Vary-base: natural images, documents, and charts go simultaneously into the frozen new vocabulary network (3×1024×1024) and the frozen original CLIP-L network (3×224×224), each through its own trainable linear input embedding layer, are concatenated into 256×4096, and go into a trainable 7B-LLM that converses following human prompts.
Original Figure 2, Wei et al., from PDF page 4, CC BY 4.0.

In the figure, flames mean trainable and snowflakes mean frozen. The method has two parts: the top half, Vary-tiny, “writes” the new vision vocabulary; the bottom half, Vary-base, combines the new vocabulary with CLIP into the LVLM actually put to use.

What the New Vocabulary Looks Like

The core of the new vocabulary network is a SAM-pretrained ViTDet image encoder, base size, with about 80 million parameters. The reason for choosing it is simple: SAM already takes high-resolution 1024×10241024 \times 1024 input, so it can see small text.

Original Figure 3: the structure of the new vision vocabulary network. A 1024×1024×3 input image enters the SAM-base image encoder, which outputs 64×64×256; Conv1 then turns it into 32×32×512, Conv2 into 16×16×1024, and finally it is flattened into 256×1024 image tokens.
Original Figure 3, Wei et al., from PDF page 5, CC BY 4.0.

Let's follow the shapes of one document page through it.

  1. The page is resized to 1024×1024×31024 \times 1024 \times 3.
  2. SAM-base has a stride of 16 and outputs a 64×64×25664 \times 64 \times 256 feature map, 4,096 positions in all.
  3. The first 3×33 \times 3 convolution halves the spatial size and doubles the channels, giving 32×32×51232 \times 32 \times 512.
  4. The second, with the same settings, gives 16×16×102416 \times 16 \times 1024.
  5. Flatten to 256×1024256 \times 1024.

That final shape is no coincidence. CLIP ViT-L/14 takes a 224×224224 \times 224 image cut into 14×1414 \times 14 patches, which also comes to exactly 16×16=25616 \times 16 = 256 tokens of 1024 dimensions each. The new network raises the resolution to 1024 and then uses two convolution layers to merge 4,096 positions back down to 256, so its output format is identical to CLIP's. The authors say these two convolution layers are a token merging unit that worked well in their experiments.

Note that both sets of 256 tokens divide the whole image into a 16×1616 \times 16 grid. The two tokens at the same position look at the same region of the page, one from a 224-pixel thumbnail and the other from the 1024-pixel original.

A Small Model “Writes” the Vocabulary

What the new network learns depends on what comes after it. CLIP is trained with contrastive learning, where the image vector only needs to match the caption as a whole; Vary switches to autoregression, attaching a very small language model, OPT-125M, after the network to write out the image's content word by word.

The authors argue autoregression suits dense text better, for two reasons. Next-token prediction lets the vision vocabulary compress longer text, since the image tokens must keep enough information for the decoder to restore the whole page word by word; and more data formats become usable, so question-answering data with prompts can be used for training too.

Vary-tiny's training data comes in three kinds:

  • Documents: English pages come from open-access arXiv papers and a large web PDF corpus, Chinese pages from e-books on the web. PyMuPDF extracts the text of each page while the page is converted to PNG, 1 million pages each for Chinese and English.
  • Charts: Chinese and English charts rendered with matplotlib and pyecharts, 250,000 of the former and 500,000 of the latter, with the ground truth written as Python dictionaries. Titles and axis text are sampled at random from a web corpus.
  • Negative samples: 120,000 natural images from COCO, whose answer is always one of five fixed sentences, such as “It's an image of nature.”

The negative samples are there for the later integration. The new vocabulary will eventually work alongside CLIP, and when it sees an ordinary photo, it shouldn't spit out a pile of OCR-like noise; so the authors simply teach it to say “This is a natural image” whenever it sees one, and leave the job to CLIP.

All of Vary-tiny's parameters are trained together, with a batch size of 512, for 3 epochs. Once training is done, OPT-125M retires with its work complete, leaving only the new vocabulary network.

Two Vocabularies Side by Side

Next comes Vary-base. The new vocabulary network sits side by side with the original CLIP-L, each followed by a linear layer that projects 1024 dimensions to 2048; the two are then concatenated along the channel dimension into 4096 dimensions, exactly the input width of Qwen-7B or Vicuna-7B.

One point that's easy to misread: after concatenation, there are still 256 tokens. The first 2048 dimensions of each token come from CLIP's thumbnail and the last 2048 from the new vocabulary network's high-resolution image; because the two grids are aligned, nothing ends up misplaced when they're joined. The language model's input doesn't get any longer for having an extra pair of eyes.

During training, both vision vocabularies are frozen, and only the two linear layers and the LLM are updated. The authors say this is closer to a pure language model pretraining setup, unlike LLaVA, which trains only the projection layer.

Vary-base's data also comes in two stages:

  • Pretraining: besides the document data above, tables, formulas, and plain text are extracted from arXiv LaTeX source files and re-rendered with pdflatex using a dozen or so templates, with the ground truth unified into Mathpix-style markdown: 500,000 English pages and 400,000 Chinese pages. For charts, the earlier ones generated from randomly sampled text had contents unrelated to one another, so this stage uses GPT-4 to generate charts with related content instead, rendering another 200,000. On top of that come 4 million general image-text pairs from LAION-COCO.
  • SFT: LLaVA-80k or LLaVA-CC665k, plus the DocVQA and ChartQA training sets.
Original Figure 4: samples of the synthetic data. On the left are synthetic documents, with three kinds of pages in Chinese and English: plain text, with formulas, and with tables. On the right are synthetic charts: pyecharts-style bar and rose charts and matplotlib-style pie and line charts, with titles and labels in both Chinese and English.
Original Figure 4, Wei et al., from PDF page 6, CC BY 4.0.

This synthetic data determines what Vary-base can do. Given the same document image, the prompt “Provide the OCR results of this image” makes it output plain text; “Convert the image to markdown format” makes it convert tables and formulas into markdown or LaTeX.

Discussion

Transcription Against Nougat

The first set of experiments uses a document test set the authors built themselves. The pure OCR part has 100 pages each in Chinese and English, sampled at random from arXiv and e-books; the markdown conversion part has 200 pages, 100 with tables and 100 with formulas. The comparison is Nougat, Meta's model built specifically for converting academic papers, and the metrics are normalized edit distance (ED; lower is better) and F1.

Pure OCR results (Table 1 of the paper):

ModelChinese EDChinese F1English EDEnglish F1
Nougat––0.12689.91
Vary-tiny0.26686.000.19784.25
Vary-base0.17487.320.10688.24

Markdown conversion results:

ModelFormula EDFormula F1Table EDTable F1
Nougat0.15483.970.33575.97
Vary-base0.08285.940.28076.26

A few things can be read from these two tables:

  1. Vary-tiny can transcribe with only OPT-125M. An edit distance of 0.266 for Chinese and 0.197 for English shows that the new vocabulary network really did squeeze the text on the page into 256 tokens. Its English precision is 89.38 but its recall only 79.67: it skips more than it gets wrong.
  2. On English pure OCR, Vary-base and Nougat each win one metric. Vary has the lower edit distance (0.106 vs. 0.126), Nougat the higher F1 (89.91 vs. 88.24); the authors call it “on-par.”
  3. Vary-base is better at markdown conversion, nearly halving the edit distance on formulas. The authors speculate this comes from the 7B language model's ability to correct text; Nougat's decoder is much smaller.
  4. Only Vary can do Chinese. Nougat has no Chinese capability, so that column has no competitor.

The limitation of these numbers lies in the test set itself. The authors sampled it from arXiv and e-books, and Vary's training data is precisely arXiv pages and web e-books; the test set has also never been released. Someone asked on GitHub at the end of 2023 whether the evaluation set and scripts would be released, and there has been no reply to this day.

Document and Chart Question Answering

The second set of experiments covers two public downstream tasks. DocVQA asks questions about document images and is measured with ANLS; ChartQA asks questions about charts and is measured with relaxed accuracy, which allows a 5% numerical error. At inference, a prompt is added asking the model to answer with a single word or phrase.

Vary-base (Qwen-7B, LLaVA-80k) has two numbers on DocVQA, 78.2 and 76.3; the test-set scores of the other methods in the table are 67.5 for Donut, 72.1 for Pix2Struct, and 65.1 for Qwen-VL.

On ChartQA the average is 65.3 (66.1 for the LLaVA-CC665k version), about the same as Qwen-VL's 65.7 and MatCha's 64.2. Broken down, Vary scores 43.2 on human-written questions, above MatCha's 38.2, and 87.3 on machine-generated ones, below MatCha's 90.2.

Two things to keep in mind when comparing. Vary-base's SFT data directly includes the DocVQA and ChartQA training sets, so it, too, was supervised fine-tuned on these two tasks. Donut and Pix2Struct are specialized models with a few hundred million parameters, while Vary-base has a 7B language model behind it; against Qwen-VL (65.1) and mPLUG-DocOwl (62.2), which also use 7B-class language models, it is still more than ten points higher on DocVQA.

Did General Ability Suffer?

One of the original goals of the whole design was to add the new vocabulary without hurting existing abilities. The authors check this with MM-Vet, a benchmark covering six capabilities: recognition, OCR, knowledge, generation, spatial awareness, and math.

With the same Vicuna-7B and the same LLaVA-CC665k fine-tuning, Vary-base scores 32.9 overall against LLaVA-1.5-7B's 30.5, 2.4 points higher; with Qwen-7B and LLaVA-80k fine-tuning, the total is 36.2. At least on this benchmark, the new vocabulary didn't drag general ability down.

What's Missing

The paper's biggest shortcoming is that none of its core claims gets an ablation.

For the claim that “CLIP is the bottleneck,” there's no control that uses CLIP alone, fine-tuned on the same data. How the new vocabulary network does on its own, whether the negative samples help, what happens if the two convolution layers are swapped for another merging scheme, the difference between freezing and unfreezing: the paper runs no experiments on any of these. The gains in the tables mix together the new vision vocabulary, over a million pages of synthetic data, a 7B language model, and the DocVQA training set, and their individual contributions can't be told apart.

Weights by Email

The code was released the day the paper went up; the weights weren't. The README's “Vary Weights” section says, “If you are in urgent need of weights for your research recently, please contact me by email,” and also, “We currently do not plan to open source the weights of the intermediate.”

What followed on GitHub was quite a sight. From December 2023 to April 2025, 33 issues piled up with titles like “请求分享权重” (please share the weights), “求权重” (weights, please), and “Vary weights download,” with people still asking as late as April 2025 (open-source weights, download method: email). The authors open-sourced Vary-tiny (the OPT-125M version) in March 2024; the Vary-base weights were never made public.

Training it yourself from scratch isn't easy either. At the end of March 2024, issue after issue reported that Vary-tiny wouldn't train from scratch with the official code. One user had trained on 300,000 samples and “got nothing out of it at all” (完全训不出任何东西); another said that whatever image went in, the output was always the same fixed, wrong text. The author replied that Vary was now maintained by the author alone, that the problem might be transformers' trainer failing to converge over multiple epochs under DeepSpeed, and suggested first loading the author's trained Vary-tiny and continuing from there. A month later, the author opened a separate repo with LAVIS-based Vary-tiny training code and the Vary-600k dataset, 300,000 pages each in Chinese and English; the paper used 2 million pages.

In July 2024, the README announced that the paper had been accepted and added, “To thank everyone for their attention, I will release a model that performs on par with the Vary-document soon.” What came out two months later was GOT-OCR2.0.

What Came After

GOT can be seen as an extension of Vary-tiny. Its encoder is likewise a SAM-base ViTDet architecture, with the last two layers following Vary's design to compress a 1024×10241024 \times 1024 input into 256×1024256 \times 1024 tokens; its first stage likewise attaches OPT-125M to practice transcription, and only the second stage switches to Qwen-0.5B. The authors removed both CLIP and the 7B language model, kept only the half that reads text, and turned it into a 580-million-parameter OCR model.

DeepSeek-OCR, for its part, classifies Vary as a “dual-tower” encoder design. It grants that this approach keeps parameters and memory reasonably under control, but the same image needs two sets of preprocessing, and pipeline parallelism is hard to do during training. DeepSeek-OCR's DeepEncoder chains the two in series instead: SAM first does cheap local attention at high resolution, and after compression, CLIP does global attention.

Conclusion

Vary's idea fits in one sentence: CLIP struggles with small print, so give it an extra pair of eyes made for reading text. These eyes are SAM-base plus two convolution layers. They first learn word-by-word transcription attached to a small 125-million-parameter model, then are frozen and placed next to CLIP, with the two sets of 256 tokens joined along the channel dimension, so the language model's input length stays the same.

As for evidence, on the authors' own test set Vary-base ties Nougat on English OCR, edges it out on markdown conversion, and has no competitor in Chinese; on DocVQA and ChartQA it is on par with the best general-purpose models of the time, and it doesn't regress on MM-Vet. What's missing is ablations: how much the new vocabulary actually contributes, the numbers in the tables can't say.

What this paper really left behind is the recipe of “training a high-resolution vision encoder through autoregressive transcription.” GOT trained it into a dedicated OCR model, DeepSeek-OCR turned the parallel arrangement into a serial one, and most document models since have had to face the same question: how many visual tokens does a page really need?

As for Vary-base itself, you still have to write in to ask for it.