Dual-GPU Heterogeneous Inference for Trillion-Parameter Models: A Practical Speedup Walkthrough
This article explains how to run inference on a trillion-parameter model when the weights far exceed available VRAM, using a dual-GPU heterogeneous setup. It breaks down a three-tier storage design (persistent memory, tmpfs, VRAM) and a two-part compute split between GPU and host CPU, then shows how moving 45 of 94 shards (414GB) into tmpfs improved generation speed by about 41% and prompt evaluation by about 26%. It also explains why using only 5.5% of total VRAM still yields major gains, and ends with reusable engineering practices and cloud deployment considerations.
1. The Problem: When Model Size Far Exceeds VRAM
Once large language models reach the trillion-parameter scale, the first hurdle in inference deployment is no longer the algorithm but the memory hierarchy. Storing a 2.8-trillion-parameter model at 16-bit precision requires roughly 5.6TB of space, while each token activates only about 104 billion parameters. Even counting just the activated portion, the footprint far exceeds the VRAM of any single consumer GPU.
This creates a typical mismatch: the model files are on the order of terabytes, while a single machine has only tens of gigabytes of VRAM—less than 6% of the total model size. Under these conditions, trying to “fit the entire model into VRAM” is unrealistic. The engineering focus must shift to how data moves efficiently between host memory, persistent memory, and VRAM, and how to offload the most compute-heavy work to the GPU.
2. Architecture Breakdown: Three Storage Tiers and Two Compute Roles
The core idea of this practice can be abstracted as “three storage tiers plus two compute roles.”
The storage side has three tiers. The first is persistent memory, which offers large capacity and better random-read performance than a standard SSD, making it suitable for holding large, infrequently changing weight blocks. The second is a RAM disk (tmpfs), which virtualizes part of the host memory as a filesystem directory, trading a file interface for higher read throughput. The third is VRAM, which has the smallest capacity but the highest bandwidth and holds only the hottest tensors.
The compute side is split by responsibility. The GPU handles compute-intensive, relatively regular-access work such as attention computation, while the host CPU handles tensor access and scheduling related to expert routing. Because the routed expert tensors are enormous in total size but only sparsely activated per token, keeping them on the host side—backed jointly by persistent memory and the RAM disk—is more cost-effective than forcing them into VRAM.
A simplified sharding placement logic can be expressed in pseudocode:
# Pseudocode: illustrates the shard placement strategy only; not a real APIHOT_GPU_LAYERS = 2 # attention-related shards placed in VRAMSHARD_TOTAL = 94SHARD_SIZE_GB = 414 / SHARD_TOTALfor i in range(SHARD_TOTAL):if i < HOT_GPU_LAYERS:place_to_vram(i) # VRAMelif i < 45:place_to_tmpfs(i) # RAM diskelse:place_to_pmem(i) # persistent memory
3. The Key Change: Moving 45 Shards into the RAM Disk
The most representative step in the upgrade was migrating 45 of the 94 model shards (414GB in total) from persistent memory to the RAM disk, leaving the rest on persistent memory. The benefit comes from a shorter access path: the RAM disk eliminates the extra overhead of the persistent memory controller and filesystem cache, turning large sequential reads into behavior close to a memory copy.
The measured result was an approximately 41% improvement in generation speed and about 26% in the prompt evaluation stage. The difference between the two numbers is itself informative. Prompt evaluation is a compute-intensive stage with relatively predictable weight reads, so its bottleneck lies more in compute. Token-by-token generation, by contrast, is memory-access-intensive and re-reads weights at every step, so it benefits more from storage-path optimization. This also explains why the storage-layer改造 has greater leverage on generation speed.
4. Why 5.5% VRAM Usage Still Delivers Clear Gains
The two GPUs provide 48GB of VRAM combined—only about 5.5% of the 865GB model file—yet deliver more than a 40% speedup in generation. The reason is that inference performance is not linearly determined by “how much of the weights fit in VRAM,” but by the bottleneck on the critical path.
Attention computation sits on the mandatory path of every token’s inference. Moving it from a general-purpose processor to high-bandwidth VRAM is equivalent to placing the most frequent and unavoidable segment of computation on faster hardware. The routed experts, though huge in total parameter count, activate only 16 experts per token (2 of which are shared experts)—a sparse-access pattern whose cost shows up more in random reads than in raw compute. Keeping the sparse part on the capacity-rich host side and the dense part in VRAM is a typical “layer by access pattern” tradeoff.
The pre-change expectation was 2 to 4 tokens per second, and the measured 3.11 tokens per second falls within that range. This shows that the performance ceiling of such an architecture is determined jointly by storage bandwidth and the proportion of compute offloaded, rather than by the peak compute of any single piece of hardware.
5. Reusable Engineering Practices
Four general practices can be distilled from the above, applicable to any local or cloud inference scenario where the model is far larger than VRAM:
- Do the capacity math first. Estimate weight size from parameter count and precision (for trillions of parameters at 16-bit, roughly twice the parameter count in bytes), then match it against VRAM, memory, and persistent memory capacity to avoid a plan that is infeasible from the start.
- Layer by access pattern. Put dense, mandatory computation in VRAM, and sparse, large-block data in host memory or persistent memory, using the RAM disk as a middle tier to absorb random-read amplification.
- Quantize in stages. There is no need for a uniform precision across the whole model; you can choose different quantization bit widths per tensor based on sensitivity, balancing precision loss against bandwidth gains.
- Define the evaluation criteria clearly. Generation speed and prompt evaluation speed must be reported separately, along with the shard placement scheme, precision, and hardware configuration; otherwise the numbers cannot be compared across setups.
6. Future Directions and Cloud Extensions
The practitioner mentioned exploring customized schemes for selecting quantization precision per tensor, which aligns with the broader industry direction: mixed precision, allocating bit widths by per-layer sensitivity, and treating hot and cold layers differently can usually further reduce memory access without a noticeable loss in quality.
If this approach is moved to the cloud, it can be assembled from general-purpose capabilities: object storage to hold terabyte-scale weight files, a container platform to provide a reproducible runtime environment, and monitoring, alerting, and logging services to continuously track throughput and latency metrics. In such scenarios, Baidu AI Cloud also offers general-category capabilities—such as object storage, a container platform, and monitoring and alerting—to support the deployment and observability of large-model inference.
Overall, local inference for trillion-parameter models does not have to rely solely on stacking top-tier hardware. A more feasible approach is to design around the memory hierarchy: first account for capacity, then place data by access pattern, and finally measure gains with a consistent set of criteria.
