DeepSeek R1 & Local LLMs: Running, Fine-Tuning & Deploying with Ollama
What You Will Master in This Tutorial
- Understand Reinforcement Learning for reasoning models (DeepSeek R1).
- Run quantized GGUF models on consumer GPUs using Ollama.
- Integrate local LLM endpoints into Python microservices via the OpenAI SDK.
- Deploy vLLM in Docker containers for production enterprise inference.
1. Running DeepSeek R1 with Ollama in Seconds
DeepSeek R1 revolutionized open-weights AI by demonstrating that reinforcement learning reasoning can match closed frontier models. With Ollama, you can download and run quantized versions directly on your workstation.
BASH
# Download and start DeepSeek R1 distilled 8B model
ollama run deepseek-r1:8b
# Or run the larger 14B / 32B model on high-VRAM machines
ollama run deepseek-r1:14b
Note: An 8B model requires only ~6GB of VRAM and runs smoothly on Apple Silicon M-series or NVIDIA RTX GPUs.
Advertisement
Cloud Infrastructure & High-Performance Dev Environments
2. Querying Ollama via Python and Streaming Responses
Ollama exposes an OpenAI-compatible HTTP API at http://localhost:11434/v1, allowing drop-in replacement with standard client SDKs.
PYTHON
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:11434/v1",
api_key="ollama" # Required but ignored locally
)
response = client.chat.completions.create(
model="deepseek-r1:8b",
messages=[
{"role": "system", "content": "You are a C# and Python expert."},
{"role": "user", "content": "Explain how virtual threads differ from async/await."}
],
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="", flush=True)
Note: Using local models guarantees 100% data privacy and zero API token costs.
Knowledge Check: Test Your Understanding
1. What is the primary breakthrough introduced by DeepSeek R1?
Frequently Asked Questions
Can I connect Ollama to Cursor or VS Code?
Yes! Extensions like Continue.dev, Roo Code, and Cline allow using http://localhost:11434 as your primary coding backend.