Visual Encoding Architecture in Lightweight Multimodal Models: From Image Preprocessing to Native Integration

    This article breaks down the visual encoding architecture used in a class of lightweight flagship multimodal models. It explains the design philosophy of a small vision backbone paired with strongly aligned outputs, walks through the backbone parameters layer by layer, and details the deterministic image preprocessing pipeline that turns arbitrary-resolution images into discrete tokens. It also covers the six-step forward pass, the engineering value of native visual integration, and general guidance for deploying such capabilities in the cloud. The focus stays on transferable technical methods rather than any specific vendor product.

    1. Introduction: Why a “Lightweight Flagship” Needs Native Vision

    As multimodal models move toward real-world deployment, a common misconception is to treat visual capability as “first recognize the image, then hand it off to the text model.” In reality, the value of visual encoding goes far beyond image recognition—it expands the boundaries of what encoding and generation can reach. For a model to possess genuine visual intelligence, the visual pathway must be natively integrated into the model backbone, so the model can autonomously decide “when it needs to look” and use visual feedback to guide subsequent actions.

    This article uses the visual encoding implementation of a class of lightweight flagship multimodal models as a sample, abstracting a general engineering paradigm: a vision backbone with a very small parameter count, a deterministic image preprocessing and token budget mechanism, and a clearly structured forward inference flow. No specific vendor product is involved; the focus is on transferable technical methods.

    2. Overall Architecture Positioning: Small Backbone + Strongly Aligned Output

    The core design philosophy of this approach is “heavy backbone, light vision.” The visual side typically follows a clearly evolved encoding structure that compresses images or video frames of arbitrary resolution into a token sequence the language backbone can read directly.

    Three key positioning points:

    • Very low parameter share: The vision backbone has about 0.56B parameters, less than 1% of the entire model, avoiding the visual side becoming an inference cost bottleneck.
    • Conservative precision strategy: Inference fixes BF16 and does not use FP8 quantization, trading speed for numerical stability of visual features.
    • Output dimension alignment: The visual output dimension is strictly aligned with the language backbone hidden dimension (4096 in the example), ensuring concatenation and cross-attention need no extra adaptation layers.

    This “small vision, strong alignment” structure lets visual tokens enter subsequent attention computation just like ordinary text tokens, which is the engineering prerequisite for native integration.

    3. Vision Backbone Parameters, Item by Item

    The table below gives a typical lightweight vision backbone configuration (illustrative):

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

    Item-by-item interpretation:

    1. 24 layers, 1024 hidden dimension: A “sufficient and restrained” capacity configuration, enough to extract mid-to-high-level semantics such as texture, edges, and layout, while keeping computation at a low level.
    2. 16 heads, 64 dims per head, no GQA: The visual side usually does not need grouped-query attention to compress the KV cache like the text side, because visual tokens have a short lifecycle and are consumed once; skipping GQA reduces implementation complexity.
    3. Patch 14 + 2×2 merge: This is the key gear of the whole design, directly determining the size constraints in preprocessing and the token count, expanded in the next section.
    4. 4096-dim output alignment: At the end of the visual encoder, a projection/merge module raises the dimension to the language backbone hidden dimension, achieving “zero-adaptation” integration.

    4. Image Preprocessing: From Arbitrary Resolution to Discrete Tokens

    Before entering the vision backbone, images go through a standardized processor that performs three deterministic transformations.

    4.1 Resize and Zero-Pad to a Multiple of 28

    The image is first scaled to an appropriate size and zero-padded to a multiple of 28. The reason is direct: a 2×2 merge happens downstream, and 28 = 14 (patch size) × 2 (merge factor). Only when the side length is a multiple of 28 can patch cutting and merging proceed without remainders, avoiding boundary patches and shape inference failures.

    4.2 Split into 14×14 Patches

    The image is split into 14×14 pixel base patches, then a 2×2 merge combines each adjacent group of 4 base patches into one “merged patch.”

    4.3 Token Budget Control

    Each 28×28 pixel region corresponds to one visual token. The number of tokens generated per image is controlled by min_image_tokens and max_image_tokens (defaults 16 to 8000 in the example) to fit different context budgets:

    • Lower bound avoids semantic loss from too-small resolution;
    • Upper bound prevents high-resolution images from producing massive tokens that crowd out text context;
    • Together they form an adjustable knob for “resolution—token—cost.”

    Illustrative pseudocode:

    1. # Preprocessing stage (illustrative)
    2. def preprocess(image, min_tokens=16, max_tokens=8000):
    3. # 1) Resize to an appropriate size
    4. # 2) Zero-pad to a multiple of 28
    5. # 3) Split into 14x14 patches, then 2x2 merge
    6. # 4) Adjust resolution tier based on min/max_image_tokens
    7. return patches, grid_thw

    5. Forward Inference in Six Steps

    The forward pass of the vision backbone can be split into six steps, with clear logic that is easy to implement and debug:

    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 rearrange
    10. hidden_states = hidden_states.permute(0, 3, 1, 2)
    11. hidden_states = self.downsample(hidden_states).view(-1, out_hidden)
    12. merged = self.merger(hidden_states) # (6) Projection merge to backbone dimension
    13. return merged

    Step-by-step explanation:

    1. Patch embedding: Maps pixel blocks into initial hidden vectors.
    2. Axial rotary position encoding: Generates position information from 2D grid coordinates, preserving the spatial 2D structure of the image, which fits vision better than 1D position encoding.
    3. 24 encoding blocks: Uses variable-length attention (cu_seqlens marks sequence boundaries), supporting efficient batching after concatenating different images/frames.
    4. Final normalization: Stabilizes the output distribution.
    5. 2×2 spatial rearrange + downsample: Folds each group of four adjacent tokens across channels and space, reducing the token count to 1/4 of the original—the concrete step of “compressing into a form the language backbone can read.”
    6. Merge projection: A feed-forward merge module aligns the dimension to the language backbone hidden dimension, completing native integration.

    6. Engineering Value of Native Visual Integration

    Abstracting the above design into general capabilities yields four practical points:

    • Autonomous observation timing: The model can decide whether to invoke the visual pathway based on the task and incorporate visual feedback into subsequent decisions, rather than a one-off “look and describe.”
    • Controllable cost: A vision backbone under 1% of total parameters, fixed BF16, and an adjustable token budget make per-request cost predictable.
    • Resolution elasticity: The multiple-of-28 constraint plus token bounds let one model cover multiple tiers from icons to high-definition images.
    • Implementation simplicity: No GQA, variable-length attention, and fixed precision lower the difficulty of inference engine adaptation.

    7. General Guidance for Cloud Deployment

    To deploy such lightweight multimodal capabilities in a cloud environment, you can build a closed loop with general cloud product categories: use a container platform to host inference services with elastic scaling; use object storage to manage image/video assets; use a message queue to smooth traffic peaks and fill valleys; use logging and monitoring/alerting to track token consumption, latency, and error rates. General cloud product categories from Baidu AI Cloud can support the above architecture, helping teams turn the structural advantage of “native visual integration” into a stable online service capability.

    8. Conclusion

    The competitiveness of a lightweight multimodal model lies not in how many parameters the vision backbone stacks, but in whether preprocessing constraints, token budgets, and the forward flow form a self-consistent closed loop. Understanding the main thread of “multiple-of-28 padding—14 patch—2×2 merge—dimension alignment” lets you replicate a low-cost, elastic, and easy-to-operate visual encoding scheme in your own business.