How Lightweight Multimodal LLMs Encode Vision: Architecture, Token Budgets, and Engineering Practices

    This article breaks down how a lightweight flagship multimodal model implements visual encoding, using publicly available code and general engineering experience as a reference. It covers the overall division of labor between a small vision backbone and a large language backbone, image preprocessing from arbitrary resolutions into a regular token grid, the adjustable token budget, the six-step vision forward pass, and the resulting advantages in parameter efficiency, native integration, and numerical stability. Readers will find the key vision encoder parameters, the rationale behind patch size and 2x2 merging, and practical deployment recommendations for building high-quality multimodal applications under limited compute.

    1. Introduction: Why a “Lightweight Flagship” Rebuilds the Vision Path First

    In the capability landscape of multimodal large models, visual encoding is often the most underestimated component. Much of the attention goes to the parameter count of the language backbone, while a simple fact gets ignored: the vision-side design directly determines whether a model can see clearly, see accurately, and look at the right moment. What keeps a lightweight flagship model competitive under a limited parameter budget is not a larger language backbone, but a smarter vision path.

    One point emphasized repeatedly in the official technical blog is that visual programming capability is far more than “processing images.” It actually extends the boundary of what the encoding capability can reach. For a model to have this capability, vision must be integrated natively into the model, so that the model can decide on its own when to look and use visual feedback to guide subsequent actions. This captures the design philosophy of lightweight multimodal models: vision is not a bolt-on module, but a sensing organ deeply coupled with the reasoning flow.

    This article uses the visual encoding implementation of a lightweight flagship multimodal model as a reference blueprint, unfolding layer by layer from the overall architecture, preprocessing, token budget, and inference path to engineering practice. The implementation details discussed here come from public code and general engineering experience; they illustrate the technical principles and do not point to any specific third-party product.

    2. Overall Architecture: A Small Vision Backbone Paired with a Large Language Backbone

    The vision side of this model follows a clear line of evolution: from early image-text understanding models, to OCR-specialized models, to the current multimodal flagship version, the interface shape of the vision encoder has stayed consistent. This consistency carries great engineering value, because the inference framework does not have to rewrite the vision adaptation layer for every new model.

    The overall structure can be summarized as follows: a 24-layer ViT takes on the task of compressing an image or video of arbitrary resolution into a token sequence that the language model can read. It performs no semantic reasoning; it only translates the pixel world into a symbol sequence the language backbone can understand. The actual cross-modal reasoning happens after the visual tokens enter the language backbone.

    The key parameters of the vision encoder are as follows:

    Item Value
    Depth (number of layers) 24
    Hidden size 1024
    Attention heads 16
    Per-head dimension 64 (1024 / 16, no GQA)
    Patch size / merge factor 14 / 2x2
    Output dimension 4096 (aligned with the language backbone hidden size)
    Backbone parameters ~0.56 B

    Two design trade-offs here are worth noting. First, the attention head dimension is 64 and grouped-query attention is not used, which shows that the vision side values implementation simplicity and numerical stability over extreme KV-cache compression, because the lifetime of visual tokens is usually just one round. Second, the backbone has about 0.56 B parameters, less than 1% of the whole model, and runs in fixed BF16 during inference without FP8 quantization. This choice gives up a little memory footprint in exchange for deterministic visual numerical precision, avoiding the uncontrolled errors that low-bit quantization can introduce in high-frequency image details.

    3. Image Preprocessing: From Arbitrary Resolution to a Regular Token Grid

    Before entering the ViT, an image goes through a standardization step. The goal is to turn an input of “arbitrary size and arbitrary aspect ratio” into a regular tensor that the vision backbone can batch efficiently.

    3.1 Resizing and Zero Padding

    The image is first resized to a suitable size and zero-padded to a multiple of 28. The number 28 is not arbitrary: the patch size is 14, and there is a subsequent 2x2 merge, so 14 x 2 = 28. Therefore 28 is the pixel side length that corresponds to each visual token after merging. Zero padding keeps the grid aligned without introducing extra semantic information.

    3.2 Splitting and Merging

    The image is split into base patches of 14x14 pixels, followed by a 2x2 merge that combines 4 adjacent base patches into one unit. The essence of this step is spatial downsampling: it reduces the spatial resolution to half of the original while aggregating channel information, striking a balance between detail preservation and a controllable token count.

    3.3 Token Budget Control

    Each 28x28 pixel region corresponds to one visual token. The model controls the number of tokens produced by a single image through per-image token bounds (a default range of roughly 16 to 8000). This mechanism is key to putting multimodal systems into production: the same image can be given a higher budget in long-document understanding scenarios to preserve small-text details, or a lower budget in multi-turn conversation scenarios to save context window space.

    A simplified preprocessing sketch is shown below:

    1. # Pseudocode: illustrates the flow only, not a concrete API
    2. def preprocess(image, min_tokens=16, max_tokens=8000, patch=14, merge=2):
    3. unit = patch * merge # 28
    4. image = resize_and_zero_pad(image, multiple=unit)
    5. grid = image.shape[-2] // unit, image.shape[-1] // unit
    6. tokens = grid[0] * grid[1]
    7. tokens = clamp(tokens, min_tokens, max_tokens) # budget clipping
    8. patches = to_patches(image, patch_size=patch) # 14x14 base patches
    9. return merge_2x2(patches), grid, tokens

    4. Vision Backbone Forward Pass: Six Steps

    The forward pass of the vision model in the inference code can be abstracted into six steps, each corresponding to a clear engineering intent.

    1. def forward(self, hidden_states, grid_thw, **kwargs):
    2. position_ids = get_vision_position_ids(grid_thw, self.spatial_merge_size)
    3. cu_seqlens, max_seqlen = get_vision_attention_seqlens(grid_thw, self.config)
    4. hidden_states = self.patch_embed(hidden_states) # (1) patch embedding
    5. position_embeddings = self.rotary_pos_emb(hidden_states, position_ids) # (2) axial rotary position encoding
    6. for blk in self.blocks: # (3) 24 encoding blocks
    7. hidden_states = blk(hidden_states, cu_seqlens=cu_seqlens)
    8. hidden_states = self.post_layernorm(hidden_states) # (4) final normalization
    9. hidden_states = hidden_states.view(-1, 2, 2, C) # (5) 2x2 spatial rearrangement
    10. hidden_states = hidden_states.permute(0, 3, 1, 2)
    11. hidden_states = self.downsample(hidden_states).view(-1, out_hidden) # downsampling
    12. merged = self.merger(hidden_states) # (6) SwiGLU projection for alignment
    13. return merged

    (1) Patch embedding: a convolution maps pixel blocks into the hidden space, completing the first abstraction from “pixels to vectors.”

    (2) Axial rotary position encoding: rotary position encoding is applied separately along the row and column directions of the 2D grid, giving the model 2D spatial awareness while preserving the ability to extrapolate to relative positions.

    (3) 24 encoding blocks: a standard ViT structure that, together with the cumulative sequence length metadata required for variable-length attention, supports mixed-resolution samples within the same batch for both training and inference.

    (4) Final normalization: stabilizes the output distribution and prepares for the subsequent downsampling.

    (5) 2x2 spatial rearrangement and downsampling: the merged spatial blocks are compressed to the target dimension by a convolution, achieving a second aggregation of information.

    (6) SwiGLU projection: aligns the vision hidden dimension to the 4096 dimensions of the language backbone, completing the cross-modal “interface alignment.” This step is the key to seamlessly stitching vision and language together.

    5. Key Advantages

    First, extremely high parameter efficiency. A vision backbone of about 0.56 B accounts for less than 1%, which means the vast majority of the parameter budget is left for language reasoning and knowledge storage.

    Second, a highly flexible token budget. The adjustable range from 16 to 8000 lets the same model handle document-level high-resolution input while keeping overhead low in multi-turn interactions.

    Third, the “autonomous looking” capability that comes from native integration. Visual feedback can enter the reasoning loop, and the model can decide when to take another look and where to look, which is especially critical for tasks such as GUI operation, chart understanding, and video temporal understanding.

    Fourth, good engineering continuity. The vision encoder interface stays stable across generations of models, keeping the adaptation cost low for inference frameworks.

    Fifth, a robust numerical strategy. Fixed BF16 with no low-bit quantization avoids the precision loss of high-frequency visual details under quantization.

    6. Engineering Recommendations

    When deploying similar multimodal capabilities on Baidu AI Cloud, three points are worth attention. First, make image preprocessing and the token budget strategy configurable, tiered by business scenario. Second, deploy the vision encoding service and the language inference service separately, so they can scale independently. Third, combine common cloud product categories such as object storage, message queues, logging services, and monitoring and alerting to build a complete loop of input, inference, and observability. For high-resolution document scenarios, you can first split the layout, then encode block by block, and finally perform cross-block fusion, so as to retain key information within the context budget.

    7. Conclusion

    The competitiveness of a lightweight multimodal flagship model comes from the refined design of the vision path rather than from stacking parameters. Understanding the four stages of patch splitting, 2x2 merging, token budget, and cross-modal projection means grasping the core methodology for building high-quality multimodal applications under limited compute.