Hierarchical Storage for Local Inference of Ultra-Large Models

    This article explains how to run ultra-large MoE models on consumer hardware using a three-tier storage hierarchy, on-demand expert loading, streaming prefetch, and low-bit quantization. It covers tier responsibilities, scheduling pitfalls, CPU-only inference trade-offs, a memory budgeting formula, and practical engineering recommendations.

    1. The Core Problem: Parameter Scale vs. Memory Capacity

    Flagship models built on ultra-large Mixture-of-Experts (MoE) architectures now reach hundreds of billions of parameters. At int4 quantization, the weights alone require hundreds of gigabytes of storage, while a typical consumer PC has only 16GB to 32GB of physical memory. The traditional assumption of loading an entire model into memory before inference no longer holds.

    One common misconception is worth clearing up. Because MoE models activate sparsely, a single forward pass wakes only a small fraction of the expert networks. The total parameter count is huge, but the number of parameters actually involved in computing a single token is far smaller. This is the physical basis that makes local deployment viable: what must stay resident in high-speed memory is the attention layers, shared layers, and routing-related core parameters, while the routed expert parameters that make up most of the model size can sit on slower media and wait to be called.

    2. The Core Approach: Three-Tier Storage with On-Demand Scheduling

    2.1 Dividing Responsibilities Across Tiers

    A sensible layout looks like this:

    • Tier 1 (VRAM / high-bandwidth memory): expert shards for the current batch plus all intermediate tensors needed by attention computation.
    • Tier 2 (system memory): a parameter cache pool holding quantized resident weights, typically around 10GB.
    • Tier 3 (local SSD): the largest routed expert parameter set, which can reach hundreds of gigabytes.

    Data moves upward through the tiers in one direction only: disk pages are cached into memory, memory shards are promoted to VRAM, and after computation they fall back tier by tier according to an eviction policy.

    2.2 Implementing Streaming Loads

    The key to streaming inference is prefetching rather than waiting. In practice, a ring buffer is maintained so that while the GPU computes layer n, a background thread has already finished reading and dequantizing the expert parameters for layer n+1. The scheduling logic can be sketched as:

    1. /* Pseudocode: main loop for hierarchical streaming inference */
    2. for (int layer = 0; layer < num_layers; layer++) {
    3. expert_id_t e = router_select(layer, hidden_state); // routing decision
    4. void *shard = cache_acquire(layer, e); // return immediately on cache hit
    5. if (!shard) {
    6. prefetch_async(layer, e); // async prefetch on miss
    7. shard = cache_wait(layer, e);
    8. }
    9. hidden_state = moe_forward(hidden_state, shard);
    10. cache_release(layer, e); // reclaim by LRU policy
    11. }

    Three things make this hard. First, balancing cache hit rate against prefetch depth: prefetch too shallow and disk waits creep in, too deep and memory gets squeezed. Second, routing outcomes are uncertain, so the prefetch target is hard to pin down in advance and usually requires statistical prediction based on historical routing distributions. Third, dequantization cost must overlap with I/O, otherwise the CPU becomes the new bottleneck.

    2.3 Low-Bit Quantization and Resident Set Compression

    The goal of quantization is not blind compression but shrinking the “must be resident” portion to something memory can hold. The common industry practice is to represent attention and shared weights in int4 or fewer bits, while keeping a few high-precision copies of sensitive layers to control accuracy loss. With reasonable quantization, resident memory usage can be held to around 10GB, leaving headroom for the operating system and runtime.

    3. The Value and Limits of a CPU-Only Inference Path

    A lightweight implementation with zero external dependencies (for example, pure C with no third-party runtime) has clear advantages locally: deployment needs no complex driver or framework stack, cross-compiling to various platforms is cheap, and memory fragmentation and runtime overhead stay controllable. Pairing it with memory-mapped file access to the on-disk parameter region lets the operating system’s page cache do most of the caching work, reducing the complexity of a custom cache.

    The constraints are equally clear. CPU compute density is far below that of accelerators, so per-token latency is typically on the order of seconds. This suits offline batch work with loose interactivity requirements and privacy-sensitive local assistance, not high-concurrency online serving. For higher throughput, running on platforms with a unified memory architecture can help by reducing cross-media copies.

    4. Memory Budgeting and Capacity Planning

    Before deployment, a rough estimate is worth doing:

    1. Total memory need ≈ resident quantized weights + activations and KV cache + runtime and system overhead + safety margin

    With 25GB of usable memory, subtracting roughly 4GB for the system and runtime and about 2GB for KV cache and activations leaves around 10GB for resident weights, which matches the resident set size after int4 quantization. On the disk side, reserve hundreds of gigabytes of contiguous space and prefer SSDs with good random-read performance, since expert loading is a large number of small random reads.

    5. Engineering Recommendations

    1. Get a minimal configuration running before tuning, and make routing logs and cache hit rates observable.
    2. Track memory levels and disk queue length with monitoring and alerting to avoid thrashing.
    3. Model files can be hosted on object storage and downloaded on demand, with a local cache to avoid repeated pulls.
    4. Pin the runtime environment in a container platform to keep dependencies consistent and rollbacks fast.
    5. If cloud assistance is used, a general-purpose container platform and logging service can host the build and evaluation pipeline, leaving only inference execution on the local machine.

    6. Conclusion

    Pushing ultra-large models down to consumer hardware is essentially trading time for space: accepting controllable latency in exchange for an order-of-magnitude gain in memory capacity. Hierarchical storage, streaming prefetch, and low-bit quantization are all indispensable, and the real engineering hurdle lies in scheduling strategy and observability. Baidu AI Cloud’s long-term investment in heterogeneous computing and storage tiering also offers a reference engineering model for this kind of local inference setup.