404human Projects Writing Build logs Learning Books Progress
Rust · Zola
zsh · 404human@dev:~ Tab complete · ↑↓ history · type help

Running local LLMs with Ollama and Qwen: guide

How to run local LLMs on a laptop with Ollama and Qwen—real RAM and quantization math, tool-calling gotchas, and when local beats cloud APIs.

Published
Read time
5 min read
Kind
guide
Topics

Running a local LLM on a laptop with Ollama and Qwen used to be a novelty demo. Today, a 4-bit quantized 8B model fits comfortably in ~5 GB of RAM, runs completely offline with zero per-token bills, and supports structured tool calling—making it genuinely useful for private dev helpers, classification, offline drafting, and learning how agent harnesses work.

It is also easy to overestimate what a local 8B model can replace. After running qwen3:8b (Q4_K_M, 4.6 GB weights) locally on a 32 GB Mac M2 Pro alongside cloud models across our repos (the model never called my function), here is the practical guide to sizing memory, avoiding Ollama’s subtle defaults, wiring tool calling cleanly, and knowing when local actually saves money.

Hardware and RAM sizing (weights are only half the bill)

The number-one mistake when choosing a local model is checking only the weight file size. Your machine has to hold model weights + KV cache + OS/editor overhead simultaneously:

Laptop RAM / GPU VRAMComfortable model size (Q4_K_M)Practical context (num_ctx)Realistic use cases
16 GB unified RAM7B–9B (~4.6–5.5 GB weights)4K–16K tokensLocal CLI helpers, summarization, narrow tool calling, learning labs
32 GB unified RAM14B–32B (~9–19 GB weights) or 8B with large context16K–32K tokensStronger coding CLI (qwen3-coder / qwen3), multi-file drafting, local RAG
64 GB+ unified RAM32B–70B quantized32K+ tokensSerious offline coding and private document analysis

Why context length matters so much on a laptop: on an 8B model, a 32,000-token conversation can use ~4.2 GB of KV cache alone—nearly matching the weight file itself (KV cache explained). If your machine swaps weights or KV cache to SSD, streaming speed collapses from 40 tokens/sec to 2 tokens/sec.

Getting started cleanly with Ollama and Qwen

Install Ollama, pull a Qwen model, and test it locally:

# Pull an 8B Q4_K_M Qwen model (~4.6 GB download)
ollama pull qwen3:8b

# Quick interactive check in the terminal
ollama run qwen3:8b "Explain the difference between TCP and UDP in 3 bullets."

Two important endpoints are exposed locally once Ollama is running:

  • Native Ollama API: http://localhost:11434/api/chat (supports Ollama-specific options like options.num_ctx and returns raw thinking fields cleanly).
  • OpenAI-compatible API: http://localhost:11434/v1/chat/completions (lets you point standard OpenAI SDKs, our 90-line framework-free agent, or CLI tools like Qwen CLI straight at localhost with zero code rewrites).

Four local LLM gotchas we actually hit

1. Ollama’s default num_ctx silently truncates long prompts

Many Ollama models default to a small context window (such as 4,096 tokens) even when the underlying model supports 32K+. If your system prompt + tool schemas + pasted file exceeds num_ctx, Ollama silently drops tokens from the start—erasing your system prompt without throwing an error (what is an LLM context window).

Fix: Set options.num_ctx explicitly in your request (for example 16384), and monitor prompt_eval_count in the response.

2. Subtle tool-calling payload differences (tool_name vs tool_call_id)

When calling Ollama’s native /api/chat directly, the tool reply message expects tool_name alongside role: "tool", whereas OpenAI’s /v1/chat/completions endpoint expects tool_call_id. Using the OpenAI-compatible /v1 endpoint keeps one wire format across local and cloud models, while native /api/chat gives finer control over options.num_ctx and keep_alive.

3. Smaller local models need smaller tool menus and stricter error envelopes

In our local qwen3:8b experiments:

  • A tight enum in a tool schema pushed the model to pick the wrong project name when the real one wasn’t listed. Accepting a plain string and returning {"ok": false, "error": "not_found"} eliminated the silent mis-selection.
  • In our dishonest-clock test (the model never called my function), feeding a fake "03:14 on Mars" tool output made the 8B model reject the tool output and emit a placeholder string ([Insert accurate time here])—a great reminder that you must validate outputs and separate what the harness executed from what the model guessed.
  • Keep local agent tool lists tight (3–6 clear tools, concise descriptions, bounded output bytes).

4. Local isn’t “free” if it fails the job

Running locally eliminates API bills, not engineering cost. As we noted in the assistant failed before the model got a turn, the metric that matters is cost per acceptable result—including retries, fallback calls, latency, and human cleanup. Measure your local model on a held-out LLM evaluation suite before assuming it replaces a cloud model on a workflow.

When local LLMs beat cloud APIs (and when they don’t)

  • Use a local LLM (Ollama / Qwen / on-device) when: data cannot leave the machine (private notes, local voice transcripts like Personal Voice Agent, sensitive logs), you need offline operation, you are building high-volume narrow classifiers/extractors, or you are learning and debugging tool loops without burning API credits.
  • Use a frontier cloud model when: you need complex multi-file architecture reasoning across huge repositories, high first-try reliability on subtle security/concurrency reviews, or low-latency concurrency for many simultaneous users without managing GPU servers.
  • Best hybrid pattern: Route simple local tasks, privacy-sensitive preprocessing, and dev harness tests to a local Qwen model, and reserve frontier cloud models for hard reasoning and independent code reviews.

Frequently asked questions

Is Q4_K_M quantization good enough for coding and tool calling? For most laptops, Q4_K_M is the best balance between memory footprint, speed, and quality. Dropping to 2-bit or 3-bit quantization noticeably degrades JSON schema adherence and code syntax; moving up to Q8_0 roughly doubles memory usage for modest gains.

Can I run Qwen Code CLI or an AI agent completely offline? Yes. Point the client’s OpenAI-compatible base URL at http://localhost:11434/v1 with a pulled Qwen model and keep your tools local (stdio MCP servers or local functions). Just ensure num_ctx is large enough for your system prompt and files, and keep tool outputs truncated.

Why did my local LLM suddenly get 10× slower mid-conversation? Either the growing KV cache pushed total memory over physical RAM into swap, or Ollama unloaded/reloaded the model after its keep_alive timeout expired. Lower num_ctx slightly, trim old tool outputs, or step down one model size so everything stays in RAM.

Related reading