Practical Guide to Deploying a 320B Multimodal Model on Non-Mainstream GPUs
This guide provides a comprehensive walkthrough for deploying a 320B multimodal model locally on non-mainstream GPUs. It covers essential steps including VRAM calculation for weights, visual files, and KV Cache, the division of labor between the main model and multimodal projection files, framework selection for multi-GPU setups, key launch parameters, and a structured OOM troubleshooting checklist. Readers will also learn best practices for post-deployment verification and system rollback to ensure stable local inference.
1. Evaluating the Need for Local Deployment
Local deployment primarily solves three problems: keeping data on-device, reducing network latency, and enabling model fine-tuning or customization. If you only need occasional inference, official APIs are usually more convenient. Local deployment involves costs for hardware procurement or rental, driver maintenance, version updates, and troubleshooting.
The figures below come from a specific practice. When changing models or hardware, you need to recalculate using the same methods rather than directly applying these numbers.
2. Calculating VRAM Requirements
1. Weight Size
Model weight size can be estimated using the following formula:
Weight size ≈ Parameters × Bits per parameter ÷ 8
Taking a 320B parameter model as an example, here is a comparison of three approaches:
| Approach | Bits per Parameter | Weight Size | Description |
|---|---|---|---|
| FP16 | 16 | ~640GB | Cannot fit on four 32GB compute cards |
| Uniform 2-bit | 2 | ~80GB | Theoretical value; all layers compressed, resulting in significant quality loss |
| Dynamic Quantization | ~2.72 | 108.7GB | Retains higher precision for sensitive layers; average bit width > 2-bit |
This article uses dynamic quantization. The filename suffix indicates the specific bit width tier, which should be recorded alongside the model file and quantization tool versions for future reproducibility.
2. Visual Files and Available Margin
The mmproj file is stored in FP16, taking about 1.13GB. The main model and mmproj total approximately 109.8GB.
The nominal total capacity of four 32GB compute cards is 128GB. The actual available capacity is 119.4GB; the difference is usually VRAM reserved by the driver and runtime. Refer to the device’s built-in query tools for exact values.
Available margin: 119.4 − 109.8 ≈ 9.6GB. This space must accommodate KV Cache, intermediate activations, and load deviations between cards.
3. KV Cache
KV Cache usage can be estimated using the following formula:
KV Cache ≈ 2 × Number of layers × Number of KV heads × Dimension per head × Context length × Bytes per element × Number of parallel sequences
Here is a calculation using hypothetical parameters (not the actual configuration of the model in this article): 64 layers, 8 KV heads, 128 dimensions per head, FP16, 4096 context length, single sequence. Substituting these values:
2 × 64 × 8 × 128 × 4096 × 2 bytes = 1073741824 bytes ≈ 1GiB
The actual number of layers and heads should be read from the model configuration file. In Hugging Face format’s config.json, the corresponding fields are typically num_hidden_layers, num_key_value_heads, and head_dim; if head_dim is missing, divide hidden_size by num_attention_heads to get the dimension per head. GGUF files can also be inspected for similar metadata using the gguf-dump tool from gguf-py.
The number of parallel sequences linearly scales KV Cache. With the hypothetical parameters above, 4 parallel sequences take about 4GiB, nearly half the margin, leaving less room for activations. Ensure unit consistency: GiB and GB differ by about 7%; mixing them will skew margin estimates.
3. Division of Labor: Main Model and mmproj
Deploying a multimodal model requires two files working together.
The main model weights (in GGUF format) handle language understanding, reasoning, and text generation, forming the bulk of VRAM usage.
The multimodal projection file (mmproj) typically contains the vision encoder and projection layers. It encodes images or video frames into vectors and maps them into the embedding space that the main model can receive.
For pure text inference, you can omit loading the mmproj. When processing images, both files are indispensable. The mmproj version must match the main model. If they mismatch, common symptoms for image inputs include dimension errors or abnormal outputs.
It is recommended to use paired files from the same release source and record their checksums using sha256sum, verifying them before and after deployment. Higher image resolutions or video frame counts generate more visual tokens, which also consume context and activation space.
4. Framework Selection and Multi-GPU Environment
Taking the llama.cpp ecosystem as an example, multimodal support for new models usually appears first in community frontier branches, while the main branch may not have merged them yet. Frontier branch interfaces change frequently. When deploying, ensure the following:
- Pin the branch name and commit hash; record the full hash using
git rev-parse HEAD. - Record compilation options, including backend type (e.g., CUDA, HIP, Vulkan, based on the branch README switches) and compiler version.
- Record driver versions, runtime versions, and dependency library versions.
- Keep a verified build directory. If a new version causes issues, switch back to the old directory for rollback without needing to recompile and debug.
VRAM readings should use the device manufacturer’s tools. For NVIDIA devices, use the following command:
nvidia-smi --query-gpu=index,name,memory.total,memory.used,memory.free --format=csv
For AMD devices, use rocm-smi --showmeminfo vram. Use native tools for other manufacturers. It is recommended to read metrics before loading, after loading, and during prolonged inference, recording the peak for each card.
5. Key Launch Parameters
The table below uses llama.cpp parameter names as examples. Specific names and defaults depend on the --help output of the branch used.
| Parameter | Function | Adjustment Direction |
|---|---|---|
-m |
Specify main model GGUF file | Path must match the recorded file |
--mmproj |
Specify multimodal projection file | Must match main model version; omit for pure text |
-ngl / --n-gpu-layers |
Number of layers placed on GPU; a large value implies offloading as much as possible | Decrease if VRAM is insufficient; some layers fall back to CPU, slowing down |
-ts / --tensor-split |
Weight distribution ratio across cards, e.g., 1,1,1,1 | Adjust based on remaining VRAM if one card fills up first |
-sm / --split-mode |
Multi-GPU split mode, e.g., by layer or by row | Choose based on supported options in the branch; re-test after changing |
-mg / --main-gpu |
Main card index, handles some intermediate results and output | Choose a card with larger VRAM margin |
-c / --ctx-size |
Context length, determines KV Cache size | Prioritize reducing this if VRAM is tight |
-np / --parallel |
Number of parallel sequences, also scales KV Cache | Set to 1 for single-user scenarios |
-b / --batch-size |
Logical batch size, affects transient usage during prefill | Decrease if long prompts cause prefill OOM |
-ub / --ubatch-size |
Physical batch size, directly impacts activation peak | Decrease in conjunction with -b to lower peak |
-ctk / --cache-type-k |
KV Cache storage type, e.g., q8_0 | Reduces KV Cache usage, but output quality needs verification |
-fa / --flash-attn |
Enable fused attention implementation | Can reduce intermediate usage; availability depends on branch and backend |
6. OOM Troubleshooting Checklist
Troubleshoot in the following four layers sequentially. For each layer, confirm the symptom first, check metrics, then adjust one parameter and re-test. Change only one parameter at a time to identify what works.
Layer 1: Weight Loading
- Symptom: Model fails during loading, or process is terminated mid-load.
- Check Metric: Whether the sum of main model and mmproj file sizes exceeds the available capacity allocated to each card.
- Action: Decrease
-nglto keep some layers on the CPU; or use a lower bit-width quantized file; or adjust-tsto relieve the most loaded card.
Layer 2: KV Cache
- Symptom: Loading succeeds, but OOM occurs during long context or multiple sessions.
- Check Metric: The product of
-cand-np, and the estimated KV Cache size using the formula. - Action: Decrease
-c; set-npto 1; try-ctk q8_0after verifying output quality.
Layer 3: Activations
- Symptom: OOM during prefill phase with long prompt inputs, while generation phase is normal.
- Check Metric: Values of
-band-ub, and the input token count. - Action: Decrease
-ubfirst, then-b.
Layer 4: Inter-card Load Deviation
- Symptom: Total VRAM appears sufficient, but one specific card errors out first.
- Check Metric:
memory.usedof each card to compare for significant unevenness. - Action: Reset
-tsbased on the ratio of remaining VRAM across cards.
7. Post-Deployment Verification and Rollback
After deployment, it is recommended to complete the following checks:
- Test both pure text requests and image requests to confirm mmproj is loaded correctly.
- Conduct a stress test with input close to the target context length, recording the VRAM peak for each card.
- Save the launch command, branch hash, and version information used this time to form a reproducible configuration.
If a new version causes issues, switch back to the verified build directory and use the same launch command. This restores service in the shortest time possible, allowing you to troubleshoot the new version separately.
Whether local deployment succeeds depends on whether the sum of weights, KV Cache, activations, and visual files falls within the available capacity of each card. By calculating each item according to the methods in this article, most issues can be identified before going live.
