Running Open-Source LLMs Locally: Model Selection, Quantization, and Deployment

    Learn how to choose an open-source LLM for your available memory, evaluate quantization options, and deploy it locally with Ollama. This guide covers licensing and cost considerations, hardware requirements, installation, API testing, GPU acceleration checks, and common deployment issues.

    1. Why Run Open-Source LLMs Locally?

    The open-source large language model ecosystem has developed rapidly over the past year. Several major models offer licenses that permit commercial use, allowing developers to run and modify them locally and redistribute them within the license terms.

    However, licenses vary. Some restrict the scale of commercial use, require attribution, or prohibit specific applications. Before deploying a model, read its model card and license to confirm that your intended use is permitted.

    Local deployment offers three main benefits:

    1. More control over API costs. Cloud models typically charge per token, so costs grow with frequent use. Running a model locally can eliminate external API charges, but hardware, electricity, cooling, and maintenance still cost money. Assess the economics against your actual usage.
    2. Data stays on your internal network. Keeping sensitive data away from third-party services can help address compliance requirements in finance, healthcare, and internal knowledge systems. Local deployment is not automatically secure: service access controls, log retention, and the provenance of model files still require separate checks.
    3. Greater customization. Local models can be fine-tuned, trimmed, or integrated with your own toolchain without depending on an external service’s quotas and rate limits.

    For developers, running an open-source model on a personal computer or server is now a common engineering option.

    2. Model Selection: Start with Memory, Then Model Size

    Model selection requires balancing three factors. Parameter count influences the model’s capability ceiling, while quantization determines the size of its weight files. The runtime also needs additional memory for the KV cache, which stores intermediate context information, and inference buffers. Longer contexts and more concurrent requests increase that overhead.

    The following figures are approximate. Actual requirements vary by model family, quantization format, context length, and inference framework.

    Model class Typical parameter count Approximate 4-bit weight size Suggested available RAM or VRAM Typical uses
    Very small models 1B–5B 1–3 GB 4–8 GB Everyday chat, simple summaries, edge devices
    Small models 7B–9B 4–6 GB 8–12 GB Text rewriting, basic Q&A, lightweight coding assistance
    Mid-sized MoE models 20B–30B total, with only some experts active per inference step 13–19 GB 24 GB Local assistants, general Q&A, moderately difficult coding
    Larger dense models Around 30B, with all parameters participating in computation 18–20 GB 24–32 GB Mathematical reasoning, complex code generation

    Two distinctions matter here.

    First, mixture-of-experts (MoE) models have a large total parameter count, with knowledge capacity approaching that of similarly sized dense models, but activate only a subset of experts during inference. As a result, they are often faster than dense models with a similar weight footprint.

    Second, Apple Silicon uses unified memory shared by the CPU and GPU, whereas a discrete GPU has its own VRAM. Available capacity must therefore be assessed differently on these systems.

    Use the following selection process:

    1. Check available memory. Use Activity Monitor on macOS, Task Manager on Windows, or free -h on Linux. If you have an NVIDIA GPU, also run nvidia-smi to check VRAM.
    2. Choose a model class from the table based on your available capacity.
    3. Leave headroom. Within that class, choose a quantized version whose weight size leaves enough room for context processing and other applications.
    4. Check free disk space before downloading. Model files commonly occupy several to tens of gigabytes.

    This helps avoid downloading a model that cannot load—or one that loads but repeatedly exits because of insufficient memory.

    Choosing a 4-Bit Quantization

    Quantization compresses model weights from higher-precision values into lower-bit representations. It is one of the main ways to reduce VRAM requirements.

    For models distributed in GGUF format, Q4_K_M is a widely used compromise. Its size is roughly one-quarter of the original high-precision weights, with relatively small quality losses on many tasks. Q8 variants retain quality closer to the original model but are roughly twice the size of Q4 versions. Q2 and Q3 are smaller, but their quality losses are usually more noticeable in reasoning and coding tasks.

    When memory is tight, prioritize a smaller model before moving to a lower-bit quantization. Quality degradation tends to become apparent in complex reasoning before it is noticeable in simple conversation.

    3. Deployment: Start with a Local Inference Framework

    3.1 Choose Your Tools

    The simplest approach is an integrated local inference framework. These tools package model downloading, quantized model loading, inference engines, and a local API service, with support for macOS, Windows, and Linux.

    Ollama is a widely used option, built on inference engines such as llama.cpp. For more detailed control, you can use projects such as llama.cpp or vLLM directly, although they require more configuration.

    For hardware acceleration, Apple Silicon devices can use Metal to access the GPU, typically providing a substantial improvement over CPU-only inference. NVIDIA GPUs require the appropriate drivers. AMD GPU support depends on the framework and operating system version; consult the framework’s documentation.

    3.2 Install Ollama and Download a Model

    The following commands use Ollama. Model tags can change as the official library is updated. Confirm the model name and size in the Ollama model library, and follow the instructions on the official download page.

    1. # macOS: download the installer from the official website,
    2. # or install with Homebrew, following the official documentation
    3. brew install ollama
    4. # Start the background service; the default address is 127.0.0.1:11434
    5. # Skip this step if the desktop application has already started the service
    6. ollama serve
    7. # Download the model; verify the tag in the official model library first
    8. ollama pull gemma3:27b
    9. # Run interactively; --verbose displays statistics such as generation speed
    10. ollama run gemma3:27b --verbose
    11. # Inspect loaded models and their CPU/GPU allocation
    12. ollama ps

    The PROCESSOR column in ollama ps indicates where the model is running. For example, 100% GPU indicates that the model is running entirely on the GPU. If ollama run --verbose reports a low evaluation rate, use the output of ollama ps to help investigate.

    3.3 Validate and Tune the Deployment

    Once the model starts, work through the following checks.

    Step 1: Test Interactive Generation

    In the ollama run interface, enter a simple prompt such as “Introduce yourself in one sentence.” Confirm that the model generates a response.

    Step 2: Test the Local API

    The service listens on port 11434 by default. Use curl to verify that the API responds:

    1. curl http://localhost:11434/api/generate -d '{
    2. "model": "gemma3:27b",
    3. "prompt": "Introduce yourself in one sentence.",
    4. "stream": false
    5. }'

    The returned JSON contains a response field with the model’s output. Ollama also provides an OpenAI-compatible endpoint at /v1/chat/completions.

    Step 3: Check Hardware Acceleration

    Run ollama ps. If it reports substantial CPU usage, check the following in order:

    • Confirm that your drivers and operating system version meet the framework’s requirements. NVIDIA users can run nvidia-smi to verify that the GPU is detected.
    • Confirm that you installed a native build rather than a version running through an emulation layer.
    • Reduce context length through the num_ctx request parameter to lower KV cache memory usage.
    • Try a smaller model or a lower-bit quantized version.

    Step 4: Investigate Common Failures

    Symptom Possible cause Troubleshooting
    Out-of-memory or insufficient-VRAM error during loading The model and its context exceed available capacity Choose a smaller model or lower-bit quantization, and reduce num_ctx
    Download fails partway through Network interruption or insufficient disk space —