Running Large Language Models Locally on Unified Memory: A Practical Guide to Quantized Inference

    This article explains how to run quantized large language models with hundreds of billions of parameters on a single machine with large unified memory. It covers why local deployment matters, how quantization shrinks model weights, how unified memory architecture supports inference, how to configure an inference runtime, which performance metrics to track, and how local and cloud deployment can work together.

    Introduction: Why Run Very Large Models Locally

    Language models have grown steadily in size. Open models with hundreds of billions, and in some cases close to a trillion, parameters now exist. Until recently, such models were generally considered to require cloud clusters for inference, which put them out of reach for individual developers and small and medium-sized businesses. Advances in on-device chip performance, the spread of unified memory architecture, and mature model quantization techniques have changed this. Running very large models on a local workstation or even a compact mini PC is now practical.

    Local deployment offers three main benefits. First, data privacy: sensitive data never leaves the local environment, which helps meet compliance requirements. Second, cost control: a one-time hardware investment replaces ongoing pay-per-use billing. Third, offline availability: local inference does not depend on network quality, which suits internal networks and edge environments with limited connectivity. This article uses a practical case as its example: running a quantized very large model on a device with a large unified memory pool. It breaks down the key technical steps and engineering practices involved.

    1. Model Quantization: The Core Method for Shrinking Large Models

    Quantization is the first hurdle in local deployment. A 280-billion-parameter model stored in FP16 precision needs about 560 GB of memory for its weights alone. That exceeds the capacity of any single consumer device. With 4-bit quantization, commonly referred to as the Q4 scheme, the weights shrink to about one quarter of their original size, roughly 140 GB. At that size, the model can fit into a device with a large memory pool.

    Quantization works by approximating the original weights with lower numerical precision. Common approaches include:

    1. Group-wise quantization: Weights are split into fixed-size groups. Each group gets its own scaling factor and zero point, which balances compression ratio against accuracy loss.
    2. Mixed precision: Precision-sensitive components, such as attention layers and embedding layers, keep a higher bit width. Other components are compressed more aggressively.
    3. Calibration: A small representative dataset calibrates the quantization parameters, which reduces shifts in the output distribution.

    For practical use, choose quantized versions that the community has widely tested. Avoid quantizing the model yourself unless you can control the resulting accuracy loss. Before deploying, compare the outputs of the original and quantized models on a fixed set of evaluation prompts. Confirm that the quality is acceptable before using the model in production.

    2. Unified Memory Architecture: The Hardware Foundation for On-Device LLMs

    In a traditional architecture, CPU memory and GPU video memory are separate. Model weights must be loaded into VRAM before the GPU can use them. Consumer graphics cards typically have only 8 GB to 24 GB of VRAM, which is the biggest bottleneck for local inference. Unified memory architecture lets the CPU and the integrated GPU share the same physical memory. Combined with a high-bandwidth memory design, the integrated GPU can access the full memory space directly.

    A device with 192 GB of unified memory can provide more than 150 GB for model inference after the operating system and other system processes take their share. That capacity covers the weights of a Q4-quantized very large model and leaves room for the KV cache. When you choose hardware for this purpose, pay attention to two factors:

    • Memory bandwidth: Local inference is a memory-bound workload. Bandwidth determines generation speed (tokens per second) more directly than raw compute performance does.
    • Memory allocation policy: Most platforms let you adjust, in firmware, the amount of memory reserved for graphics. Before deployment, set this limit high enough to prevent inference from failing partway through because of insufficient memory.

    3. Inference Engine and Runtime Configuration

    At the software level, local inference typically relies on a tensor-optimized inference runtime and a framework that schedules work across CPU and GPU. The following startup configuration illustrates the approach. It is an example only:

    1. # Example only: load a quantized model and enable GPU-accelerated layers
    2. inference-cli \
    3. --model ./model-q4.gguf \
    4. --gpu-layers 99 \
    5. --ctx-size 8192 \
    6. --threads 16

    Several key parameters deserve explanation:

    1. GPU offload layers: This setting determines how many layers run on the GPU. If memory allows, offload as many layers as possible. Offload only part of the model when memory is insufficient, and let the CPU process the remaining layers.
    2. Context length: KV cache usage grows in proportion to the context length, the number of layers, and the hidden dimension. Very long contexts substantially increase memory use. Set the context length based on actual business needs instead of always using the maximum.
    3. Threads and batching: CPU-side work, such as part of the prompt prefill operations, depends on the thread count. Adjust the thread count to match the number of physical cores.

    4. Performance Evaluation: Metrics That Matter

    Evaluate local inference across three dimensions:

    • Time to first token (TTFT): This measures how quickly the model processes the prompt. It depends heavily on compute performance.
    • Generation throughput (tokens per second): This measures memory efficiency during token-by-token generation. Memory bandwidth is the main factor. For Q4 local inference on very large models, single-digit to low-double-digit tokens per second is a common range. Whether that speed is acceptable depends on the use case. Offline batch processing can tolerate lower speeds, while interactive chat requires a trade-off.
    • Output quality: Use a standardized test set or your own evaluation set to check whether quantization and inference settings cause noticeable capability loss.

    Create a fixed benchmark script and rerun it after every configuration change. This builds a reproducible performance record.

    5. Combining Local and Cloud Deployment

    Local deployment does not aim to replace the cloud. A more practical architecture divides the work between the two. Sensitive, frequent, and lightweight requests run locally, which protects privacy and keeps latency low. Complex, long-tail tasks that need a more capable model go to elastic cloud compute. For example, on Baidu AI Cloud, you can use general container platform, object storage, and monitoring and alerting services to build a unified management layer for cloud inference services and local nodes. That layer can handle model version distribution, load scheduling, and log aggregation.

    This hybrid model keeps the privacy and cost advantages of local deployment and retains the elasticity and higher model capability of the cloud. It is a practical path for enterprise adoption.

    Conclusion

    Running Q4-quantized very large models on a unified memory device shows that moving large models to the edge is technically feasible. Three factors make it work: a mature quantization method, a large and high-bandwidth unified memory pool, and a well-tuned inference runtime. Quantization algorithms and on-device chips continue to improve, so local inference speed and quality should keep rising. For developers, now is a good time to build local large-model engineering skills. Start with one complete deployment and evaluation, then gradually build experience in quantization assessment, performance tuning, and hybrid local-cloud operation.