TL;DR

DeepSeek v4 runs locally through Ollama with Open WebUI providing a chat interface. This guide covers installation, model-specific configuration for DeepSeek’s extended context window, and performance tuning for the model’s unique reasoning architecture.

Install Ollama first, then pull the DeepSeek v4 model:

curl -fsSL https://ollama.com/install.sh | sh
ollama pull deepseek-v4

DeepSeek v4 requires specific memory allocation due to its 128K token context window. Set OLLAMA_NUM_GPU to control GPU layer offloading – most systems benefit from full GPU utilization with this model’s architecture:

export OLLAMA_NUM_GPU=999
ollama serve

Deploy Open WebUI to interact with the model:

docker run -d -p 3000:8080 \
  -e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
  -v open-webui:/app/backend/data \
  ghcr.io/open-webui/open-webui:main

Access the interface at http://localhost:3000 and select deepseek-v4 from the model dropdown.

DeepSeek v4’s reasoning mode requires explicit activation in prompts. Unlike standard chat models, it performs better with structured reasoning requests. Configure system prompts in Open WebUI to include reasoning triggers like “think step-by-step” or “analyze this problem systematically.”

The model’s context handling differs from Llama-based models – it maintains coherence across longer conversations without aggressive summarization. Adjust Open WebUI’s context length settings to leverage the full 128K window for technical documentation analysis or large codebase reviews.

Caution: DeepSeek v4 generates commands and code snippets. Always review generated shell commands before execution, especially those involving system configuration or file operations. Test AI-generated configurations in isolated environments before deploying to production systems.

Understanding DeepSeek v4 Architecture and Requirements

DeepSeek v4 represents a significant architectural shift from earlier models, built on a mixture-of-experts (MoE) design that activates only a subset of parameters per token. This approach reduces memory bandwidth requirements during inference while maintaining strong reasoning capabilities. The model comes in several quantization levels through Ollama’s library, with the Q4_K_M variant offering the best balance between quality and resource usage for most self-hosted deployments.

The base DeepSeek v4 model requires substantial VRAM allocation. For the 236B parameter version with Q4_K_M quantization, expect to allocate at least 140GB of combined system and GPU memory. Most homelab setups will need to offload layers strategically between GPU and CPU memory using Ollama’s OLLAMA_NUM_GPU environment variable.

# Example: Offload 35 layers to GPU on a 24GB card
export OLLAMA_NUM_GPU=35
ollama run deepseek-v4:236b-q4_K_M

The smaller 67B variant runs comfortably on systems with 48GB total memory, making it more accessible for typical self-hosted environments. Test different OLLAMA_NUM_GPU values to find optimal performance – higher values improve speed but require more VRAM.

Context Window Handling

DeepSeek v4 supports extended context lengths up to 128K tokens, but this dramatically increases memory consumption during inference. For typical chat applications through Open WebUI, limiting context to 32K tokens provides responsive performance without exhausting available memory. Configure this in Open WebUI’s model settings after initial deployment.

Caution: Always validate memory availability before pulling large models. Running ollama pull deepseek-v4:236b-q4_K_M will download approximately 140GB of data. Monitor disk space in your OLLAMA_MODELS directory and ensure adequate bandwidth for the initial download.

Installing Ollama for DeepSeek v4

DeepSeek v4 requires Ollama as the runtime engine to serve the model locally. The installation process is straightforward but requires attention to system requirements given DeepSeek v4’s larger context window and reasoning capabilities.

Install Ollama using the official script:

curl -fsSL https://ollama.com/install.sh | sh

Verify the installation by checking the service status:

systemctl status ollama

The service should start automatically and listen on port 11434. Test connectivity:

curl http://localhost:11434/api/tags

GPU Configuration for DeepSeek v4

DeepSeek v4’s extended reasoning mode benefits significantly from GPU acceleration. Configure GPU allocation before pulling the model:

export OLLAMA_NUM_GPU=1

