CPU + GPU + NPU Heterogeneous Mode: Configuring Local LLM Inference

    This article explains how to configure CPU + GPU + NPU heterogeneous execution for local large language model inference. It covers why a single compute unit cannot balance performance, power, and cost; the division of labor and bottlenecks across the three device types; and the four core runtime mechanisms: layer offloading, operator-level placement, memory management, and KV Cache placement. It also walks through a practical configuration workflow, notes format and quantization considerations when choosing a model, and lists common tuning mistakes to avoid.

    1. Why Local Inference Needs CPU + GPU + NPU Cooperation

    When you deploy a large language model locally, a single compute unit rarely balances performance, power draw, and cost at the same time. Each type of hardware is designed with a different goal in mind:

    • GPU excels at large-scale parallel floating-point math, which suits operator-heavy workloads such as attention computation and matrix multiplication.
    • NPU uses a dedicated pipeline optimized for neural network inference. It offers high energy efficiency and fits forward passes with relatively fixed data flow.
    • CPU is general-purpose and flexible. It handles task scheduling, tensor pre- and post-processing, and operators that are hard to offload to accelerators.

    Scheduling all three together yields higher throughput and lower latency on limited hardware, which is the core value of heterogeneous inference. One point deserves emphasis: heterogeneous execution is not simply “stuffing the model onto every device.” It requires splitting and placing work according to operator characteristics and data dependencies.

    2. Division of Labor and Bottleneck Analysis

    Understanding the division of labor is the prerequisite for configuration.

    • Compute and bandwidth bottlenecks: GPU memory is limited. When model parameters exceed it, they must spill over to system memory or a dedicated accelerator. NPUs usually pair with a unified memory architecture, offering larger capacity but lower peak compute than high-end GPUs.
    • Data movement overhead: Transferring tensors across devices adds latency. Moving data frequently among CPU, GPU, and NPU can cancel out the gains from parallelism.
    • Operator compatibility: Not every operator is fully supported by accelerators. Unsupported operators fall back to the CPU, creating breaks in the compute path.

    The configuration goal, therefore, is not to keep every device at full load, but to minimize data movement and balance the bottlenecks.

    3. Core Runtime Configuration Mechanisms

    3.1 Layer Offloading

    The most common strategy splits the model by Transformer layer: compute-intensive layers go to the GPU or NPU, while overflowing layers stay in CPU memory. Runtimes typically expose a setting for the number of offloaded layers or a device mapping table, illustrated below (for explanation only, not a specific API):

    1. device_map = {
    2. "embed_tokens": "npu",
    3. "layers.0-15": "gpu",
    4. "layers.16-23": "cpu",
    5. "lm_head": "gpu"
    6. }

    The more layers you assign to accelerators, the higher the performance, but capacity limits on GPU memory or dedicated memory constrain this. You need to balance capacity against performance.

    3.2 Operator-Level Placement

    Finer-grained than layer splitting, operator-level scheduling assigns matrix multiplication to the GPU and lightweight operators such as normalization and activation to the NPU or CPU. This approach is flexible but complex to schedule, and is generally worth enabling only when operator compatibility differs substantially across devices.

    3.3 GPU Memory and System Memory Management

    • Reserve enough GPU memory for the KV Cache to avoid spilling mid-inference.
    • Use paging or unified memory management on the CPU side to reduce fragmentation.
    • Reuse buffers through a memory pool to cut the cost of repeated allocation.

    3.4 KV Cache Placement Strategy

    In long-context scenarios, the KV Cache grows quickly. Keep the frequently accessed portion on the GPU and push the cold portion down to the NPU or system memory, combined with a paging mechanism that swaps data in and out on demand. This maintains stable throughput on long sequences.

    4. Configuration Workflow

    A typical implementation proceeds as follows:

    1. Assess the hardware: measure GPU memory, available NPU memory, and CPU memory capacity.
    2. Decide the placement plan: generate an initial device_map based on model size.
    3. Set the number of offloaded layers: start conservatively, then shift gradually toward the accelerators.
    4. Enable memory reuse and KV Cache paging.
    5. Stress-test and tune: watch per-device utilization and end-to-end latency, then iterate.
    1. # Sample pseudo-configuration
    2. offload_layers = 16 # layers offloaded to accelerators
    3. kv_cache_paging = true # enable KV Cache paging
    4. memory_pool = enabled # reuse memory buffers

    5. Model Sources and Format Compatibility

    Whether local inference is practical depends largely on how rich the model ecosystem is and how well formats are supported. The common industry practice is to obtain weights from open model hosting communities, which update quickly and cover a wide range of models, so new releases usually become available soon after launch. Keep the following in mind:

    • Format conversion: runtimes require different model formats, so a conversion or quantization step is usually needed to turn the original weights into a supported format.
    • Quantization choice: INT8 and INT4 quantization significantly reduce memory usage, but require a trade-off between accuracy and performance.
    • Operator coverage: if a model contains new operators that accelerators do not support, execution degrades to the CPU and erodes the benefits of heterogeneity.

    When selecting a model, prioritize ones with good format support and complete operator coverage.

    6. Tuning Tips and Common Mistakes

    • Mistake 1: more offloading means more speed. Excessive offloading makes data shuttle back and forth between devices, which is actually slower.
    • Mistake 2: every device must be fully utilized. Balance matters more than full load; the weakest link determines overall performance.
    • Recommendation: start stress-testing with small batches and short contexts, then scale up gradually; continuously monitor per-device utilization; fix the random seed so results are reproducible.

    7. Summary

    The essence of CPU + GPU + NPU heterogeneous inference is finding the optimal trade-off among capacity, compute, and data movement. Master the four mechanisms — layer offloading, operator placement, memory management, and KV Cache management — and combine them with model format compatibility and systematic stress testing, and you can build a local inference setup that balances performance and energy efficiency.