Smart Systems for Home

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

Ollama Local Settings: GPU Context & Storage Guide

· 6 min read · Home Tech

In this article
  1. Background on Local AI Inference
  2. How It Works: The Role of Context Windows
  3. How to Choose Your Configuration
  4. Configuring Ollama for Local Privacy and Control
  5. Managing Storage and Model Files
  6. Common Problems and Troubleshooting
  7. Safety and Security Considerations
  8. Alternatives to Ollama
  9. Frequently Asked Questions

To keep Ollama strictly local and tune your GPU context and storage, you must configure the `ollama.conf` file to set environment variables like `OLLAMA_HOST` and `OLLAMA_KEEP_ALIVE`, while managing model files in the default system directories or custom paths via `OLLAMA_MODELS`. This ensures no data leaves your machine and allows precise control over how much VRAM and RAM are allocated for inference.

Background on Local AI Inference

Ollama is an open-source tool designed to run large language models (LLMs) locally on consumer hardware. Unlike cloud-based APIs such as ChatGPT or Claude, which send your prompts to remote servers, Ollama executes models directly on your CPU or GPU. This architecture provides significant privacy benefits, as your conversation history and data never leave your device. However, running these models requires careful management of system resources, particularly memory (RAM/VRAM) and storage space, as modern LLMs can be several gigabytes in size.

How It Works: The Role of Context Windows

The "context window" refers to the amount of information a model can process at once, including the prompt, previous conversation history, and the generated response. A larger context window allows the model to remember more details but requires exponentially more memory. When you ask Ollama to "tune GPU context," you are essentially adjusting how many tokens the model loads into your GPU's video memory (VRAM) or system RAM before processing begins.

If the context window exceeds available VRAM, Ollama will offload some layers to your system RAM. While this keeps the model running, it significantly slows down inference speed because RAM is much slower than VRAM. Therefore, tuning this setting involves balancing performance with the depth of context you need for your specific tasks.

How to Choose Your Configuration

Selecting the right settings depends on your hardware capabilities and use case. Here are the key factors to consider when configuring Ollama:

  • VRAM Capacity: Check your GPU’s total VRAM. If you have 8GB, you might fit a 7B parameter model fully in VRAM with a small context. For 16GB or more, you can handle larger models or wider contexts.
  • Model Size: Smaller models (e.g., 7B, 8B) require less memory but may lack reasoning depth. Larger models (e.g., 70B+) require massive resources and often rely heavily on CPU/RAM offloading if VRAM is insufficient.
  • Use Case: Simple chatbots benefit from smaller contexts. Code generation or document analysis requires larger contexts to maintain coherence across long inputs.

Configuring Ollama for Local Privacy and Control

To ensure Ollama remains local and to tune its behavior, you need to modify configuration files or use environment variables. Ollama does not have a graphical settings menu; instead, it relies on configuration files and command-line flags.

  1. Locate the Configuration File: On macOS and Linux, the primary configuration file is typically located at `~/.ollama/config.json` or `/etc/ollama/config.json`. On Windows, it is usually found in `%USERPROFILE%\.ollama\config.json`.
  2. Edit the JSON Config: Open the file in a text editor. You can add keys to control various aspects of the runtime.
  3. Set Host Binding: To restrict access, ensure `OLLAMA_HOST` is set to `127.0.0.1` (localhost). This prevents other devices on your network from accessing your local Ollama instance.
  4. Adjust Keep Alive: Set `OLLAMA_KEEP_ALIVE` to specify how long models stay loaded in memory after the last request. Setting this to `0` unloads models immediately, saving RAM/VRAM, while `-1` keeps them loaded indefinitely until Ollama shuts down.

For advanced users, environment variables can override config file settings. Common variables include `OLLAMA_NUM_PARALLEL` to manage concurrent requests and `OLLAMA_MAX_LOADED_MODELS` to limit how many models are resident in memory simultaneously.

Managing Storage and Model Files

Ollama stores downloaded models in a specific directory structure. By default, this is hidden within your user profile. Managing this storage is crucial for disk space optimization.

  • Default Locations: On Linux/macOS, models are stored in `~/.ollama/models`. On Windows, they are in `%USERPROFILE%\.ollama\models`.
  • Custom Storage Paths: If your primary drive is full, you can move the models directory to a secondary drive. Set the `OLLAMA_MODELS` environment variable to point to the new location (e.g., `D:\OllamaModels`). Ollama will then read and write new models to this path.
  • Cleanup: Use the `ollama rm ` command to delete unused models and reclaim storage space. Regularly auditing installed models helps prevent disk bloat.

Common Problems and Troubleshooting

Users often encounter issues related to memory exhaustion or incorrect configuration. Here are common scenarios and solutions:

  • Out of Memory Errors: If you see errors indicating insufficient VRAM, reduce the context length in your API calls or switch to a smaller quantized model (e.g., Q4_K_M instead of Q8_0).
  • Slow Performance: If inference is sluggish, check if Ollama is offloading to system RAM. Ensure your GPU drivers are up-to-date and that CUDA (NVIDIA) or ROCm (AMD) support is correctly configured.
  • Network Access Issues: If external tools cannot connect, verify that `OLLAMA_HOST` is set to `0.0.0.0` (if security permits) or that your firewall allows traffic on port 11434.

Safety and Security Considerations

Running local AI introduces unique security considerations. Since you are executing code (the model weights and inference engine) locally, trust in the source is paramount.

  • Source Verification: Only download models from trusted repositories like Hugging Face or official Ollama library tags. Malicious models could potentially contain embedded payloads, though this is rare.
  • Network Isolation: By binding to localhost, you protect your local Ollama instance from unauthorized network access. If you expose it to a LAN, implement strong authentication mechanisms.
  • Data Privacy: While Ollama itself does not phone home, ensure that any plugins or integrations you use also respect local-only constraints. Avoid using browser extensions that might transmit logs to third-party services.

Alternatives to Ollama

While Ollama is popular for its ease of use, other tools offer different approaches to local inference:

  • Llama.cpp: The underlying C++ library that powers Ollama. It offers granular control but requires command-line expertise.
  • LM Studio: A graphical interface for running GGUF models, suitable for users who prefer a visual UI over CLI.
  • Vicuna / Text Generation WebUI: Advanced interfaces for power users who want to fine-tune parameters extensively.

Frequently Asked Questions

How do I force Ollama to use only the CPU?

You can disable GPU acceleration by setting the environment variable `OLLAMA_NO_GPU=1` or by ensuring your CUDA/ROCm drivers are not detected. This forces all computations to run on the CPU, which is slower but useful for debugging or systems without compatible GPUs.

Can I store Ollama models on an external drive?

Yes. Set the `OLLAMA_MODELS` environment variable to the path of your external drive before starting Ollama. The application will automatically redirect all model downloads and reads to that location.

Why is my GPU usage low even when running a model?

This often happens when the model is too small to saturate the GPU or when the context window is very small, resulting in minimal computation per token. Additionally, if the model is partially offloaded to RAM, GPU utilization will appear fragmented. Try increasing the context length or loading a larger model.

Does Ollama save my chat history locally?

Ollama itself does not maintain a persistent chat history database by default. Each session is stateless unless you explicitly pass the conversation history in the prompt. However, some front-end applications built on top of Ollama (like Open WebUI) may store history locally in their own databases.

How do I update Ollama to the latest version?

On macOS, use Homebrew (`brew upgrade ollama`). On Windows, download the latest installer from the official website. On Linux, follow the installation script provided on the Ollama GitHub repository. Always restart the service after updating.