Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Small Language Models: How to Choose Where AI Runs

· 7 min read · Home Tech

In this article
  1. Background: Why Small Models Changed the Deployment Game
  2. How It Works: The Hardware and Software Stack
  3. How to Choose: Key Factors and a Decision Framework
  4. Common Problems and How to Solve Them
  5. Comparison: On-Device vs. Self-Hosted Server vs. Cloud API
  6. Costs and Performance Trade-offs
  7. Safety and Security Considerations
  8. Alternatives and Future Trends
  9. Frequently Asked Questions

Small language models (SLMs) are compact AI systems that can run directly on your device or on a local server, and choosing where they run depends on your hardware, privacy needs, and performance requirements. The main options are on-device inference (your phone, laptop, or edge device) or self-hosted servers (your own PC, NAS, or a rented cloud VM), and the right choice balances speed, cost, and control.

Background: Why Small Models Changed the Deployment Game

For years, large language models (LLMs) like GPT-4 or Claude required massive cloud data centers and API calls. But a new generation of small language models—typically under 10 billion parameters—can run on consumer hardware. Examples include Meta's Llama 3.2 1B/3B, Microsoft's Phi-3 family, and Google's Gemma 2 2B/9B. These models are trained to be efficient, often using techniques like quantization (reducing precision of weights) and knowledge distillation (training a small model to mimic a large one).

This shift means that instead of sending your data to a third-party server, you can run the AI locally. That has huge implications for privacy, latency, and cost. But it also introduces a new problem: where exactly should you run it? The answer isn't one-size-fits-all.

How It Works: The Hardware and Software Stack

Running an SLM requires a few key components:

  • Model weights: The trained parameters, usually stored in a format like GGUF or ONNX for local inference.
  • Inference engine: Software that loads the model and processes text, such as llama.cpp, ONNX Runtime, or TensorFlow Lite.
  • Compute hardware: The processor that does the math—CPU, GPU, or a neural processing unit (NPU).
  • Memory: RAM or VRAM to hold the model and its working data.

The key metric is tokens per second (TPS)—how many text pieces the model can generate per second. A human reads about 200-300 words per minute, so for chat you want at least 10-20 TPS. For batch processing (like summarizing thousands of documents), you might accept lower speed for higher throughput.

Quantization is critical. A 7B parameter model in 16-bit floats takes about 14GB of memory. But with 4-bit quantization (e.g., Q4_K_M), it drops to around 4GB—small enough to fit in many laptops or phones. The trade-off is a slight drop in accuracy, often imperceptible in practice.

How to Choose: Key Factors and a Decision Framework

