Set Up a Local Offline Coding Assistant with Ollama
This article walks through deploying a local, offline AI coding assistant using Ollama and the Qwen2.5-Coder-3B model. It covers hardware requirements, model selection rationale, installation steps, storage and runtime configuration, baseline testing, and HTTP API invocation. You'll learn how to verify your hardware, install Ollama, configure model storage paths, and measure generation speed to ensure a stable and private coding experience entirely on your machine.
1. Check Your Hardware
Before deployment, check your GPU memory (VRAM) and system memory (RAM). These two factors determine whether the model runs smoothly. The table below shows two reference configurations for the Q4_K_M quantized 3B model.
| Tier | GPU | RAM | Experience |
|---|---|---|---|
| Minimum | Dedicated GPU with 6GB VRAM | 16GB | Model fits entirely in VRAM; sufficient for everyday code completion and Q&A |
| Recommended | 8GB VRAM or more | 32GB | Supports longer context windows; remains stable even with multiple apps competing for resources |
You can run without a dedicated GPU, in which case the model falls back to CPU and system memory. Speed will drop noticeably, which is acceptable for occasional testing or feature verification but not suitable for sustained high-frequency use.
The Q4_K_M model file is approximately 1.9GB. Once loaded, runtime footprint typically sits around 3GB, increasing with longer context lengths. These numbers vary based on your operating system, GPU drivers, and context window. The most reliable approach is to test it yourself using the --verbose flag in Section 5.
2. Why Qwen2.5-Coder-3B
This article uses a code-specialized model from the Qwen (Tongyi Qianwen) team with roughly 3 billion parameters. It is a dense model, meaning every inference uses all parameters. Some models advertised as “sparsely activated” have a different architecture. When selecting a model, be careful to distinguish the two, or you may miscalculate hardware requirements.
The model natively supports a 32K context window, suitable for reading moderately sized code files. The official technical report provides benchmark scores on HumanEval, MBPP, and other coding benchmarks, along with comparisons against models of similar size. For formal model selection, we recommend reviewing the original report and running side-by-side tests with your own code samples.
3. Install Ollama and Verify
Ollama is an open-source local model runtime that provides both a command-line interface and a local HTTP API. Choose the installation method based on your operating system:
- Windows: Run
winget install --id Ollama.Ollama -ein PowerShell, or download the installer from the official website. - macOS: Run
brew install ollama, or download the application from the official website. - Linux: We recommend downloading the installation script, reviewing its contents, and then executing it. Do not pipe remote scripts directly into a shell.
curl -fsSL https://ollama.com/install.sh -o install.shless install.shsudo sh install.sh
After installation, run the following two commands to verify:
ollama --versioncurl http://127.0.0.1:11434/api/version
The second command should return a JSON response similar to {"version":"x.y.z"}, confirming the background service is listening on port 11434. If the connection is refused, run ollama serve in a separate terminal, or check the system service status.
4. Configure Storage Path and Runtime Parameters
Ollama uses environment variables to control storage location and service behavior. Common variables include:
OLLAMA_MODELS: Directory for storing model files.OLLAMA_HOST: Listen address and port. Default is127.0.0.1:11434, which only allows local access.OLLAMA_KEEP_ALIVE: Duration models stay resident in memory. Default is approximately 5 minutes. On shared machines, setting this too long will hold resources unnecessarily; adjust it shorter as needed.OLLAMA_NUM_PARALLEL: Number of simultaneous requests a model can handle.
Model files are large and are stored on the system disk by default. On Linux, the service is managed by systemd. To change the storage directory, follow these steps. First, open the service editor:
sudo systemctl edit ollama.service
In the editor, write and save:
[Service]Environment="OLLAMA_MODELS=/data/ollama/models"
Then create the directory, grant permissions for the service user, and restart the service:
sudo mkdir -p /data/ollama/modelssudo chown -R ollama:ollama /data/ollama/modelssudo systemctl daemon-reloadsudo systemctl restart ollama
On Windows, add OLLAMA_MODELS to your system environment variables, then exit Ollama from the system tray and restart it.
5. Pull the Model and Run a Baseline Test
Execute the following commands to download the model and enter the interactive prompt:
ollama pull qwen2.5-coder:3bollama run qwen2.5-coder:3b
The initial pull downloads about 1.9GB; the time depends on your network. During the pull, Ollama verifies the checksum of each file layer. After the download completes, ollama list shows the model, and ollama show qwen2.5-coder:3b displays the parameter count and context length. If tags change, use these two commands again to confirm the actual model name.
Once in the interactive prompt, ask the following three categories of questions and record the answers as a baseline for later tuning:
- Code generation: Write a Python function that reads a CSV file and calculates the average of each column.
- Code explanation: Explain what a piece of code containing recursion and closures does.
- Bug fixing: Paste a code snippet that throws an error, along with the error message, and ask for the cause and a fix.
To obtain performance data, add the --verbose flag when running. After the command finishes, it displays the eval rate, measured in tokens generated per second.
6. Invoke the HTTP API
The generation endpoint is POST /api/generate. Key fields include:
model: Specifies the model name.prompt: The input text.stream: Set tofalseto return the complete response at once.
