TROUBLESHOOTING: Common Issues & Solutions¶
Solutions to the most common problems encountered during learning
Docker Issues¶
Issue: Container won't start¶
Symptoms:
Error: Cannot connect to the Docker daemon
docker: Error response from daemon: ...
Solutions:
-
Check if Docker is running:
# Linux/Mac sudo systemctl status docker # Windows # Check Docker Desktop is running -
Restart Docker daemon:
sudo systemctl restart docker -
Check if port is already in use:
# Linux/Mac netstat -tulpn | grep ${PORT} lsof -i :${PORT} # Windows netstat -ano | findstr ${PORT}
Solution: Change the port mapping or stop the conflicting service.
Issue: Out of Memory (OOM)¶
Symptoms:
ERROR: for <container> Cannot start service ...
OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused "write /proc/self/attr/keycreate: invalid argument"
Solutions:
-
Increase Docker memory limit (Docker Desktop):
- Settings → Resources → Memory → Increase to 8GB+
-
Check container memory usage:
docker stats -
Limit container memory:
docker run -m 512m myapp
Issue: GPU not accessible in container¶
Symptoms:
Error: could not select device driver
nvidia-smi not found
Solutions:
-
Install NVIDIA Container Toolkit:
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \ sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ sed "s#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#" | \ sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit sudo nvidia-ctk runtime configure --runtime=docker sudo systemctl restart docker -
Test GPU container:
docker run --rm --gpus all nvidia/cuda:13.0.2-base-ubuntu24.04 nvidia-smi -
Check GPU availability on host:
nvidia-smi -
Docker Commands - Containers, images, volumes and networking in one page.
- Virtualization and GPU Passthrough - the Hypervisor RAM Ledger, the Passthrough Gate Chain, and the Multi-GPU Scaling Wall - The hypervisor RAM ledger, the IOMMU group verdict, the passthrough gate chain, the Thunderbolt tunnel bill, the kernel module ledger, the multi-GPU scaling wall, and the NCCL peer wall.
LLM Issues¶
Issue: Model download fails¶
Symptoms:
Error: failed to load model
Connection timeout during download
Solutions:
-
Check internet connection and proxy settings:
export HTTP_PROXY=http://proxy.example.com:8080 export HTTPS_PROXY=http://proxy.example.com:8080 -
Use mirror for Hugging Face models:
import os os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com' from transformers import AutoModel model = AutoModel.from_pretrained("model-name") -
Download model manually:
# Install git-lfs git lfs install # Clone model repo git clone https://huggingface.co/model-name
Issue: CUDA out of memory¶
Symptoms:
RuntimeError: CUDA out of memory. Tried to allocate XYZ MiB
Solutions:
-
Reduce batch size:
batch_size = 1 # Reduce from larger value -
Enable gradient checkpointing:
model.gradient_checkpointing_enable() -
Use 4-bit quantization:
from transformers import AutoModelForCausalLM from transformers import BitsAndBytesConfig bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.float16 ) model = AutoModelForCausalLM.from_pretrained( model_name, quantization_config=bnb_config ) -
Reduce sequence length:
max_length = 512 # Reduce from 2048 or 4096 -
Clear CUDA cache:
import torch torch.cuda.empty_cache()
Issue: Slow inference¶
Symptoms:
- Model takes >10 seconds per token
- GPU utilization is low
Solutions:
-
Use vLLM or TGI instead of raw PyTorch:
vllm serve model-name --gpu-memory-utilization 0.9 -
Enable Flash Attention:
from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained( model_name, attn_implementation="flash_attention_2" ) -
Batch requests:
# Process multiple prompts at once outputs = model.batch_generate(prompts) -
Use CPU offloading for large models:
from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained( model_name, device_map="auto", offload_folder="offload" ) -
Local Inference with llama.cpp & Ollama - GGUF downloads, llama.cpp build/serve flags, Ollama run and Modelfile customization, and offload tuning for local machines.
- Quantization Formats & Methods - The bpw block arithmetic behind Q4_0/Q4_K, the three GGUF families, and the EXL2/AWQ/GPTQ GPU-only map.
- vLLM Serving & Inference - Serving, quantization, parallelism and tuning flags for the vLLM inference server.
- Flash Attention - The memory-hierarchy argument, the online-softmax block update, the FA1-FA2-FA3 ladder, the three enablement paths, and the when-not rules.
RAG Issues¶
Issue: Poor retrieval quality¶
Symptoms:
- Retrieved documents not relevant to query
- Answers are generic or unhelpful
Solutions:
-
Improve chunking strategy:
# Use smaller chunks with overlap chunker = DocumentChunker( chunk_size=256, # Smaller chunks chunk_overlap=50, method="recursive" # Try "semantic" instead ) -
Try different embedding models:
# Better quality models from sentence_transformers import SentenceTransformer model = SentenceTransformer('all-mpnet-base-v2') # Better but slower model = SentenceTransformer('all-MiniLM-L6-v2') # Faster but simpler -
Add re-ranking:
from sentence_transformers import CrossEncoder reranker = CrossEncoder('ms-marco-MiniLM-L-6-v2') reranked = reranker.rank(query, results, top_k=5) -
Use hybrid search (keyword + semantic):
from qdrant_client import QdrantClient from qdrant_client.models import QueryRequest # Combine BM25 and vector search results = qdrant.query_batch_points( collection_name="docs", requests=[ QueryRequest( query=vector, limit=10, with_payload=True ) ] )
Issue: Qdrant connection fails¶
Symptoms:
ConnectionError: Failed to connect to Qdrant
urllib3.exceptions.MaxRetryError
Solutions:
-
Check if Qdrant is running:
curl http://localhost:6333/ -
Check Docker logs:
docker logs qdrant -
Verify port is not blocked by firewall:
# Linux sudo ufw allow 6333/tcp # Check if port is listening netstat -tulpn | grep 6333 -
Check Qdrant health:
curl http://localhost:6333/health -
Retrieval Strategies - the Two-Channel Fusion, the Rerank Funnel, and the Diversity Dial - BM25 and the dense channel, RRF and the alpha dial joining them, the cross-encoder rerank funnel, the MMR diversity dial, and the provenance boost.
- RAG Systems - Chunking, embedding, retrieval and generation parameters at a glance.
- Semantic Vectors - the HNSW Ledger, the Recall Dial, and the Truncation Contract - What the vector is, how cosine and dot measure closeness, the HNSW walk with its ef dial, the MRL truncation contract, and the anisotropy trap.
- Vector Databases - the RAM Ledger, the Quantile Trap, and the Rescore Ladder - The RAM ledger arithmetic, the distance trio, the SQ quantile trap, binary and product quantization floors, the oversample x rescore ladder, and the snapshot RPO bill.
Fine-Tuning Issues¶
Issue: Training loss not decreasing¶
Symptoms:
- Loss stays flat or increases
- Model doesn't learn
Solutions:
-
Check learning rate:
# Try different learning rates learning_rate = 2e-4 # Common starting point learning_rate = 1e-4 # Lower if unstable learning_rate = 5e-4 # Higher if too slow -
Increase dataset size:
- 10-100 samples for testing
- 1000+ samples for real fine-tuning
-
Check data quality:
# Remove duplicates data = list(set(data)) # Filter too short samples data = [d for d in data if len(d['text']) > 100] # Balance classes from collections import Counter print(Counter([d['label'] for d in data])) -
Reduce batch size if memory constrained:
per_device_train_batch_size = 1 gradient_accumulation_steps = 8 # Effective batch = 1 * 8 = 8
Issue: LoRA adapters not loading¶
Symptoms:
ValueError: Cannot load PeftModel
KeyError: 'base_model.model.model.layers'
Solutions:
-
Check base model compatibility:
# Must use same base model as during training base_model = "Qwen/Qwen3-8B" -
Verify PEFT version:
uv pip show peft # Should be >= 0.7.0 uv pip install --upgrade peft -
Load adapter explicitly:
from transformers import AutoModelForCausalLM from peft import PeftModel model = AutoModelForCausalLM.from_pretrained(base_model) model = PeftModel.from_pretrained(model, adapter_path) -
Advanced Optimization - the Optimizer Memory Ledger, the Schedule Arc, and the Failure Toolbox - The optimizer memory ledger, Adam's scale-free first step, the warmup-decay schedule arc, the failure toolbox, SAM's flat-minima search, and the LR range test.
- LoRA & QLoRA - The low-rank arithmetic and the three knobs, the QLoRA 4-bit pipeline, and the merge-on-FP16 rule.
Python Environment Issues¶
Issue: Import errors¶
Symptoms:
ModuleNotFoundError: No module named 'transformers'
ImportError: cannot import name 'AutoModel'
Solutions:
-
Check Python version:
python --version # Should be 3.8+ for most ML libraries -
Install in correct environment:
# Create the project environment with uv uv venv --python 3.13 source .venv/bin/activate # macOS/Linux .\.venv\Scripts\Activate.ps1 # Windows PowerShell .venv\Scripts\activate.bat # Windows Command Prompt # Install from the project manifest (pyproject.toml + uv.lock) uv sync --locked -
Verify installation:
uv pip list | grep transformers -
Check import path:
import sys print(sys.path) # Add custom path if needed sys.path.append('/path/to/module')
Issue: Version conflicts¶
Symptoms:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed.
TypeError: __init__() got an unexpected keyword argument
Solutions:
-
Reinstall with uv's resolver:
uv pip install --reinstall package-name -
Create fresh environment:
# Recreate the exact environment from the project lock rm -rf .venv && uv sync --locked -
Pin exact versions:
# pyproject.toml - exact pins recorded by uv add dependencies = [ "transformers==5.10.2", "torch==2.12.0", "peft==0.19.1", ] -
Use conda for better dependency management:
conda create -n ml-env python=3.13 conda activate ml-env conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia pip install transformers -
Python for AI/ML - The Python idioms, libraries and snippets used across the curriculum.
Network Issues¶
Issue: Proxy blocking downloads¶
Symptoms:
SSLError: HTTPSConnectionPool
ProxyError: Unable to connect to proxy
Solutions:
-
Set environment variables:
export HTTP_PROXY=http://proxy.example.com:8080 export HTTPS_PROXY=http://proxy.example.com:8080 export NO_PROXY=localhost,127.0.0.1 -
Set the proxy per command (uv and pip both honor the variables above):
HTTPS_PROXY=http://proxy.example.com:8080 uv pip install package-name -
Use Hugging Face mirror:
export HF_ENDPOINT=https://hf-mirror.com
Issue: Git clone fails¶
Symptoms:
fatal: unable to access 'https://github.com/.../'
Failed to connect to github.com
Solutions:
-
Use SSH instead of HTTPS:
git clone git@github.com:user/repo.git -
Configure Git proxy:
git config --global http.proxy http://proxy.example.com:8080 git config --global https.proxy http://proxy.example.com:8080 -
Use mirror sites:
# Gitee mirror for Chinese users git clone https://gitee.com/mirrors/repo.git
Storage Issues¶
Issue: Disk space full¶
Symptoms:
No space left on device
ERROR: write error
Solutions:
-
Check disk usage:
df -h du -sh ~/* | sort -h -
Clean Docker:
# Remove unused images docker image prune -a # Remove unused containers docker container prune # Remove unused volumes docker volume prune # Remove everything unused docker system prune -a --volumes -
Clean package cache (uv):
uv cache clean -
Clean model cache:
# Hugging Face cache rm -rf ~/.cache/huggingface # Ollama models rm -rf ~/.ollama/models -
Linux Commands for AI/ML - Shell commands, permissions and process management on the lab machines.
Performance Issues¶
Issue: High GPU memory usage¶
Symptoms:
- nvidia-smi shows high memory usage
- Other applications can't use GPU
Solutions:
-
Reduce model size:
# Use smaller model model_name = "mistralai/Mistral-7B" # Instead of 70B -
Enable quantization:
bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16 ) -
Limit memory fraction:
import torch torch.cuda.set_per_process_memory_fraction(0.7) -
Kill zombie processes:
# Find processes using GPU nvidia-smi # Kill specific process kill -9 ${PID} -
Quantization Formats & Methods - The bpw block arithmetic behind Q4_0/Q4_K, the three GGUF families, and the EXL2/AWQ/GPTQ GPU-only map.
Monitoring Issues¶
Issue: Grafana dashboards not loading¶
Symptoms:
- Dashboard shows "No data"
- Panel errors
Solutions:
-
Check Prometheus is running:
curl http://localhost:9090/-/healthy -
Verify datasource configuration:
# Check Grafana datasources curl http://localhost:3000/api/datasources -
Check Prometheus targets:
curl http://localhost:9090/api/v1/targets -
Restart Grafana:
docker restart grafana -
LLM Observability - The four LLM-specific metric families and their alert thresholds, the timing trio with its decode-rate trap, the hallucination ladder, and the nearest-rank percentile rule.
Emergency Commands¶
Force stop all containers:¶
docker kill $(docker ps -aq)
Remove all containers:¶
docker rm -f $(docker ps -aq)
Factory reset Docker:¶
# ⚠️ WARNING: Deletes all data!
docker system prune -a --volumes -f
Reboot machine (last resort):¶
sudo reboot
Getting Help¶
If you're still stuck:
-
Check logs:
docker logs ${CONTAINER_NAME} journalctl -u docker -
Search error messages:
- Google the exact error
- Check Stack Overflow
- GitHub Issues
-
Ask in communities:
- Discord servers
- Reddit (r/LocalLLaMA, r/MachineLearning)
- Hugging Face Forums
Quick Links¶
- TUTORIAL-001: Hello LLM - Getting started
- TUTORIAL-002: Docker Essentials - Docker basics
- LAB-001: Docker & LLM - Troubleshooting in practice
- 1501: Monitoring and Observability - Debug with observability
Need more help? Check the specific documentation for the service you're using.