You're building something cool, and suddenly your OpenAI bills hit $300/month because your feature flags turned into feature spam. Been there. This is how to run models on your machine and stop throwing money at API providers.
Why Local Models Actually Make Sense Now
Six months ago, local models were "interesting." Now they're legitimately fast and capable. Ollama, LM Studio, and Hugging Face models have leveled up, and honestly, they're worth the setup time if you're hitting API rate limits or costs.
The math: A single GPU (RTX 4090 or even a decent RTX 4070) can run inference at speeds comparable to API calls. You own the model, own your data, and don't worry about tokens or rate limits.
Getting Started: The Fast Path
1. Install Ollama (Seriously, Just Use This)
Ollama is like Docker but for LLMs. Dead simple.
# macOS
brew install ollama
# Linux
curl https://ollama.ai/install.sh | sh
# Windows: Download installer from ollama.ai
Then pull a model:
ollama pull mistral # ~4GB, solid all-around performer
ollama pull neural-chat # Optimized for conversation, smaller footprint
ollama pull llama2 # Meta's model, good for everything
That's literally it. Models sit in ~/.ollama/models/ and are ready to use.
2. Talk to It from Your Code
Once a model is pulled, Ollama starts a local server on http://localhost:11434. Your code can just talk to it like an API:
// Node.js example using fetch
const response = await fetch('http://localhost:11434/api/generate', {
method: 'POST',
body: JSON.stringify({
model: 'mistral',
prompt: 'explain REST APIs in one sentence',
stream: false
})
});
const data = await response.json();
console.log(data.response);
# Python using requests
import requests
import json
response = requests.post('http://localhost:11434/api/generate', json={
'model': 'mistral',
'prompt': 'what are microservices?',
'stream': False
})
print(response.json()['response'])
Literally just HTTP requests. No SDK needed.
3. For Chat-Style Interactions
If you want a ChatGPT-like interface (messages with roles), Ollama has that too:
curl http://localhost:11434/api/chat -d '{\n "model": "mistral",\n "messages": [\n { "role": "user", "content": "write a function to validate emails" }\n ],\n "stream": false\n}'
Model Selection (Don't Overthink It)
- Mistral 7B: All-around solid. Fast, good at coding and reasoning. Start here.
- Neural Chat: Smaller (~8GB), specifically trained for conversations.
- Llama 2 13B: Slightly larger but more capable. Good if you have the VRAM.
- Deepseek Coder: If you're doing heavy code generation. Actually impressive.
For comparison: Most fit in 16GB RAM. You don't need a $2000 GPU—even integrated graphics on newer chips can handle inference, just slower.
Real World: Where This Pays Off
Local models rule when:
- You're doing bulk processing (summarizing 1000 documents? Run it locally overnight)
- Your feature needs instant feedback (autocomplete in an editor—no latency)
- You're prototyping and iterating fast (no rate limits, iterate forever)
- Your data is sensitive (medical records, internal docs—stays on your machine)
- You're in a region with expensive APIs
APIs still win when:
- You need cutting-edge performance (Claude 3.5, GPT-4 still beat local models)
- You're scaling to thousands of concurrent users (let someone else handle the infrastructure)
- You need reliability guarantees and uptime SLAs
Gotchas and Real Talk
VRAM is the bottleneck. A 7B model needs ~15-20GB to load and run comfortably. If your GPU doesn't have it, you'll be swapping to RAM (slow). Check before you get excited.
Startup time. First inference takes a second or two. Not a deal-breaker, but note it.
Performance varies by model size. A 70B model will give better answers but needs proportionally more resources. 7B is the sweet spot for most of us.
Running on CPU is possible but slow. You can run models on CPU-only machines, but expect 2-5 second response times. GPU is genuinely better here.
Next Steps
- Install Ollama, pull a model
- Write 10 lines of code to call it from your app
- See what changes
Once you've run a model locally, the economics become obvious. For most side projects and internal tools, local models save money and give you more control.
Want to level up your AI workflow faster? Subscribe to LearnAI Weekly for practical guides on tools, models, and strategies that actually work. No fluff, just what's useful.
Top comments (0)