Deep expertise in ML/CV model selection, training pipelines, and inference architecture. Use when designing machine learning systems, computer vision pipelines, or AI-powered features.
Provides specialized guidance for machine learning and computer vision system design, model selection, and production deployment.
Use Case Identified
β
βββΊ Text/Language Tasks
β βββΊ Classification β BERT, DistilBERT, or API (OpenAI, Claude)
β βββΊ Generation β GPT-4, Claude, Llama (self-hosted)
β βββΊ Embeddings β OpenAI Ada, sentence-transformers
β βββΊ Search/RAG β Vector DB + Embeddings + LLM
β
βββΊ Computer Vision Tasks
β βββΊ Classification β ResNet, EfficientNet, ViT
β βββΊ Object Detection β YOLOv8, DETR, Faster R-CNN
β βββΊ Segmentation β SAM, Mask R-CNN, U-Net
β βββΊ OCR β Tesseract, PaddleOCR, Cloud Vision API
β βββΊ Face Recognition β InsightFace, DeepFace
β
βββΊ Audio Tasks
β βββΊ Speech-to-Text β Whisper, DeepSpeech, Cloud APIs
β βββΊ Text-to-Speech β ElevenLabs, Coqui TTS
β βββΊ Audio Classification β PANNs, AudioSet models
β
βββΊ Structured Data
βββΊ Tabular β XGBoost, LightGBM, CatBoost
βββΊ Time Series β Prophet, ARIMA, Transformer-based
βββΊ Recommendations β Two-tower, matrix factorization
| Factor | API Preferred | Self-Hosted Preferred |
|---|---|---|
| Volume | < 10K requests/month | > 100K requests/month |
| Latency | > 500ms acceptable | < 100ms required |
| Customization | General use case | Domain-specific fine-tuning |
| Data Privacy | Non-sensitive data | PII, HIPAA, financial |
| Team Expertise | No ML engineers | ML team available |
| Budget | Predictable per-call costs | High volume justifies infra |
## API Costs (Example: OpenAI GPT-4)
- Input: $0.03/1K tokens
- Output: $0.06/1K tokens
- Average request: 500 input + 200 output tokens
- Cost per request: $0.027
- 100K requests/month: $2,700
## Self-Hosted Costs (Example: Llama 70B)
- GPU instance: $3/hour (A100 40GB)
- Throughput: ~50 requests/minute = 3K/hour
- Cost per request: $0.001
- 100K requests/month: $100 + $500 engineering time
## Break-even Analysis
- < 50K requests: API likely cheaper
- > 50K requests: Self-hosted may be cheaper
- Factor in: engineering time, ops burden, model quality
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA LAYER β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Data Sources β ETL β Feature Store β Training Data β
β (S3, DBs) (Airflow) (Feast) (Versioned) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TRAINING LAYER β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Experiment Tracking β Training Jobs β Model Registry β
β (MLflow, W&B) (SageMaker) (MLflow, S3) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SERVING LAYER β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Model Server β Load Balancer β Monitoring β
β (TorchServe) (K8s/ELB) (Prometheus) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Options | Recommendation |
|---|---|---|
| Feature Store | Feast, Tecton, SageMaker | Feast (open source), Tecton (enterprise) |
| Experiment Tracking | MLflow, Weights & Biases, Neptune | MLflow (free), W&B (best UX) |
| Training Orchestration | Kubeflow, SageMaker, Vertex AI | SageMaker (AWS), Vertex (GCP) |
| Model Registry | MLflow, SageMaker, custom S3 | MLflow (standard) |
| Model Serving | TorchServe, TFServing, Triton | Triton (multi-framework) |
Best for: Low-latency requirements, simple integration
Client β API Gateway β Model Server β Response
β
Load Balancer
β
ββββββββ΄βββββββ
β β
Model Pod Model Pod
Latency targets:
Best for: Long-running inference, batch processing
Client β API β Queue (SQS) β Worker β Result Store β Webhook/Poll
β
S3/Redis
Use when:
Best for: Privacy, offline capability, ultra-low latency
βββββββββββββββββββββββββββββββββββββββββββ
β EDGE DEVICE β
β βββββββββββ βββββββββββββββββββββββ β
β β Camera βββββΆβ Optimized Model β β
β βββββββββββ β (ONNX, TFLite) β β
β βββββββββββββββββββββββ β
β β β
β Local Result β
βββββββββββββββββββββββββββββββββββββββββββ
β
Sync to Cloud
(non-blocking)
Model optimization for edge:
Camera Stream β Frame Extraction β Preprocessing β Model β Postprocessing β Output
β β β β β
RTSP/ 1-30 FPS Resize, Batch or NMS, tracking,
WebRTC normalize single annotation
Performance optimization:
## Pipeline Components
1. **Input Processing**
- Video decode: FFmpeg, OpenCV
- Frame buffer: Ring buffer for temporal context
- Preprocessing: NVIDIA DALI (GPU), OpenCV (CPU)
2. **Detection**
- Model: YOLOv8 (speed), DETR (accuracy)
- Batch size: 1-8 depending on latency requirements
- Confidence threshold: 0.5-0.7 typical
3. **Post-processing**
- NMS (Non-Maximum Suppression)
- Tracking: SORT, DeepSORT, ByteTrack
- Smoothing: Kalman filter for stable boxes
4. **Output**
- Annotations: Bounding boxes, labels, confidence
- Events: Trigger on detection (webhook, queue)
- Storage: Frame + metadata to S3/DB
User Query β Embedding β Vector Search β Context Retrieval β LLM β Response
β
Vector DB
(Pinecone, Weaviate,
Chroma, pgvector)
Vector DB Selection:
| Database | Best For | Limitations |
|---|---|---|
| Pinecone | Managed, scale | Cost at scale |
| Weaviate | Self-hosted, features | Operational overhead |
| Chroma | Simple, local dev | Not for production scale |
| pgvector | PostgreSQL users | Performance at >1M vectors |
| Qdrant | Performance | Newer, smaller community |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β API GATEWAY β
β Rate limiting, auth, request routing β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββ ββββββββββ ββββββββββ
β GPT-4 β β Claude β β Local β
β API β β API β β Llama β
ββββββββββ ββββββββββ ββββββββββ
β
Model Router
(cost/latency/capability)
Multi-model strategy:
| Technique | Memory Reduction | Speed Impact |
|---|---|---|
| FP16 (Half Precision) | 50% | Neutral to faster |
| INT8 Quantization | 75% | 10-20% slower |
| INT4 Quantization | 87.5% | 20-40% slower |
| Gradient Checkpointing | 60-80% | 20-30% slower |
| Model Sharding | Distributed | Communication overhead |
# Dynamic batching pseudocode
class DynamicBatcher:
def __init__(self, max_batch=32, max_wait_ms=50):
self.queue = []
self.max_batch = max_batch
self.max_wait = max_wait_ms
async def add_request(self, request):
self.queue.append(request)
# Batch when full or timeout
if len(self.queue) >= self.max_batch:
return await self.process_batch()
await asyncio.sleep(self.max_wait / 1000)
return await self.process_batch()
async def process_batch(self):
batch = self.queue[:self.max_batch]
self.queue = self.queue[self.max_batch:]
return await self.model.predict_batch(batch)
| Metric | What It Measures | Alert Threshold |
|---|---|---|
| Latency (P95) | Response time | > 2x baseline |
| Throughput | Requests/second | < 80% capacity |
| Error Rate | Failed predictions | > 1% |
| Model Drift | Distribution shift | PSI > 0.2 |
| Data Quality | Input anomalies | > 5% anomalies |
Training Distribution βββ
ββββΊ Statistical Test βββΊ Alert
Production Distribution ββ
(PSI, KS test, JS divergence)
Population Stability Index (PSI):
| Use Case | Recommended Model | Latency | Cost |
|---|---|---|---|
| Text Classification | DistilBERT | 10ms | Low |
| Text Generation | GPT-4 / Claude | 1-5s | Medium |
| Image Classification | EfficientNet-B0 | 5ms | Low |
| Object Detection | YOLOv8-n | 10ms | Low |
| Object Detection (Accurate) | YOLOv8-x | 50ms | Medium |
| Semantic Segmentation | SAM | 100ms | Medium |
| Speech-to-Text | Whisper-base | Real-time | Low |
| Embeddings | text-embedding-ada-002 | 50ms | Low |
| Scale | GPU | Model Size | Throughput |
|---|---|---|---|
| Development | T4 (16GB) | < 7B params | 10-50 req/s |
| Production Small | A10G (24GB) | < 13B params | 50-100 req/s |
| Production Medium | A100 (40GB) | < 70B params | 100-500 req/s |
| Production Large | A100 (80GB) x 2+ | > 70B params | 500+ req/s |