Here’s a practical checklist to decide where your SLM should run:

  1. Privacy requirements: If you handle sensitive data (medical, legal, proprietary code), on-device or self-hosted is non-negotiable. No data leaves your control.
  2. Latency needs: For real-time apps (chatbots, voice assistants), on-device inference avoids network round-trips. A local model on a phone can respond in under 100ms, while cloud calls take 200-500ms plus network time.
  3. Hardware budget: Check your device's RAM and whether it has a GPU or NPU. A phone with 8GB RAM can run a 3B quantized model; a laptop with 16GB RAM and an integrated GPU can handle 7B; a desktop with a 12GB VRAM GPU can run 13B models comfortably.
  4. Power and heat: On-device inference drains battery. A phone running a model continuously might last only a few hours. Self-hosted servers can run on wall power indefinitely.
  5. Cost: Cloud API calls have per-token costs. Self-hosting has upfront hardware costs but zero marginal cost per query. For high-volume use, self-hosting wins.
  6. Scalability: If you need to serve many users simultaneously, a central server (even a small one) is easier to manage than distributing models to every device.
  7. A simple rule: if you need privacy and low latency, go on-device. If you need heavy compute or multi-user access, go server. If you need both, consider a hybrid—run a small model on-device for simple tasks and fall back to a larger cloud model when needed.

    Common Problems and How to Solve Them

    People often run into these issues when deploying SLMs:

    • Out-of-memory errors: The model doesn't fit in RAM/VRAM. Solution: use a smaller quantization (e.g., Q4 instead of Q8) or a smaller model. Also, close other apps.
    • Slow generation: CPU-only inference can be painfully slow. Solution: enable GPU acceleration (e.g., CUDA on NVIDIA, Metal on Apple Silicon, or Vulkan for cross-platform). Even a modest GPU gives 5-10x speedup.
    • Poor output quality: Small models sometimes hallucinate or produce repetitive text. Solution: use better sampling parameters (temperature 0.7, top-p 0.9), or fine-tune the model on your domain data.
    • Compatibility issues: Some engines don't support certain model formats. Solution: convert the model to a supported format (e.g., GGUF) using conversion scripts provided by the engine.

    One common misconception is that you need a powerful GPU to run any AI. In reality, many SLMs are optimized for CPU-only inference. For example, a 3B model in 4-bit can run at 10-20 TPS on a modern laptop CPU. It's not blazing fast, but it's usable.

    Comparison: On-Device vs. Self-Hosted Server vs. Cloud API

    FactorOn-DeviceSelf-Hosted ServerCloud API
    PrivacyHighest (data never leaves)High (you control the server)Low (data sent to provider)
    LatencyLowest (no network)Low (local network)Variable (internet)
    CostFree (after hardware)Electricity + hardwarePer-token fees
    ScalabilitySingle userMulti-user (limited)Unlimited (with cost)
    Offline capabilityYesYes (if server is local)No
    Hardware requirementPhone/laptop specServer/PC specNone (just internet)

    Note that self-hosting on a cloud VM (like a rented GPU instance) is a middle ground—you get privacy from your own data, but you still rely on a third-party for infrastructure. That's often easier to scale than physical hardware.

    Costs and Performance Trade-offs

    Let's talk numbers. Running a 7B Q4 model on a consumer GPU (e.g., RTX 3060 12GB) gives around 30-50 TPS. That's more than enough for real-time chat. The GPU itself costs a few hundred dollars, but if you run it 24/7, electricity adds up—maybe $10-20/month depending on rates.

    Cloud APIs like OpenAI's GPT-3.5-turbo cost about $0.0015 per 1K input tokens and $0.002 per 1K output tokens. For heavy use (say, 1 million tokens per day), that's $2-3/day—$60-90/month. A local GPU pays for itself in under a year if you run it continuously.

    But there's a hidden cost: your time. Setting up a local inference server requires some technical skill (installing software, downloading models, troubleshooting). If your time is valuable, the cloud API might be cheaper overall.

    Safety and Security Considerations

    Running SLMs locally has security benefits: you don't expose data to third parties. But it also introduces new risks:

    • Malicious models: Downloading a model from an untrusted source could contain hidden code that executes on your machine. Always download from official repositories (e.g., Hugging Face) and check checksums.
    • Prompt injection: If you build an app that processes untrusted text, a malicious prompt could cause the model to output harmful instructions. Use input sanitization and output filtering.
    • Model bias: Small models can reflect biases in their training data. Be aware of this if you deploy in sensitive contexts.
    • Data poisoning: If you fine-tune a model on your own data, ensure that data is clean and doesn't contain malicious examples.

    For on-device deployment, also consider physical security—if your device is stolen, the model and data are exposed. Use encryption and remote wipe capabilities.

    If SLMs don't fit your needs, consider:

    • Larger open-source models: Llama 3 70B or Mixtral 8x7B can run on high-end hardware (e.g., 2x24GB GPUs) and offer better quality, but require more resources.
    • Hybrid approaches: Use a small model on-device for simple tasks (e.g., keyword spotting) and a large model in the cloud for complex reasoning.
    • Distillation and pruning: You can compress a larger model to a smaller one that runs faster, but this requires training expertise.
    • Specialized hardware: Newer devices include NPUs (like Apple's Neural Engine or Qualcomm's Hexagon) that accelerate inference with low power. These are great for always-on assistants.

    The trend is clear: models are getting smaller and more efficient. In a few years, we may see 100B+ models running on phones. But for now, SLMs are the sweet spot for local AI.

    Frequently Asked Questions

    Can I run a small language model on my phone?

    Yes, modern smartphones with 6-8GB RAM can run 1-3B parameter models quantized to 4-bit. Apps like Ollama and MLCChat support on-device inference on iOS and Android. Expect 10-20 TPS, which is usable for chat but not for real-time translation.

    What is the best small model for a Raspberry Pi?

    For a Raspberry Pi 4/5 with 4-8GB RAM, look at models under 1B parameters, such as TinyLlama 1.1B or Phi-2 (2.7B, but only with heavy quantization). Expect 1-5 TPS—slow but functional for simple tasks like text classification.

    Do I need a GPU to run a small model?

    No. Many SLMs run on CPU alone, especially with quantization. A 3B model at Q4 can run at 5-10 TPS on a modern laptop CPU. A GPU speeds things up significantly but isn't strictly necessary.

    How do I choose between on-device and cloud API for my business?

    Consider your data sensitivity, usage volume, and latency requirements. If you process customer data that must stay private, on-device is safer. If you have sporadic usage, cloud API is cheaper. For constant high-volume, self-hosting is cost-effective.

    What is quantization and why does it matter?

    Quantization reduces the precision of a model's weights (e.g., from 16-bit to 4-bit), shrinking memory usage and speeding up inference, at the cost of a small accuracy drop. It's what makes running SLMs on consumer hardware possible.