A scalable, production-ready platform for hosting and managing ML models locally
Quick Start β’ Features β’ Documentation β’ Deployment
- Multiple Model Types: Text-to-text, text-to-image, image-to-text, speech-to-text, text-to-speech
- Local Model Hosting: Download and manage models from HuggingFace Hub
- Async Inference: High-performance async API with Celery workers
- GPU/CPU Support: Automatic device detection with separate worker queues
- β Authentication: JWT & API key support
- β Error Handling: Retry policies, circuit breakers, structured exceptions
- β Monitoring: Prometheus metrics, health checks, performance tracking
- β Database Optimization: Connection pooling, async operations
- β Model Management: Warm pool with LRU caching, automated downloads
- β Result Caching: Redis-based caching layer
- β Context Management: Smart token counting & truncation for LLMs
- β Load Balancing: Nginx reverse proxy with multiple backend instances
- β Horizontal Scaling: Multiple workers, configurable resources
- β¨ Prompt Templates: 10+ pre-built templates, Jinja2 rendering, custom templates
- π¬ Conversation Management: Multi-turn chat history, export capabilities
- π¨ Chat Formatters: Support for ChatML, Llama-2, Mistral, Alpaca, Vicuna
- π¦ Batch Inference: Dynamic batching for 3-5x throughput improvement
- π·οΈ Model Versioning: Version tracking, traffic splitting, A/B testing
- π§ͺ A/B Testing: Statistical analysis, winner determination, metrics collection
- π’ Model Quantization: INT4/INT8/FP8 quantization, 75% size reduction
- βοΈ Object Storage: S3/MinIO integration for model artifacts
- π Comprehensive Monitoring: Grafana dashboards, Prometheus metrics, alerting
- π CI/CD Pipeline: Automated testing, building, deployment
- Quick Start
- Architecture
- Model Types
- API Endpoints
- Deployment
- Monitoring
- Configuration
- Development
- Performance
# 1. Clone repository
git clone <repository-url>
cd ml-platform
# 2. Configure environment
cp .env.example .env
# Edit .env with your settings
# 3. Deploy everything
./scripts/quick-deploy.sh
# 4. Access the platform
open http://localhost/docsSee QUICK_DEPLOYMENT.md for detailed instructions.
# 1. Start infrastructure
docker-compose -f docker-compose.prod.yml up -d postgres redis minio
# 2. Run migrations
docker-compose -f docker-compose.prod.yml run --rm backend1 alembic upgrade head
# 3. Start application
docker-compose -f docker-compose.prod.yml up -d
# 4. Start monitoring
cd monitoring && docker-compose -f docker-compose.monitoring.yml up -dβββββββββββββββ
β Nginx β β Load Balancer
β (Port 80) β
ββββββββ¬βββββββ
β
βββββββββββββββ¬ββββββββββββββ¬ββββββββββββββ
β β β β
ββββββββΌβββββββ βββββΌβββββββββ ββββΌββββββββββ β
β Backend 1 β β Backend 2 β β Backend 3 β β
β (FastAPI) β β (FastAPI) β β (FastAPI) β β
ββββββββ¬βββββββ βββββββ¬βββββββ ββββββββ¬ββββββ β
β β β β
ββββββββββββββββ΄ββββββββββββββββ β
β β
ββββββββββββββββ΄ββββββββββββββββββββββββββ
β
ββββββββΌβββββββββββββββββββββββββββββββββββββββ
β Redis (Cache & Queue) β
ββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββ¬βββββββββββββ¬ββββββββββββββ
β β β β
ββββββββΌβββββββ ββββΌβββββββββ βββΌβββββββββββ β
β GPU Worker β βGPU Worker β β CPU Worker β β
β (High) β β (Low) β β β β
βββββββββββββββ βββββββββββββ ββββββββββββββ β
β
βββββββββββββββ βββββββββββββββ ββββββββββββΌβ
β PostgreSQL β β MinIO β βPrometheus β
β Database β β Storage β β& Grafana β
βββββββββββββββ βββββββββββββββ βββββββββββββ
# Example: GPT-2, LLama-2, Mistral
POST /api/v1/inference/text-to-text
{
"model_id": 1,
"input_data": {
"text": "Explain quantum computing",
"system_prompt": "You are a helpful assistant",
"template_id": 5, # Optional: Use prompt template
"conversation_id": 123 # Optional: Continue conversation
},
"parameters": {
"max_length": 200,
"temperature": 0.7
}
}# Example: Stable Diffusion, DALL-E
POST /api/v1/inference/text-to-image
{
"model_id": 2,
"input_data": {
"prompt": "A futuristic city at sunset",
"negative_prompt": "blurry, low quality"
},
"parameters": {
"num_inference_steps": 50,
"guidance_scale": 7.5
}
}# Example: BLIP, LLaVA
POST /api/v1/inference/image-to-text
{
"model_id": 3,
"input_data": {
"image_url": "https://example.com/image.jpg"
}
}POST /api/v1/auth/register # Register user
POST /api/v1/auth/login # Login
POST /api/v1/auth/api-keys # Create API key
GET /api/v1/auth/api-keys # List API keys
DELETE /api/v1/auth/api-keys/{id} # Delete API key
GET /api/v1/models # List models
POST /api/v1/models # Create model
GET /api/v1/models/{id} # Get model
PATCH /api/v1/models/{id} # Update model
DELETE /api/v1/models/{id} # Delete model
POST /api/v1/models/{id}/download # Download model
POST /api/v1/inference/text-to-text # Text generation
POST /api/v1/inference/text-to-image # Image generation
POST /api/v1/inference/image-to-text # Image captioning
POST /api/v1/inference/speech-to-text # Speech recognition
POST /api/v1/inference/text-to-speech # Speech synthesis
GET /api/v1/prompts # List templates
POST /api/v1/prompts # Create template
GET /api/v1/prompts/{id} # Get template
POST /api/v1/prompts/render # Render template
GET /api/v1/prompts/search/{q} # Search templates
GET /api/v1/conversations # List conversations
POST /api/v1/conversations # Create conversation
GET /api/v1/conversations/{id} # Get conversation
POST /api/v1/conversations/{id}/messages # Add message
GET /api/v1/conversations/{id}/export # Export conversation
GET /api/v1/health # Basic health check
GET /api/v1/health/detailed # Detailed health
GET /api/v1/health/metrics # Prometheus metrics
Full API Documentation: http://localhost/docs
docker-compose up -ddocker-compose -f docker-compose.prod.yml up -dkubectl apply -f k8s/See detailed deployment guides:
| Service | URL | Default Credentials |
|---|---|---|
| Grafana | http://localhost:3000 | admin / admin |
| Prometheus | http://localhost:9090 | - |
| Flower (Celery) | http://localhost:5555 | - |
| MinIO Console | http://localhost:9001 | minioadmin / minioadmin |
- Request Rate: Requests per second
- Latency: p50, p95, p99 percentiles
- Error Rate: Failed requests percentage
- GPU Utilization: GPU usage and memory
- Queue Length: Pending tasks in Celery
- Cache Hit Rate: Redis cache performance
- Model Load Time: Time to load models
- Platform Overview: System-wide metrics
- Inference Metrics: Model-specific performance
- Resource Usage: CPU, Memory, GPU, Disk
# Security
SECRET_KEY=<generate-secure-key>
POSTGRES_PASSWORD=<database-password>
REDIS_PASSWORD=<redis-password>
# Model Configuration
MODEL_POOL_SIZE=5
DEFAULT_DEVICE=cuda
# Batch Processing
BATCH_INFERENCE_ENABLED=true
BATCH_MAX_SIZE=8
BATCH_MAX_WAIT_MS=100
# S3/MinIO
S3_ENABLED=true
USE_MINIO=true
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=<secret-key>
# Monitoring
SLACK_WEBHOOK_URL=<slack-webhook>
PAGERDUTY_SERVICE_KEY=<pagerduty-key>See .env.example for all options.
- Python 3.11+
- Docker & Docker Compose
- NVIDIA GPU (optional)
# 1. Create virtual environment
python -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
# 2. Install dependencies
cd backend
pip install -r requirements.txt
# 3. Run database
docker-compose up -d postgres redis
# 4. Run migrations
alembic upgrade head
# 5. Start development server
uvicorn app.main:app --reload
# 6. Run tests
pytest# Format code
black app/
isort app/
# Lint
flake8 app/
mypy app/
# Run tests with coverage
pytest --cov=app --cov-report=html| Metric | Value |
|---|---|
| Throughput | 45 requests/second (with batching) |
| Latency (p95) | 150ms (cached), 2s (inference) |
| GPU Efficiency | 4 models per GPU (with INT4 quantization) |
| Cache Hit Rate | 95% for repeated requests |
| Model Load Time | 0.1s (from pool), 2s (cold start) |
- Enable Batch Inference: 3-5x throughput improvement
- Use Quantization: 75% smaller models, 3-4x faster
- Cache Aggressively: 95%+ hit rate possible
- Model Pool: Eliminate cold starts
- Horizontal Scaling: Add more workers as needed
- Quick Deployment Guide: Get started in 10 minutes
- Phases 3-6 Summary: Complete feature documentation
- API Documentation: Interactive Swagger UI
- Production Guide: Deployment best practices
- Core inference system
- Authentication & authorization
- Monitoring & alerting
- Prompt templates
- Conversation management
- Batch inference
- Model versioning & A/B testing
- Quantization support
- CI/CD pipeline
- Kubernetes deployment
- Advanced rate limiting
- Custom model fine-tuning
- Multi-tenancy support
- Cost tracking & billing
- Model marketplace
- Advanced analytics
- Auto-scaling policies
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- π Bug fixes
- β¨ New features
- π Documentation
- π§ͺ Tests
- π¨ UI/UX improvements
This project is licensed under the MIT License - see LICENSE for details.
- Documentation: Check the
/docsfolder - Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@ml-platform.com
Built with amazing open-source tools:
- FastAPI
- PyTorch
- HuggingFace Transformers
- Celery
- PostgreSQL
- Redis
- Prometheus & Grafana
- Docker
β Star us on GitHub if you find this useful! β
Made with β€οΈ for the ML community