Skip to content

saptak/fine-tuning-small-llms

Repository files navigation

Fine-Tuning Small LLMs with Docker Desktop

License: MIT Docker Python

Complete reference code and documentation for the comprehensive 6-part blog series on fine-tuning small language models using Docker Desktop.

πŸ“š Blog Series

This repository accompanies the detailed blog series:

  1. Part 1: Setup and Environment - Docker development environment with CUDA support
  2. Part 2: Data Preparation and Model Selection - High-quality dataset creation and model selection
  3. Part 3: Fine-Tuning with Unsloth - Efficient training with LoRA adapters
  4. Part 4: Evaluation and Testing - Comprehensive evaluation framework
  5. Part 5: Deployment with Ollama and Docker - Production deployment
  6. Part 6: Production, Monitoring, and Scaling - Enterprise operations

πŸš€ Quick Start

Prerequisites

  • Docker Desktop with GPU support
  • Python 3.10+
  • 16GB+ RAM (32GB+ recommended)
  • NVIDIA GPU with 8GB+ VRAM (optional but recommended)

Clone and Setup

git clone https://github.com/saptak/fine-tuning-small-llms.git
cd fine-tuning-small-llms

# Set up environment
cp .env.example .env
# Edit .env with your configuration

# Start the development environment
docker-compose up -d

πŸ“ Repository Structure

fine-tuning-small-llms/
β”œβ”€β”€ part1-setup/                 # Development environment setup
β”‚   β”œβ”€β”€ src/                     # Setup scripts and utilities
β”‚   β”œβ”€β”€ configs/                 # Docker and environment configs
β”‚   β”œβ”€β”€ scripts/                 # Installation and setup scripts
β”‚   └── docs/                    # Part 1 documentation
β”œβ”€β”€ part2-data-preparation/       # Dataset creation and validation
β”‚   β”œβ”€β”€ src/                     # Data processing utilities
β”‚   β”œβ”€β”€ examples/                # Example datasets
β”‚   └── scripts/                 # Data preparation scripts
β”œβ”€β”€ part3-training/               # Model fine-tuning
β”‚   β”œβ”€β”€ src/                     # Training scripts
β”‚   β”œβ”€β”€ notebooks/               # Jupyter notebooks
β”‚   └── configs/                 # Training configurations
β”œβ”€β”€ part4-evaluation/             # Model evaluation and testing
β”‚   β”œβ”€β”€ src/                     # Evaluation frameworks
β”‚   β”œβ”€β”€ tests/                   # Test suites
β”‚   └── scripts/                 # Evaluation scripts
β”œβ”€β”€ part5-deployment/             # Production deployment
β”‚   β”œβ”€β”€ src/                     # API and web interfaces
β”‚   β”œβ”€β”€ docker/                  # Deployment containers
β”‚   └── configs/                 # Production configs
β”œβ”€β”€ part6-production/             # Monitoring and optimization
β”‚   β”œβ”€β”€ src/                     # Production utilities
β”‚   β”œβ”€β”€ monitoring/              # Grafana dashboards and configs
β”‚   └── scripts/                 # Production scripts
β”œβ”€β”€ docker/                      # Docker configurations
β”‚   β”œβ”€β”€ images/                  # Custom Docker images
β”‚   └── compose/                 # Docker Compose files
β”œβ”€β”€ data/                        # Training datasets
β”œβ”€β”€ models/                      # Model storage
└── docs/                        # Additional documentation

🎯 What You'll Learn

  • Environment Setup: Complete Docker-based development environment
  • Data Engineering: High-quality dataset creation and validation techniques
  • Model Training: Efficient fine-tuning with Unsloth and LoRA adapters
  • Evaluation: Comprehensive testing frameworks and A/B testing
  • Deployment: Production-ready APIs and web interfaces
  • Operations: Monitoring, security, scaling, and cost optimization

πŸ”§ Key Technologies

πŸ—οΈ Architecture Overview

graph TB
    A[Data Preparation] --> B[Model Training]
    B --> C[Evaluation]
    C --> D[Deployment]
    D --> E[Production Monitoring]
    
    subgraph "Part 1-2: Foundation"
        A
        F[Environment Setup]
    end
    
    subgraph "Part 3-4: Training & Testing"
        B
        C
    end
    
    subgraph "Part 5-6: Production"
        D
        E
    end
Loading

πŸ“Š Performance Benchmarks

Our approach achieves:

  • 80% Memory Reduction with Unsloth optimization
  • 2x Faster Training compared to standard fine-tuning
  • Sub-second Inference for SQL generation tasks
  • 99.9% Uptime with proper deployment configuration
  • <$10/day operational costs for moderate usage

πŸ§ͺ Example Use Cases

SQL Query Generation

# Fine-tune a model for SQL generation
python part3-training/src/train_sql_model.py --dataset data/sql_dataset.json

# Deploy and test
curl -X POST "http://localhost:8000/generate-sql" \
  -H "Content-Type: application/json" \
  -d '{"instruction": "Find all users who registered last month"}'

Code Documentation

# Train for code documentation
python part3-training/src/train_code_docs.py --dataset data/code_docs_dataset.json

Customer Support

# Train for customer support responses
python part3-training/src/train_support_model.py --dataset data/support_dataset.json

πŸ”’ Security Features

  • JWT Authentication for API access
  • Rate Limiting and request throttling
  • Input Validation and sanitization
  • HTTPS/TLS encryption
  • Web Application Firewall (WAF)
  • Secrets Management with environment variables

πŸ“ˆ Monitoring & Observability

  • Real-time Metrics with Prometheus
  • Custom Dashboards with Grafana
  • Distributed Tracing for request flows
  • Cost Tracking and optimization
  • Automated Alerting for issues

πŸ› οΈ Development Workflow

  1. Setup Environment (Part 1)
cd part1-setup && ./scripts/setup_environment.sh
  1. Prepare Data (Part 2)
cd part2-data-preparation && python src/create_dataset.py
  1. Train Model (Part 3)
cd part3-training && python src/fine_tune_model.py
  1. Evaluate Results (Part 4)
cd part4-evaluation && python src/run_evaluation.py
  1. Deploy to Production (Part 5)
cd part5-deployment && ./scripts/deploy.sh
  1. Monitor and Scale (Part 6)
cd part6-production && ./scripts/setup_monitoring.sh

πŸ“‹ Requirements

Hardware

  • CPU: 8+ cores recommended
  • RAM: 16GB minimum, 32GB+ recommended
  • GPU: NVIDIA GPU with 8GB+ VRAM (optional but recommended)
  • Storage: 100GB+ free space

Software

  • OS: Linux, macOS, or Windows with WSL2
  • Docker: Latest version with GPU support
  • Python: 3.10 or higher
  • CUDA: 11.8+ (if using GPU)

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

# Clone the repository
git clone https://github.com/saptak/fine-tuning-small-llms.git
cd fine-tuning-small-llms

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
pytest tests/

# Format code
black src/
isort src/

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

  • Documentation: Check the docs/ directory for detailed guides
  • Issues: Report bugs and request features in GitHub Issues
  • Discussions: Join the conversation in GitHub Discussions

πŸ”— Related Projects


⭐ Star this repository if you find it helpful!

Happy Fine-Tuning! πŸš€

About

Complete reference code for the Fine-Tuning Small LLMs on your Desktop blog series

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published