For systems with multiple GPUs, specify the count to distribute the model layers. DeepSeek v4’s architecture uses more layers than typical models, so proper GPU allocation reduces inference latency during complex reasoning tasks.

Pulling DeepSeek v4

Download the model from Ollama’s library:

ollama pull deepseek-v4

For the quantized version optimized for consumer hardware:

ollama pull deepseek-v4:q4_K_M

The download size varies by quantization level. The q4_K_M variant balances performance with memory usage, typically requiring 16-24GB RAM depending on context length.

Verification

Test the model with a reasoning prompt:

ollama run deepseek-v4 "Explain the difference between mmap and direct I/O for model loading"

Caution: Always validate AI-generated system commands before execution. DeepSeek v4 can produce plausible but incorrect technical instructions. Cross-reference configuration recommendations with official documentation.

Monitor resource usage during initial runs to ensure your system handles the model’s memory footprint, especially when using extended context windows beyond 32K tokens.

Deploying Open WebUI with DeepSeek Integration

Open WebUI connects to your Ollama instance automatically when both run on the same host. Deploy the container with network access to Ollama’s API:

docker run -d \
  --name open-webui \
  -p 3000:8080 \
  --add-host=host.docker.internal:host-gateway \
  -e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
  -v open-webui:/app/backend/data \
  ghcr.io/open-webui/open-webui:main

The --add-host flag ensures the container can reach Ollama running on your host system. Access the interface at http://localhost:3000 and create an admin account on first launch.

DeepSeek v4 Model Selection

Navigate to Settings > Models after logging in. Open WebUI automatically discovers models from your Ollama instance. Select deepseek-r1:latest from the dropdown. DeepSeek v4’s extended context window requires specific configuration – set the context length to 32768 tokens in the model settings panel to leverage its full reasoning capabilities.

For multi-turn conversations where DeepSeek’s chain-of-thought reasoning shines, enable “Keep Alive” in Advanced Settings. This maintains model state between requests, critical for DeepSeek’s iterative problem-solving approach.

Testing DeepSeek-Specific Features

DeepSeek v4 excels at mathematical reasoning and code generation. Test with a complex query:

Explain the time complexity of quicksort with a working Python implementation, then optimize it for nearly-sorted arrays.

DeepSeek’s response will include explicit reasoning steps before code output – a behavior distinct from standard instruction-following models. Monitor response times in the UI; DeepSeek’s reasoning phase adds latency compared to direct-answer models.

Caution: Always review AI-generated code before execution. DeepSeek may suggest system commands or configurations that require validation against your specific environment and security requirements.

DeepSeek v4 Model Configuration and Context Handling

DeepSeek v4 requires specific configuration to leverage its extended context window and reasoning capabilities. The model supports up to 128K tokens of context, significantly more than earlier versions, but this requires careful memory management on local hardware.

Pull the DeepSeek v4 model and configure context limits through Ollama’s Modelfile system:

ollama pull deepseek-v4
ollama show deepseek-v4 --modelfile > Modelfile.deepseek

Edit the Modelfile to adjust context parameters:

FROM deepseek-v4
PARAMETER num_ctx 32768
PARAMETER num_gpu 35
PARAMETER num_thread 8

The num_ctx parameter controls context window size. Start with 32768 tokens for systems with 24GB VRAM. Increase to 65536 or higher only if you have 48GB+ VRAM available. Create the custom model:

ollama create deepseek-v4-extended -f Modelfile.deepseek

Reasoning Mode Activation

DeepSeek v4 includes a reasoning mode that generates intermediate thinking steps before final answers. Enable this in Open WebUI by setting system prompts that explicitly request step-by-step reasoning:

You are DeepSeek v4 in reasoning mode. Show your thinking process before providing final answers. Use <thinking> tags for internal reasoning.

Caution: AI-generated configuration suggestions may recommend non-existent parameters. Always verify parameter names against official Ollama documentation before applying them to production systems.

Memory Optimization

For systems with limited VRAM, reduce num_gpu to offload layers to CPU:

