Running a 320B Multimodal Model Locally on Four Non-NVIDIA GPUs
This guide details the deployment of a 320-billion parameter multimodal model on four 32GB non-NVIDIA accelerator cards. It covers essential steps including inference branch selection, compute backend verification, VRAM budgeting with 2-bit dynamic quantization, KV Cache calculation, multi-GPU layer-wise splitting, validation methods, and troubleshooting strategies.
Goals and Success Criteria
This deployment is designed for developers with operations experience. The hardware consists of four 32GB non-NVIDIA professional accelerator cards. The model has 320 billion (320B) parameters and must process both text and image inputs simultaneously. Video input is out of scope for this deployment.
The success criteria are as follows:
- Stable text-based Q&A: continuous requests should not cause process crashes, empty outputs, or garbled text.
- Long-text retrieval: the model must be able to retrieve specified paragraphs within the target context length.
- Image recognition: image content must be correctly identified.
1. Selecting an Inference Branch for New Architectures
Newly released native multimodal models often use novel attention structures and multimodal fusion layers. If the inference code in the main branch lacks definitions for these layers, loading the model will result in tensor shape mismatches or missing layer errors. Therefore, verify the framework’s support status before deployment.
Search the project’s Issues and Pull Requests for the model name to find a branch that supports the architecture. Record the following items in your deployment checklist:
- Repository URL and branch name
- Full commit hash (can be obtained using
git log -1 --format=%H) - Compilation date and compiler version
Preview branches are typically less stable. Compile them separately from the main branch, placing the binaries in independent directories, such as /opt/llm/main-<hash> and /opt/llm/preview-<hash>. Use a symlink to switch the current version:
ln -sfn /opt/llm/preview-<hash> /opt/llm/current
If issues arise, point the symlink back to the main branch directory to roll back. Do not delete either set of compiled artifacts or the model files during a rollback.
2. Verifying Compute Backend and Drivers
Non-NVIDIA cards typically use two types of compute backends: ROCm for AMD graphics cards, and Vulkan for general GPUs that support it. Both have specific requirements for driver and compiler versions, which must match the graphics card model. The target architecture specified during compilation must match the device’s gfx number.
Use the following commands to check the ROCm environment:
rocminfo | grep gfxrocm-smi --showproductnamecat /opt/rocm/.info/versionhipcc --version
Use the following commands to check the Vulkan environment:
vulkaninfo --summaryvulkaninfo | grep -i driverinfo
Confirm that all four cards are recognized. If only some devices are detected, troubleshoot in the following order:
- Use
lspci | grep -i vgato confirm the OS sees all four cards. - Check
dmesgfor driver errors and confirm the kernel module is loaded. - Check power cables, slots, and PCIe lanes.
- ROCm users must ensure their account is in the
videoandrenderuser groups. - Once all the above are normal, proceed to troubleshoot model loading.
3. VRAM Budget After 2-bit Dynamic Quantization
Dynamic quantization allocates bit-width on a per-layer basis. Layers sensitive to precision retain a higher bit-width, while others are compressed to 2 bits. In this article, GB is calculated as 1 GB = 10^9 bytes.
Theoretical weight size estimation formula:
Theoretical Weight (GB) = Parameters (B) × Bit-width ÷ 8
Calculating 320B entirely at 2 bits yields roughly 320 × 2 ÷ 8 = 80 GB. The actual deployment package is about 110 GB, indicating that sensitive layers occupied a higher bit-width. After deducting the visual projection weights (about 1 to 2 GB), the average bit-width for language weights is roughly 2.7 bits. These figures are based on the deployment package used here; switching to a different quantization version requires recalculation.
Note that 110 GB is the model file size, not the VRAM usage after loading. Once loaded, VRAM must also accommodate:
- KV Cache: grows with context length and the number of concurrent requests.
- Activations and temporary buffers: space required for calculating intermediate results during inference.
- Framework overhead: space used by the runtime and inter-card communication libraries.
VRAM headroom estimation formula:
Available Headroom (GB) = Total VRAM − Model Weights − Reserved per Card × Number of Cards
This article assumes a reservation of 2 GB per card, totaling 8 GB for four cards.
Confirm the units for total VRAM first. 32 GB converted by bytes is 128 GB. If the vendor’s specified 32 GB is actually 32 GiB (about 34.4 GB), the total for four cards is about 137 GB. Use rocm-smi --showmeminfo vram or vulkaninfo to check the actual number of bytes, then plug it into the formula.
Calculated at 128 GB: Available Headroom = 128 − 110 − 8 = 10 GB. Calculated at 137 GB, the headroom is about 19 GB.
4. KV Cache and Context Length
The KV Cache usage formula is as follows:
KV Cache (bytes) = 2 × Number of Layers × Number of KV Heads × Head Dimension × Bytes per Element × Context Length × Concurrency
The “2” in the formula represents the two caches for K and V. In fp16, each element occupies 2 bytes. The parameters below are example values, assuming the model has 60 layers, 8 KV heads, a head dimension of 128, and uses fp16. In actual deployment, replace these with the real values from the model’s config.json file.
Using this set of example values, the KV Cache per token is roughly 2 × 60 × 8 × 128 × 2 = 245,760 bytes, or about 0.25 MB.
The table below calculates the usage for a single request based on the above formula. Theoretical concurrency is calculated based on a 10 GB headroom. Planned concurrency is calculated at 7 GB, retaining roughly a 30% buffer.
| Context Length | KV Cache per Request | Theoretical Concurrency (10 GB) | Planned Concurrency (7 GB) |
|---|---|---|---|
| 8K | ~2.0 GB | 4 | 3 |
| 16K | ~4.0 GB | 2 | 1 |
| 32K | ~8.1 GB | 1 | 0 |
| 64K | ~16.1 GB | 0 | 0 |
Looking at the planned values, a 32K single request exceeds the safe headroom. Under a 128 GB total, it is recommended to set the context limit to 16K or less in production environments. If the actual VRAM of the cards is 32 GiB, the headroom increases, and the limit can be relaxed accordingly.
When starting the service, the maximum context length and maximum concurrency must be set simultaneously. Setting only one may still trigger VRAM overflow for certain long requests. When overflow occurs, logs will typically show terms like out of memory or HIP error.
5. Multi-GPU Layer-wise Splitting
A single card’s VRAM cannot fit the 110 GB of weights, so multiple cards are required. The layer-wise splitting approach places consecutive layers on the same card; after one card finishes calculating, it passes the activations to the next card.
Before splitting, find out the total number of layers in the model, then calculate the number of layers each card will handle. Assuming the model has 60 layers, distributed evenly across four cards, each card handles 15 layers.
The visual encoder, word embedding, and output layers consume extra VRAM. They are usually located on the first and last cards, which require more reserved headroom. The following is a rough allocation plan based on total weight size; actual values should be based on testing:
| Card | Layer Range | Extra Load | Target Usage |
|---|---|---|---|
| GPU0 | Layers 1 to 15 | Visual encoder, word embedding | ~28 GB |
| GPU1 | Layers 16 to 30 | None | ~27 GB |
| GPU2 | Layers 31 to 45 | None | ~27 GB |
| GPU3 | Layers 46 to 60 | Output layer | ~28 GB |
Two things to note about layer-wise splitting:
- A single request passes sequentially through all four cards, meaning single-request latency is higher than running on a single card. With multiple concurrent requests, all four cards can work simultaneously, increasing throughput. This is an inherent characteristic of pipeline splitting.
- Inter-card communication goes over PCIe. If the motherboard topology is not ideal—for example, if the four cards span across CPU sockets—communication latency will increase significantly. Use
rocm-smi --showtopoto check the topology and try to ensure the cards are under the same PCIe root complex.
After deployment, use rocm-smi --showmeminfo vram to check the used VRAM on each card. If one card is near its limit while others have free space, adjust the layer allocation and move some layers to the idle cards.
6. Validation Methods and Failure Criteria
Before going live, verify the deployment results with the following three tests.
Text Q&A. Prepare 30 questions with standard answers, covering factual Q&A, logical reasoning, and coding—10 of each type. Run two consecutive rounds. The pass criteria are as follows:
- No process crashes allowed.
- No empty outputs, or repeated output of the same sentence allowed.
- Accuracy must reach a pre-agreed threshold, such as 80%.
Long-text Retrieval. Embed a piece of information with a unique identifier into a long text, such as “The code is A7F3”. Insert the information at the front, middle, and back positions. Test lengths are divided into three tiers: 4K, 16K, and 32K. There are 9 combinations, each repeated 5 times, totaling 45 tests. A retrieval rate of 95% or higher is considered a pass. If a certain length tier fails, return to Section 4 and lower the context limit for that tier.
Image Recognition. Prepare 20 images, each with manually annotated standard answers. Question types include text recognition, object counting, and chart reading. Calculate accuracy based on key information (text, numbers, objects); reaching the agreed threshold is a pass. If the model describes objects that do not exist in the image, the entry is counted as a failure, regardless of whether other content is correct.
If any test experiences VRAM overflow, return to Sections 3 and 4 to recalculate headroom, and then adjust the context limit or concurrency.
7. Troubleshooting Checklist
- Tensor shape mismatch during loading: The inference branch does not match the model version. Return to Section 1 and verify the commit hash.
- Only some cards recognized: Troubleshoot drivers and hardware in the order outlined in Section 2.
- Short text works fine, but long-text retrieval fails: Likely KV Cache exceeding headroom. Lower the maximum context length and re-check the values in Section 4.
- Text works fine, but image recognition is poor: Check if the visual projection layer loaded successfully, and look for warnings in the logs about skipped weights.
8. Risk Warnings
- 2-bit quantization reduces precision, especially affecting numerical reasoning and detail recognition. You must re-test with your own test set before going live; do not directly adopt the scores published by the model authors.
- Preview branches may output incorrect results without throwing errors, so the validation phase cannot be skipped.
- The service should only listen to localhost or intranet addresses; do not expose it directly to the public internet.
- Logs and request records may contain user-uploaded images or sensitive text. Handle these according to data security requirements and do not store them in shared directories.
- Do not hardcode the service’s API keys and access tokens into startup scripts; place them in environment variables or a secrets management tool.
- The numbers in this article are derived from a specific deployment and do not represent the results of all four-card environments. Driver versions, firmware, and motherboard topology will change the conclusions, so you need to measure them on your own machine.
