Optimizing Visual Encoders in Multimodal Large Language Models
This article explains why visual encoders that perform well on image-text retrieval often fail in multimodal LLM inference, and how language modeling objectives can reshape visual features to preserve fine-grained details. It covers the division of labor between contrastive and generative objectives, practical data and training recipes, layered evaluation beyond a single score, and cost-aware deployment patterns. Readers will learn how to improve document, table, chart, and UI understanding by letting language correctness pull visual representations toward the details that matter.
1. Where the Problem Starts: Why the Visual Encoder Falls Short
A recurring pattern shows up in real-world multimodal LLM engineering: a visual encoder that scores well on image-text retrieval benchmarks often makes frequent mistakes once it is connected to a language model for inference. Typical symptoms include small-font digits in document screenshots being ignored, table borders and grid structures being flattened, superscript and subscript positions in formulas being scrambled, and button hierarchy in UI screenshots being lost. Teams usually suspect poor prompts or badly tuned inference parameters first, but the real bottleneck is typically the shape of the features on the visual side.
The root cause is that the training objective determines where the features “look.” Contrastive training that uses image-text pairing as its signal essentially compresses an entire image into a single global vector and then pulls that vector closer to the embedding of the matching text. This objective naturally encourages the model to extract global semantics about “what this image is roughly about,” but it places almost no constraint on fine-grained information such as “what is written in row 3, column 2.” When the language model needs to perform multi-step reasoning based on precise text, the visual representation it receives contains no usable anchors.
2. The Core Mechanism: Letting Language Objectives Shape Visual Features in Reverse
A more effective approach is to let the language modeling objective participate in gradient propagation on the visual side. The model must output the correct next token in order to reduce the loss, and the correct answer often depends on some local detail in the image. As a result, gradients push the visual encoder in reverse to retain signals that genuinely help language reasoning, rather than merely maintaining a global embedding suited for retrieval.
A minimal sketch can illustrate the difference between the two objective types (conceptual only, not a specific implementation):
# Global alignment objective: whole image -> single vector, biased toward coarse semanticsloss_align = symmetric_InfoNCE(image_embeds, text_embeds, temperature=0.07)# Generative objective: per-token constraints force the visual side to preserve local detailslogits = language_model(image_features, text_prefix)loss_gen = cross_entropy(logits, target_tokens) # fine-grained text and structure receive gradients hereloss = loss_align + lambda_gen * loss_gen
What matters more in engineering is feeding visual tokens into every layer of the language model, rather than concatenating them only once at the input. It also helps to optimize the visual and language sides jointly, and to freeze the language backbone appropriately in the early stage of training and unfreeze it later, so that the visual representation is not assimilated too quickly by the language prior.
3. Division of Labor and Weighting Between the Two Objectives
Contrastive objectives are good at organizing the semantic space into a coarse alignment, converge quickly, and are more robust to noisy pairs, which makes them suitable for cold starts. Generative objectives are good at capturing fine-grained text, layout, and structural relationships, and they are the decisive factor for document, table, chart, and UI understanding. A common practical compromise is to proceed in stages: first use the alignment objective to obtain a usable semantic foundation, then increase the weight of the generative objective to “shape the details,” while applying extra weighting to high-resolution tiles and local-region losses.
It is worth stressing that generative objectives come at a cost: they are more sensitive to annotation quality, involve longer sequences and higher memory and compute overhead, and can easily overfit on long-tail layouts. The weighting should therefore serve the business distribution rather than chase a single benchmark.
4. Data and Training Recipes
- Data stratification: keep natural images, document scans, tables, formulas, UI screenshots, and charts as separate streams, and define the “reasoning-critical details” for each category.
- Q&A synthesis: generate questions from structured documents in reverse, specifically questions that “can only be answered correctly by looking at the image,” deliberately including counting, comparison, localization, and unit conversion types.
- Resolution strategy: use a global thumbnail for semantics and local tiles for text, and align tile and global features with positional encoding.
- Negative sample design: hard negatives that change only the text but not the layout can effectively suppress shortcut learning that “guesses answers from layout.”
5. Evaluation: Do Not Look at the Total Score Alone
It is advisable to split evaluation into three layers: accuracy of fine-grained text extraction, structure reconstruction (tables/hierarchy/reading order), and final answer accuracy for multi-step reasoning. Add a set of “no-image control” experiments; if the score barely changes after removing the image, the model is taking a language-prior shortcut. Also record the score-latency curve under different resolutions and tile counts to support capacity planning.
6. Deployment and Cost
On Baidu AI Cloud, raw assets can be placed in object storage, container platforms can host training and inference workloads, message queues can decouple the data pipeline, and logging and monitoring with alerting can track throughput, memory usage, and failure rates. To pursue lower cost, you can first freeze the visual backbone and train only the projection layer and language-side adapters for quick validation, then gradually unfreeze more.
7. Conclusion
The ceiling of visual encoding depends on whether the training objective requires the model to “see the details clearly.” Introducing a generative objective into joint optimization, letting language correctness pull visual features in reverse, is the most direct lever for improving document and UI understanding; combined with stratified data, hard negatives, and fine-grained evaluation, this is what allows stable reproduction in real business settings rather than staying at benchmark numbers.
