Guide to Local Deployment of Open-Source Multimodal LLMs: Architecture and Quantization Essentials

    Transitioning from API calls to deploying open-source multimodal large language models (LLMs) locally requires a deep understanding of model architecture, quantization, and resource estimation. This guide explores essential topics including Mixture of Experts (MoE) and vision fusion structures, mixed-precision quantization strategies, constructing multimodal inputs, production-grade inference engines, VRAM estimation formulas, and key metrics for cloud deployment.

    From API Calls to Local Control: What to Look For First

    In the past, developers could only access vision multimodal models through APIs without the ability to inspect their internal structures. With open weights, developers can now audit vision modules, perform quantization adaptation, modify inference frameworks, and integrate models into private agent workflows. These capabilities are highly valuable for scenarios where data cannot leave the local domain, customizations are required, or offline execution is mandatory.

    However, the ability to download model weights does not mean deployment is straightforward. Below, we will break down the model structure, storage and quantization, reference implementations, multimodal input construction, VRAM estimation, and cloud deployment. The specific numbers mentioned in this article are based on a public configuration; always refer to the official model card for actual usage.

    How MoE and Vision Fusion Architectures Work in Multimodal Models

    A common approach is to use a mature text-based LLM as the foundation, add a vision encoder and an alignment module (Aligner or Projector), and then continue training with image-text data. Taking a public configuration as an example, the language component consists of dozens of Transformer layers, including a large number of routed experts and a few shared experts. Each token is only computed by a select few experts (e.g., 6) chosen by a routing mechanism. Therefore, the total parameter count of the model can be much larger than the parameters actually involved in computation at each step.

    On the vision side, images are typically divided into fixed-size patches (e.g., 14x14). Features are extracted by the vision encoder and then mapped to the hidden dimensions of the language model by a projection module. The number of vision tokens generated by an image depends on the resolution and merging strategy, often numbering in the hundreds. Vision tokens occupy the context window, increase attention computation overhead, and expand the KV Cache. When processing high-resolution images, this overhead is often the primary reason for VRAM exceeding expectations.

    When evaluating inference resources, do not directly apply the active parameter count of the text-only version to the multimodal version. After adding vision modules and continuing training, the structure or effective computational load may have changed.

    How Much VRAM Can Mixed-Precision Quantization Save?

    FP16 takes 2 bytes per parameter, FP8 takes 1 byte, and FP4 takes 0.5 bytes. A rough estimate for weight VRAM is:

    Weight VRAM ≈ Parameter count × Bytes per parameter

    For a 100B parameter model, FP8 weights require about 100 GB, and FP4 weights require about 50 GB, neither of which includes other overheads. Using a public configuration as an example, its expert layers use FP4 while the remaining layers use FP8. Expert layers typically account for the majority of parameters, so prioritizing their compression yields the greatest benefits.

    Here, it is necessary to distinguish between two quantization methods. Native low-precision storage means the model is already released in a low-precision format, with weights trained or saved in that format. Post-training quantization refers to quantizing FP16 or BF16 weights after release. The precision loss and adaptation requirements of these two methods differ and should not be confused.

    A small file size does not mean it can run directly. Using a public configuration as an example, the total weight volume can reach hundreds of GBs, split into dozens of shard files. Loading requires sufficient system RAM and VRAM, and peak memory during the shard loading process may be higher than the final stable footprint. During inference, KV Cache, activations, and the framework’s own overhead will continue to consume resources.

    Before quantization adaptation, confirm the following checklist:

    • Operator support: Whether the target GPU and inference framework have corresponding FP4 or FP8 kernels.
    • De-quantization path: Whether certain layers fall back to BF16, and how much extra VRAM this fallback costs.
    • Precision regression: Comparing response quality before and after quantization using a fixed evaluation dataset.
    • VRAM and throughput: Comparing VRAM usage and output tokens per second before and after quantization under the same request batch.
    • Version consistency: Recording framework, CUDA, and driver versions to avoid irreproducible results due to environment changes.

    Can Reference Implementations Be Used Directly in Production?

    The code provided in the official repository is a readable reference implementation, including the vision encoder, attention mechanism, and forward computation path. It is suitable for understanding the model’s computation logic, validating input/output formats, and conducting small-scale experiments. It is not a production-grade inference engine.

    To support stable online services, the following capabilities are typically required:

    • Continuous batching: Dynamically merging computations for requests of different lengths.
    • Paged management and release strategies for KV Cache: Preventing long requests from permanently occupying VRAM.
    • Multi-GPU tensor parallelism or pipeline parallelism: Ensuring communication bandwidth meets demands.
    • Operator fusion and hardware-specific optimizations.
    • Health checks, timeout control, and request rate limiting.

    How to Correctly Construct Multimodal Inputs

    Constructing image-text inputs usually involves three steps:

    1. Encode the prompt using the text tokenizer to get text Token IDs.
    2. Process the image using the vision encoder and project it to the hidden dimensions of the language model to obtain vision embeddings.
    3. Place placeholder tokens in the input sequence, which are replaced by vision embeddings at the corresponding positions during the model’s forward computation.

    Below is simplified pseudocode illustrating the data structure:

    1. def build_multimodal_inputs(text_prompt, image_path):
    2. # 1. Text encoding
    3. text_ids = tokenizer.encode(text_prompt)
    4. # 2. Image encoding and projection to the language model's hidden dimension
    5. image_embeds = vision_encoder.encode_and_project(image_path) # shape: [num_img_tokens, hidden]
    6. num_img = image_embeds.shape[0]
    7. # 3. Place placeholders in input_ids instead of vision vectors
    8. input_ids = [BOS_ID] + [IMAGE_PLACEHOLDER_ID] * num_img + [SEP_ID] + text_ids
    9. # Modality mask: 0 for text, 1 for image
    10. modality_mask = [0] + [1] * num_img + [0] + [0] * len(text_ids)
    11. attention_mask = [1] * len(input_ids)
    12. return {
    13. "input_ids": input_ids,
    14. "attention_mask": attention_mask,
    15. "modality_mask": modality_mask,
    16. "image_embeds": image_embeds, # Passed separately, replacing placeholders at the embedding layer
    17. }

    During debugging, three points must be checked. First, the number of placeholders must exactly match the number of rows in the vision embeddings; otherwise, the replacement will fail or become misaligned. Second, the attention_mask must correspond to the actual valid tokens; when padding is used, padded positions should not be counted as valid lengths. Third, some models rely on modality types for positional encoding or attention rules, so the modality_mask must be handled strictly according to the official implementation.

    How to Estimate VRAM for Local Deployment?

    The rough formula for total VRAM is:

    Total VRAM ≈ Weight VRAM + KV Cache + Activations + Framework & Fragmentation Overhead

    The estimation formula for KV Cache is:

    KV Cache ≈ 2 × Number of layers × Number of KV heads × Head dimension × Sequence length × Concurrent requests × Bytes per element

    When using structures like GQA or MLA, the number of KV heads should be adjusted according to the actual configuration. Here is a hypothetical example: 48 layers, 8 KV heads, head dimension 128, sequence length 8192, 4 concurrent requests, BF16 (2 bytes). Plugging these into the formula gives approximately 6.4 GB. Long images directly extend the sequence, so the number of vision tokens simultaneously drives up the KV Cache.

    The estimation methods and troubleshooting points for each component are as follows:

    Component Estimation Method Common Troubleshooting Points
    Weights Parameter count × Bytes per parameter Whether vision encoder and projection layers are included
    KV Cache Calculate using the formula above Whether long images drive up sequence length; whether concurrency exceeds expectations
    Activations Correlates with batch size and sequence length Whether peaks occur during the prefill stage
    Framework Overhead Based on actual measurements CUDA context, communication buffers

    The estimated results serve only as a starting point. Final deployment should be based on actual measurement data on the target hardware.

    What Metrics to Monitor for Cloud Deployment?

    General cloud platforms can provide infrastructure support, with common practices including:

    • Object storage for weight shards: Focus on read bandwidth and load times during cold starts.
    • Container platforms for elastic scaling of inference nodes: GPU nodes start slowly, so scale-out thresholds should be set with a buffer.
    • Log services and monitoring alerts: Track key metrics in real time.

    It is recommended to monitor the following metrics:

    • GPU VRAM usage: Distinguishing between weight footprint and KV Cache footprint.
    • Prefix cache hit rate: Only tracked when the framework enables this feature.
    • Time To First Token (TTFT) and end-to-end latency.
    • Output tokens per second (throughput).
    • Error rate and timeout rate.

    The definition of the same metric may vary across different frameworks—for example, whether “KV Cache usage rate” is calculated by blocks or by bytes. Before going live, confirm the statistical caliber of each metric before setting alert thresholds.

    Pre-Deployment Checklist

    1. Confirm parameter scale, structural configuration, and quantization format from the official model card.
    2. Estimate weights and KV Cache using the VRAM formulas, and reserve margins for activations and framework overhead.
    3. Load the model on the target hardware and record peak VRAM and loading time.
    4. Perform regression comparisons on a fixed evaluation dataset before and after quantization.
    5. Validate multimodal input formats on the reference implementation before migrating to the production inference framework.
    6. Observe latency, throughput, and VRAM curves in a stress-testing environment to ensure stability before going live.