Running a Large Language Model (LLM) for code generation on a system with an NVIDIA GPU (4GB VRAM) using Ollama is a bit challenging, because most state-of-the-art LLMs require more than 4GB of VRAM to run efficiently — especially when fine-tuned for code. However, there are still several good models that can be quantized and run effectively under these constraints.
Below is a list of the best LLMs for coding that can be run via Ollama, or adapted to run on systems with limited GPU memory (4GB VRAM), often through quantization techniques like GGUF or FP16.
✅ Best LLMs for Coding (Runnable on Ollama with 4GB VRAM)
1. CodeLlama / CodeLlama-Python
2. StarCoder / StarCoder2
3. Phind-CodeLlama-34B-v2
4. Solar-Instruct (Code-focused variant)
5. Mistral-7B + Code-specific fine-tunes
6. WizardCoder
📌 Tips for Running on 4GB VRAM
- Use Quantized Models (Q4, Q5): These reduce model size at the cost of some accuracy.
- Use CPU Offloading: Some frameworks allow offloading layers to CPU.
- Prefer 7B Models: 13B+ models usually require more than 4GB even after quantization.
- Optimize Context Length: Shorter context = less VRAM usage.
- Use llama.cpp or GGUF-compatible builds if Ollama doesn’t yet support your desired model natively.
🔧 How to Check Available Models in Ollama
ollama list
You can pull models using:
ollama pull <model-name>
For example:
ollama pull codellama:7b-q5_K
ollama pull wizardcoder:7b-q4_0
🏁 Summary Table
| Model | Size | Code-Focused | Quantized? | Fits in 4GB VRAM |
|---|
| CodeLlama 7B | 7B | ✅ | ✅ | ✅ |
| StarCoder2 | 19B | ✅ | ✅ (unofficial) | ⚠️ (with Q4) |
| WizardCoder 7B | 7B | ✅ | ✅ | ✅ |
| Phind-CodeLlama | 34B | ✅ | ✅ | ⚠️ |
| Solar-Instruct | 10B | ✅ | ✅ | ✅ |
| Mistral 7B | 7B | ⚠️ | ✅ | ✅ |
📦 Bonus: Install Ollama with CUDA Support
Make sure you have CUDA drivers properly set up and install the GPU-accelerated version of Ollama:
If you want a recommendation tailored to your exact hardware or use case (e.g., Python-only, C++, etc.), feel free to ask!