OLLAMA_NUM_GPU=20 ollama run deepseek-v4-extended

Monitor memory usage during inference. DeepSeek v4’s architecture benefits from keeping attention layers on GPU while offloading feed-forward layers to system RAM when necessary.

Verification and Testing

Start by confirming Ollama responds on port 11434:

curl http://localhost:11434/api/tags

This returns JSON listing all pulled models. If DeepSeek v4 appears in the response, the model is available for inference.

Test direct inference through Ollama’s API:

curl http://localhost:11434/api/generate -d '{
  "model": "deepseek-v4",
  "prompt": "Explain quantum entanglement in two sentences.",
  "stream": false
}'

DeepSeek v4’s response should demonstrate its reasoning capabilities with structured, coherent output. Compare response quality against smaller models to verify you’re actually using the v4 variant.

Open WebUI Integration Check

Access Open WebUI at http://localhost:3000 and navigate to Settings > Models. DeepSeek v4 should appear in the model dropdown. Create a new chat and send a multi-turn conversation to test context retention – DeepSeek v4 handles extended context windows better than many alternatives, so test with conversations exceeding 8,000 tokens.

Try a reasoning-heavy prompt:

Analyze the trade-offs between microservices and monolithic architectures 
for a team of 12 engineers building a SaaS platform. Consider deployment 
complexity, debugging overhead, and operational costs.

DeepSeek v4 should provide structured analysis with clear reasoning chains. If responses seem generic or lack depth, verify you selected the correct model variant in Open WebUI’s interface.

Caution: Always validate AI-generated architectural recommendations against your specific requirements. DeepSeek v4 provides reasoning frameworks, not production-ready decisions.

Performance Baseline

Monitor response latency for a standard prompt:

time curl http://localhost:11434/api/generate -d '{"model":"deepseek-v4","prompt":"List five Linux security hardening steps.","stream":false}'

Typical response times range from 2-8 seconds on modern GPUs, depending on prompt complexity and available VRAM. Significantly longer delays indicate resource constraints or misconfigured OLLAMA_NUM_GPU settings.

Performance Optimization for DeepSeek v4

DeepSeek v4’s 671B parameter architecture demands careful resource allocation to achieve acceptable inference speeds on consumer hardware. The model’s mixture-of-experts design activates roughly 37B parameters per token, making GPU memory management critical for local deployments.

Set OLLAMA_NUM_GPU to control layer offloading. For systems with 24GB VRAM, start with 32 layers offloaded:

export OLLAMA_NUM_GPU=32
systemctl restart ollama

Monitor GPU utilization with nvidia-smi during inference. If memory usage exceeds 90%, reduce the layer count by 4-8 layers. Systems with 16GB VRAM typically handle 24-28 layers effectively.

Context Window Tuning

DeepSeek v4 supports up to 128K tokens of context, but longer contexts increase memory pressure exponentially. For most local use cases, limit context to 32K tokens in Open WebUI’s model settings. Navigate to Settings > Models > deepseek-v4 and set “Context Length” to 32768.

For extended reasoning tasks requiring full context, enable disk-based KV cache offloading:

mkdir -p /var/lib/ollama/cache
export OLLAMA_MODELS=/var/lib/ollama/cache

This trades inference speed for memory capacity – expect 2-3x slower token generation with full 128K context on systems with limited VRAM.

Batch Size and Concurrency

DeepSeek v4’s sparse activation pattern benefits from batch processing. In Open WebUI, enable request batching under Admin Settings > Advanced. Set “Max Concurrent Requests” to 2 for single-GPU systems, 4 for dual-GPU configurations.

Caution: Always validate AI-generated optimization commands against official Ollama documentation before applying them to production systems. Incorrect memory settings can cause system instability or model crashes.

Test inference speed with ollama run deepseek-v4 "Explain quantum entanglement" and measure tokens per second in the output. Typical consumer GPUs achieve 8-15 tokens/second with optimized settings.