Lightweight Multimodal Models: Visual Encoding Architecture and Advantages

    This article examines how lightweight multimodal models integrate visual encoding natively into the model backbone, control visual token budgets, and use a compact ViT design to balance multimodal performance with inference efficiency. It covers image preprocessing, ViT architecture parameters, the forward pass, and cloud deployment considerations, providing developers with technical insight into the visual encoding module and its engineering implications.

    In the ongoing shift of large language models toward multimodality, visual encoding serves as the bridge between images, video, and language reasoning. The quality of its architecture directly determines the model’s overall performance and inference efficiency. Recently, a series of lightweight flagship multimodal models have emerged. While maintaining strong language capabilities, they achieve a balance between performance and resource consumption through refined visual module design. This article uses the visual encoding module of a class of lightweight multimodal models as an example to analyze its architecture design, image processing mechanism, and forward pass in depth, offering developers technical insight.

    1. Native Visual Integration: Expanding the Boundaries of Multimodal Applications

    Traditional multimodal processing often treats the visual module as an independent add-on component used only for basic image parsing. Modern lightweight flagship models, however, explicitly take the architectural position that visual encoding is not merely about processing images; it extends the boundaries of what the encoding capability can reach. Visual capabilities therefore need to be natively integrated into the model backbone.

    This native integration gives the model dynamic decision-making ability. The model can decide on its own “when to perform visual observation” and use visual feedback to guide subsequent language generation and action planning. This mechanism allows the model to invoke visual information more naturally when handling complex image-text interleaved tasks, code review, or multi-step reasoning, rather than mechanically processing the entire image on every inference pass.

    2. Image Preprocessing and Token Budget Control

    Before an image is sent to the vision Transformer (ViT), it must be standardized to meet the model’s input tensor requirements. Taking a common industry implementation as an example, the image processing flow includes the following core steps:

    1. Size adjustment and padding: The original image is first resized to an appropriate size and then zero-padded to align to a multiple of 28. This design is not arbitrary; it is tightly coupled with the subsequent patch-splitting mechanism. Because the model later performs a 2x2 merge and the base patch size is 14, 28 is exactly 14 (patch size) multiplied by 2 (merge factor), ensuring perfect division of the pixel matrix.
    2. Patch splitting and spatial merging: The image is split into base patches of 14x14 pixels. The model then performs a 2x2 merge, combining four adjacent base patches into a new unit. This step substantially reduces the computational complexity of subsequent Transformer layers.
    3. Token budget control: After the operations above, each 28x28 pixel region corresponds to one visual token. To adapt to context window limits in different scenarios, the model supports controlling the number of tokens generated per image by setting minimum and maximum visual token counts (the default range is usually between 16 and 8,000). This dynamic budget control keeps computation feasible for high-resolution images while saving inference resources for lower-resolution requirements.

    3. Lightweight ViT Architecture Design Analysis

    This class of models pursues extreme lightness and efficiency in the visual backbone design. The core parameters of its ViT architecture are as follows:

    • Network depth: 24 layers
    • Hidden dimension: 1024
    • Number of attention heads: 16
    • Head dimension: 64 (i.e., 1024 / 16; grouped-query attention, GQA, is not used)
    • Patch size and merge factor: 14 / 2x2
    • Output dimension: 4096 (aligned with the hidden dimension of the underlying LLM)

    In terms of parameter scale, the visual backbone has only about 0.56B parameters, accounting for less than 1% of the entire multimodal model. This extremely lightweight design means that at inference time, the vast majority of compute and memory can be allocated to the language model. In addition, for inference precision, the visual module consistently uses BF16 (Bfloat16) precision and does not follow an FP8 quantization path. This is mainly to ensure numerical stability in visual feature extraction and to avoid small quantization losses being amplified during multimodal fusion.

    4. In-Depth Analysis of the Forward Pass

    To understand the extraction and transformation of visual features more intuitively, we can analyze the underlying forward pass logic. In the implementation of an open-source inference framework, the core code logic typically follows these steps:

    1. def forward(self, hidden_states, grid_thw, **kwargs):
    2. # ① Get visual position IDs and attention sequence lengths
    3. position_ids = get_vision_position_ids(grid_thw, self.spatial_merge_size, ...)
    4. cu_seqlens, max_seqlen = get_vision_attention_seqlens(grid_thw, self.config, ...)
    5. # ② Patch embedding and rotary position encoding
    6. hidden_states = self.patch_embed(hidden_states) # Conv3d patch embedding
    7. position_embeddings = self.rotary_pos_emb(hidden_states, position_ids) # axial RoPE
    8. # ③ Multi-layer Transformer Block processing
    9. for blk in self.blocks: # 24 x Block
    10. hidden_states = blk(hidden_states, cu_seqlens=cu_seqlens, ...)
    11. # ④ Final LayerNorm
    12. hidden_states = self.post_layernorm(hidden_states)
    13. # ⑤ 2x2 spatial rearrangement and downsampling
    14. hidden_states = hidden_states.view(-1, 2, 2, C)
    15. hidden_states = hidden_states.permute(0, 3, 1, 2)
    16. hidden_states = self.downsample(hidden_states).view(-1, out_hidden) # Conv2d downsampling
    17. # ⑥ SwiGLU projection fusion
    18. merged = self.merger(hidden_states)
    19. return merged

    Flow analysis: First, the model generates multi-dimensional position IDs and cumulative sequence lengths based on the input image grid information to support batched processing of variable-length images. Next, it performs patch embedding through Conv3d and applies axial rotary position encoding to preserve the spatial relative position relationships of the image. The features then pass through 24 Transformer blocks for deep feature extraction. After the final LayerNorm, the model performs the most critical spatial rearrangement operation: it reshapes the feature matrix to (-1, 2, 2, C), then applies dimension transposition and Conv2d downsampling to physically merge 2x2 feature maps. Finally, SwiGLU activation is used for projection, mapping the visual features into a 4096-dimensional space aligned with the language model.

    5. Cloud Deployment and Engineering Practice

    For enterprise applications, this lightweight visual encoding module has significant advantages when deployed in the cloud. Because its parameter count is very small and its structure is fixed, developers can use container platforms to package it as an independent backend service. When building multimodal applications, images and videos uploaded by the frontend can be persisted through object storage, which then triggers the inference service inside the container.

    At the same time, thanks to its token budget control mechanism, the server can dynamically adjust the resolution and token upper limit of received images based on the current compute load of the cloud instance (observed in real time through logging and monitoring alerts), thereby shaving peaks and filling valleys in compute resource usage. This approach, combining a lightweight ViT with a cloud-native architecture, can effectively reduce response latency and operational costs in real-world deployment of multimodal large models, providing solid technical support for scenarios such as intelligent coding tools and image-text moderation.