Deploying a Multimodal LLM on Four Heterogeneous GPUs with llama.cpp: VRAM Budgeting, Quantization, and Layer Splitting

    This article documents a practical deployment of a multimodal large model across four 32GB heterogeneous GPUs using a llama.cpp-family GGUF workflow. It covers VRAM budgeting, 2-bit dynamic quantization, feature-branch selection, mmproj matching, layer splitting, launch flags, initial test observations, limitations, and troubleshooting.

    1. Estimate the VRAM Budget Before Deciding Whether Deployment Is Feasible

    Before deployment, estimate whether the model can fit. In this run, the main model weights after 2-bit dynamic quantization were about 108.7GB, and the multimodal projection file was about 1.13GB, for a total of about 109.83GB. Four 32GB cards provide 128GB in total, leaving about 18.17GB. If split evenly by layer, each card would carry about 27.46GB of weights, leaving about 4.5GB per card.

    This remaining headroom must also cover KV cache, activation tensors, intermediate results from image encoding, and fixed overhead from drivers and runtime. The KV cache size can be estimated as follows:

    KV cache bytes = 2 × number of layers × number of KV heads × head dimension × context length × bytes per element

    The longer the context, the larger the KV cache. A high-resolution image is split into many visual tokens, which also consume context length. Therefore, weights fitting into VRAM does not mean inference will run successfully. Before deployment, calculate the headroom for the target context length and observe VRAM peaks under real workloads.

    2. Choosing the Inference Framework and Branch

    A C++ inference framework has strong cross-platform capabilities and is suitable for heterogeneous hardware. This article uses a llama.cpp-family framework as an example;这类 projects store models in GGUF format. For the latest native multimodal architectures, the main branch often does not yet provide full support. A common symptom is a shape mismatch or missing operator at load time. In that case, a feature branch separately maintained by the community for the new architecture is usually required.

    When choosing a branch, follow these steps:

    1. Record the branch name and commit hash, not just the branch name, because branches change continuously.
    2. Read the known issues list for that branch and confirm whether the compute backend for the target hardware is supported.
    3. Keep a previously compiled working build as a fallback so you can determine whether the problem comes from the model file or from the branch code.
    4. First validate loading with text-only input, and add image input only after that is confirmed working.

    Feature branches are less stable. Rerun the basic tests after every update.

    3. Compression Effect of 2-Bit Dynamic Quantization

    The original model has about 320B parameters. Stored in FP16, the weights would be about 640GB. After dynamic quantization, the main model file was about 108.7GB, averaging about 2.72 bits per parameter (108.7 × 8 ÷ 320 ≈ 2.72). This average is above 2 bits because important layers retain higher precision while redundant layers use extremely low bit width.

    When reproducing the setup, record the following information:

    • The quantization tool and its version number;
    • The source and size of the calibration data;
    • Whether the vision tower and embedding layers were quantized;
    • The actual byte size of the output file, which can be checked with ls -lh or du -sh.

    Quantization introduces accuracy loss. To judge the loss on text tasks and image-text understanding tasks, compare against an FP16 or higher-bit version using the same test set.

    4. Loading the Multimodal Projection Module

    A multimodal model requires two files: the main model weights and the multimodal projection module (mmproj). The main model handles language understanding and text generation. The mmproj maps features from the visual encoder into the embedding space recognized by the main model.

    In this run, the mmproj was kept at FP16 precision and was about 1.13GB. It must strictly match the main model. When versions do not match, common symptoms are a dimension mismatch at load time or clearly abnormal output after image input. Therefore, obtain both files from the same release and keep version information in the filenames.

    Below is a startup example:

    1. ./llama-server \
    2. -m ./model-2bit.gguf \
    3. --mmproj ./mmproj-f16.gguf \
    4. -c 8192 -ngl 999 -sm layer -ts 1,1,1,1 \
    5. --host 127.0.0.1 --port 8080

    Here, -c sets the context length, -ngl 999 means placing as many layers as possible on the GPU, -sm layer means splitting by layer across multiple cards, and -ts specifies the weight ratio for each card. Parameter names should be confirmed against the --help output of the branch in use. If the weights are split into multiple shard files, usually only the first shard needs to be specified.

    5. Four-Card Layer Splitting and Startup

    This run used layer splitting, assigning different layers of the model to four cards. During inference, data passes through the cards sequentially. This approach can hold very large models, but inter-card communication increases and inference speed decreases accordingly. Communication overhead depends on the hardware interconnect and the communication backend used.

    The -ts 1,1,1,1 example assumes that all four cards have the same available VRAM. If other processes occupy VRAM on a card, adjust the ratios according to the remaining VRAM on each card. Before startup, use the vendor-provided monitoring tool to confirm the free VRAM on each card.

    6. Test Results and Limitations

    In initial tests of text question answering and image-text understanding, the model produced coherent answers and was able to describe image content and reason with context. This conclusion is based on a small number of manual spot checks, without statistical metrics, and does not represent model performance in all scenarios.

    The current approach has the following limitations:

    • The feature branch used does not yet connect to the native video processing pipeline, and video input was not tested. Video processing requires frame-by-frame handling, higher VRAM bandwidth, and framework support for temporal attention.
    • The accuracy loss caused by quantization was not quantitatively evaluated.
    • Inter-card communication affects inference speed, and this article does not provide a specific tokens-per-second figure.

    7. Troubleshooting Common Issues

    • Shape mismatch or missing operator at load time: Check whether the branch supports the model architecture and verify the commit hash.
    • Out of memory (OOM) at startup: Lower the value of -c, reduce concurrent requests, or adjust the -ts ratios to balance the load more evenly.
    • Abnormal output after image input: Verify the versions of mmproj and the main model, and confirm that both come from the same release.
    • Inter-card communication timeout during inference: Check the inter-card connections and driver versions, and reduce the number of cards participating in parallelism for comparison.
    • Long first run: Weights must be read from disk into VRAM, which is normal. Time this separately from the inference stage.

    8. Applicable Boundaries

    This approach is suitable for local testing and research to validate model capabilities and deployment workflows. For services that require stable throughput, choose a configuration with more VRAM or switch to a model with fewer parameters. Before that, compare accuracy and speed using the same test set, then decide which approach to use.