How to Deploy Open-Source Lightweight LLMs Locally with Ollama

    This article explains how to run open-source lightweight LLMs on a local machine, covering hardware and memory sizing, quantization trade-offs, and a step-by-step Ollama deployment workflow. Readers will learn how to estimate memory requirements, choose a suitable model, evaluate quantized versions, and pull, run, and verify a model locally.

    Running large language models on your own computer is no longer something only researchers can do. Open-source model licenses are becoming more permissive, allowing commercial use, modification, and redistribution. With mature local inference tools, ordinary developers can complete inference on a laptop. Using Ollama as an example, this article walks through the full process, from model selection to integration into an application. The approach is not tied to a single model; it also applies when you switch to other tools or models.

    Benefits and Costs of Local Deployment

    Local deployment offers three main benefits. First, for long-term, high-frequency usage, token-based cloud API fees continue to grow, while the marginal cost of local inference is mainly electricity. Second, sensitive data does not need to leave the machine, making it easier to meet privacy and compliance requirements. Third, open weights allow fine-tuning, distillation, and domain adaptation, which proprietary APIs rarely provide.

    The costs are equally clear. Hardware is a one-time investment, but it must also be factored into depreciation, electricity, and maintenance time. If the device sits idle most of the time, the amortized cost per call may be higher than cloud usage. Whether local deployment is worthwhile depends on call frequency and device utilization. Therefore, the first step in model selection is assessing your machine.

    Choose a Model Based on Memory

    A local model uses memory in four parts: model weights, KV cache, inference runtime, and the operating system and other programs. The weights can be roughly estimated as parameter count in billions multiplied by bytes per parameter. 4-bit quantization uses about 0.5 bytes per parameter, so a 3B-parameter model has about 1.5 GB of weights, and a 30B-parameter model has about 15 GB. Actual files also include metadata such as group scaling, so they are usually 10% to 20% larger than this estimate.

    KV cache grows with context length. The longer the context, the more memory it uses, so nominal 128K or 256K context windows are often impractical on ordinary devices. The inference runtime and the operating system also need a few GB reserved.

    Using this method, the following rough guidance applies. Assume a 4K context and batch size 1:

    • Lightweight models with about 2B to 3B parameters: 4-bit weights are about 1.5 to 2 GB, and about 3 GB with the runtime. An 8 GB RAM device can run them, and edge devices such as Raspberry Pi can also run small models.
    • Everyday models with about 4B to 5B parameters: weights are about 2.5 to 3 GB, and the total is about 4 to 5 GB. A 16 GB office laptop can run them smoothly.
    • Mixture-of-Experts (MoE) models: all expert parameters must remain resident in memory, so the footprint is determined by total parameter count, not by the number of active parameters per inference. A 4-bit model with about 30B total parameters has about 15 GB of weights. 24 GB of memory is fairly comfortable, but long contexts require more headroom. Inference speed for this type of model is close to that of a small model with a similar number of active parameters, and quality on some tasks may approach full-parameter models in the same series. This depends on expert routing, training data, and task distribution, so the two cannot be simply equated.
    • Full-parameter dense models: at about 30B parameters, weights are about 15 GB, and the overall requirement is around 20 GB. 24 GB can run the model but with little headroom; 32 GB is more comfortable.

    These numbers are estimates. Before selecting a model, check the actual file size on the model page and reserve enough memory for the system and other programs.

    Quantization: Trade Precision for Memory

    Quantization compresses weights originally stored as 16-bit floating point into fewer bits. 4-bit quantization is about one quarter the size of 16-bit, and techniques such as group scaling reduce accuracy loss. For most chat and code tasks, this quality loss is usually acceptable. Lower bit counts cause more noticeable degradation in long-text reasoning and complex logic tasks. 8-bit quantization has less loss but doubles the memory footprint, making it suitable for critical workloads or hardware with ample capacity.

    Do not evaluate quantization quality by feel alone. Prepare 50 to 100 real task samples, run them on different quantized versions, check accuracy manually or with rules, and then decide which version to use.

    Deployment Workflow: Ollama Example

    Step 1: Install the Tool and Confirm the Service Is Running

    macOS users can run:

    1. brew install --cask ollama

    After installation, launch the Ollama app. Linux and Windows users should download the appropriate installer from the official website at ollama.com and verify the checksums provided on the release page. Confirm that the service is running:

    1. curl http://localhost:11434/api/version

    Step 2: Reserve Disk Space and Pull the Model

    Before downloading, confirm that available disk space is at least twice the model size, because the pull process temporarily stores data. For a model with about 3B parameters:

    1. ollama pull qwen2.5:3b

    Ollama verifies the SHA256 digest of each layer during the pull. If a file is corrupted, it reports an error rather than silently using it. If the download is interrupted, rerun the command to resume.

    Step 3: Run and Verify

    Enter interactive mode and send a test question:

    1. ollama run qwen2.5:3b

    Then, in another terminal, check resource usage:

    1. ollama ps

    The PROCESSOR column in the output shows GPU and CPU usage.