Architecture Design and Performance Evaluation of Lightweight Vision-Language Models
This article examines the architecture of lightweight vision encoders in multimodal models, covering patch-based image processing, spatial merging, a typical 24-layer vision backbone, dynamic visual token budgets, and the forward computation pipeline. It also discusses inference precision, deployment considerations, and how lightweight designs balance visual accuracy, context length, latency, and cost.
1. The Core Value of a Lightweight Vision Encoder
In multimodal models, visual capability is not just about “recognizing what is in an image.” More importantly, the model should be able to actively inspect an image when needed, read local details, and use visual feedback to complete subsequent reasoning, generation, or operations. Therefore, the design goals of the vision module cannot be limited to improving classification accuracy. They must also address the following:
- Converting images into sequential information that a language model can understand;
- Controlling the number of visual tokens so that image information does not consume too much of the context window;
- Preserving spatial structure so the model can understand positions, layouts, and local relationships;
- Supporting images and videos of different resolutions;
- Balancing computational cost, memory usage, and visual accuracy.
A typical lightweight approach uses a medium-depth vision Transformer as the front end. The image is divided into base patches, spatial merging is applied to reduce sequence length, and the resulting visual features are projected into the hidden dimension of the language model. Compared with using a very large vision backbone directly, this design is better suited for real-time question answering, document parsing, image-based programming, and on-device inference.
2. From Arbitrary Resolutions to Visual Tokens
Input images come in different aspect ratios. Resizing every image to a fixed resolution creates two problems: targets are distorted by aspect-ratio changes, and fine details in high-resolution images are excessively compressed. In engineering practice, preprocessing therefore follows a “resize plus edge padding” workflow.
2.1 Resizing and Alignment
The input image is scaled according to a preset minimum and maximum visual token budget. After scaling, the image height and width usually need to be aligned to a specific stride — typically the product of the base patch size and the spatial merge factor.
Assume the base patch side length is 14 pixels and a 2×2 spatial merge is applied afterward. The final alignment unit is then:
14 × 2 = 28 pixels
As a result, the image width and height are adjusted or padded to integer multiples of 28. Padding regions are generally filled with zero values or boundary values so that subsequent convolutions and patch partitioning can run stably.
This is not a simple formatting requirement. It ensures that every region forms a complete 2×2 feature block during spatial merging, avoiding irregular tensors at the image edges.
2.2 Patch Partitioning
After preprocessing, the image is divided into 14×14-pixel base patches. Each patch represents a local region of the visual input and is mapped through a linear projection or convolution into an initial visual feature.
If the aligned image dimensions are:
Height = HWidth = W
then the approximate number of base patches is:
(H / 14) × (W / 14)
The vision Transformer builds relationships among these patches, allowing the model to understand both local textures and global structure.
2.3 2×2 Spatial Merging
When the number of base patches is large, the visual sequence grows rapidly. To reduce the computational burden on the downstream language model, the system merges every 4 adjacent patches — a 2×2 region — into one higher-dimensional visual unit.
After merging, each visual token corresponds to roughly a 28×28-pixel region of the original image. The direct effects are:
- The visual sequence length is reduced to one quarter of the original;
- Attention computation is significantly reduced;
- The basic spatial layout is preserved;
- It becomes easier to project visual features into the language model’s input space.
Note that spatial merging is not equivalent to simply discarding information. A common practice is to first concatenate the features of the 4 adjacent patches and then re-project them through a linear layer or MLP, letting the model learn how to compress local information.
3. A Typical Vision Backbone Architecture
A lightweight vision encoder can use a 24-layer vision Transformer as its backbone, with a typical configuration as follows:
| Configuration | Typical Setting |
|---|---|
| Network depth | 24 layers |
| Hidden dimension | 1024 |
| Attention heads | 16 |
| Per-head dimension | 64 |
| Base patch size | 14×14 |
| Spatial merge method | 2×2 |
| Output dimension | 4096 |
| Backbone parameters | ~560 million |
With a hidden dimension of 1024 and 16 attention heads, the dimension of each attention head is:
1024 / 16 = 64
This is a standard multi-head attention structure that does not rely on grouped-query attention. After processing by the vision encoder, features are projected to 4096 dimensions to align with the hidden states of the language model.
The vision backbone has about 560 million parameters, which typically accounts for only a small fraction of a complete multimodal system. This means most of the model’s parameters remain concentrated in the language reasoning module, while the vision component primarily handles “perception and compression.”
4. Dynamic Visual Token Budgets
Different images have very different resolution requirements. A casual scene photo may only need low resolution, while images containing small fonts, tables, or code screenshots need to retain much more detail. A fixed visual token count is therefore not reasonable.
A more flexible approach is to set a minimum and maximum token count per image, for example:
Minimum visual tokens: 16Maximum visual tokens: 8000
The actual token count is determined jointly by image dimensions, aspect ratio, and the budget limits.
4.1 Scenarios for a Low Token Budget
A lower visual token budget is suitable for:
- Coarse-grained image description;
- Scene classification;
- Simple object recognition;
- Fast image understanding in conversation;
- Online requests with strict latency requirements.
The advantages are low computation and fast response, but information loss may occur with fine text, complex tables, and dense layouts.
4.2 Scenarios for a High Token Budget
A higher budget is suitable for:
- Document and contract parsing;
- Code screenshot analysis;
- Table reading;
- UI interface understanding;
- Video keyframe analysis;
- Small object and local detail recognition.
The trade-off is a longer visual sequence, which increases attention computation, KV cache, and memory usage in the language model. In practice, deployment should apply a dynamic strategy based on business needs rather than blindly pursuing the highest resolution.
5. The Vision Forward Computation Pipeline
The forward pass of the vision encoder can be abstracted into the following steps:
def forward(pixel_values, grid_shape):position_ids = build_visual_position_ids(grid_shape,merge_factor=2)attention_info = build_attention_metadata(grid_shape)hidden_states = patch_embedding(pixel_values)hidden_states = add_position_information(hidden_states,position_ids)hidden_states = visual_transformer(hidden_states,attention_info)hidden_states = spatial_merge(hidden_states,merge_factor=2)hidden_states = project_to_language_space(hidden_states)return hidden_states
The code above represents generic computation logic. The core steps are:
5.1 Patch Embedding
The image first passes through a convolution or an equivalent patch projection layer, transforming pixel space into hidden feature space. For video input, the time dimension must also be handled so that the input tensor can represent multiple consecutive frames.
5.2 Visual Position Encoding
Visual tokens must carry not only content but also their two-dimensional positions. Otherwise, the model may know that “there is text in the image” without being able to determine which row of a table the text is in, or which area of the interface a button occupies.
Position encoding typically needs to reflect:
- Position along the height axis;
- Position along the width axis;
- Temporal position in video scenarios.
For video input, three-dimensional position indices can be constructed so the model can distinguish the same spatial region across different frames.
5.3 Visual Attention
The vision Transformer builds relationships among patches through multiple layers of self-attention. Shallow layers focus more on textures, edges, and local shapes, while deeper layers gradually learn object structure, layout relationships, and semantic information.
For mixed image and video inputs, the inference engine typically maintains sequence boundaries and the maximum sequence length for each sample, preventing invalid attention between different samples during batching.
5.4 Spatial Merging and Dimension Projection
After multi-layer visual modeling, adjacent patches are further merged. A projection layer then converts the visual hidden dimension to the language model’s input dimension — for example, from 1024 to 4096.
This step is critical. If the visual features do not match the language model’s hidden space, direct cross-modal fusion is impossible downstream.
6. Why a Lightweight Vision Module Still Works
A smaller parameter count in the vision encoder does not necessarily mean weaker visual capability. Its effectiveness also depends on training data, resolution strategy, language model capacity, and how well vision and language are aligned.
A lightweight design brings the following advantages:
6.1 Lower Inference Cost
The vision module is only a small part of the complete system, reducing overall memory and compute requirements. This advantage is especially pronounced for tasks that process multiple images or video frames simultaneously.
6.2 More Controllable Visual Sequences
Through patch merging and token budget control, the system avoids context explosion caused by high-resolution inputs, improving stability in long-text and multi-image scenarios.
6.3 Easier Deployment and Scaling
The vision encoder has a regular structure that adapts easily to different inference backends and can be deployed on container platforms, dedicated inference nodes, or edge devices.
6.4 Support for On-Demand Inspection
A multimodal model should not always process every image at the highest resolution. A more reasonable strategy is to browse at low cost first, then increase resolution or run additional visual analysis on suspected key regions — a “look first, then go deeper” working pattern.
7. Precision and Deployment Considerations
During inference, consistently using BF16 for the vision module is a sound engineering choice. Visual features are sensitive to numerical changes, especially in high-resolution images, fine text, and complex layout tasks, where aggressive quantization can cause information loss.
For deployment, pay close attention to the following:
- Peak memory: more visual tokens mean greater context and cache overhead in the language model;
- Batching strategy: when image sizes vary widely, uniform padding wastes computation;
- Video sampling: select keyframes based on the task rather than processing all frames indiscriminately;
- Tall or long images: webpage screenshots, tables, and code images should be prioritized for higher token budgets;
- Effects of edge padding: padded regions must not be misinterpreted as valid image content;
- Protection against abnormal inputs: limit the maximum resolution, maximum frame count, and total visual tokens per request.
8. Overall Assessment
The competitiveness of a lightweight vision-language model lies not only in parameter scale or individual benchmarks, but in the complete engineering loop: whether it can efficiently handle images of different sizes, dynamically balance detail and speed, stably connect visual features to language reasoning, and control memory and latency in real-world workloads.
A 24-layer vision backbone with about 560 million parameters, combined with 14×14 patches, 2×2 spatial merging, dynamic token budgets, and a 4096-dimensional cross-modal projection, represents a typical lightweight design path. It reduces system cost by compressing the visual sequence while preserving spatial structure and multi-scale input capability.
That said, the final performance of such architectures still depends on training data quality, vision-language alignment, resolution allocation strategy, and inference scheduling. For ordinary image question answering, a lower budget is sufficient; for document, code, table, and video understanding, more refined token configuration and stricter memory management are required. In other words, lightweighting is not simply about reducing parameters — it is a systematic design effort that balances perceptual accuracy, context length, inference speed, and deployment cost.
