Design an LLM Fine-Tuning System
Understanding the Problem
🎛️ What is an LLM fine-tuning system? Fine-tuning takes a pretrained language model and trains it further on a smaller, task-specific dataset so it follows a format, learns a domain's vocabulary, or prefers the answers your users prefer. A fine-tuning system is the platform around that: users upload examples, pick a base model and a method, the platform runs the training job on GPUs, evaluates the result against the base model, and deploys it behind an inference API.
This comes up as "design a fine-tuning API like the ones model providers offer," "design an internal platform for teams to fine-tune models," or as a use case: "fine-tune a model for code completion on our repos," "build a domain Q&A model," "fine-tune a model to analyze legal contracts." It's the same platform underneath. We'll design the platform first, then show how each use case changes the data, the method and the evaluation.
Functional Requirements
Core Requirements
- Users should be able to upload a training dataset and have it validated.
- Users should be able to launch a fine-tuning job (base model, method: SFT, LoRA or DPO, hyperparameters) and track its progress.
- Users should be able to evaluate the fine-tuned model against the base model on their own test sets and standard checks.
- Users should be able to deploy the fine-tuned model and call it through the inference API.
Below the line (out of scope)
- Pretraining base models from scratch.
- RLHF with a separate reward model and PPO, beyond comparing it to DPO.
- Building the labeling tools that produce the datasets.
Non-Functional Requirements
Ask about tenants, sizes and job mix. For our design, we're a platform serving many customers: about 2,000 jobs a week. Most are LoRA fine-tunes of 7-8B models on 1k-50k examples; a smaller number are full fine-tunes of a 70B model on hundreds of millions of tokens.
Core Requirements
- The system should isolate tenants: one customer's data, weights and outputs must never be visible to or trained into another's model.
- The system should finish small jobs fast (a typical LoRA job in under an hour, start to finish) and make big jobs predictable.
- The system should survive GPU and node failures: a job resumes from its last checkpoint instead of starting over.
- The system should use GPUs efficiently: high utilization, and the cheapest method that meets the user's quality bar.
- The system should not ship regressions: a model deploys only after it beats (or at least matches) its baseline on the user's evals, and passes safety checks.
Below the line (out of scope)
- Multi-region training; jobs run where their data lives.
- Hyperparameter search beyond a few presets and simple sweeps.
Now the math, because two job shapes fall out of it. Training compute is about 6 × parameters × tokens for full fine-tuning (forward pass ≈ 2, backward ≈ 4). With LoRA, the base weights are frozen, so we skip their weight gradients and it's closer to 4 × parameters × tokens.
Typical LoRA job: 8B model, 10M tokens × 3 epochs = 30M tokens
4 × 8×10^9 × 3×10^7 ≈ 1×10^18 FLOPs
at ~400 TFLOP/s effective on one H100 → ~40 minutes on 1 GPU
Big full fine-tune: 70B model, 500M tokens
6 × 7×10^10 × 5×10^8 ≈ 2.1×10^20 FLOPs
at ~400 TFLOP/s per GPU on 64 H100s → ~2.3 hours
Memory decides the hardware. Full fine-tuning with Adam in mixed precision needs about 16 bytes per parameter (2 for BF16 weights, 2 for gradients, 4 for an FP32 master copy, 8 for Adam's two moments), before activations. That's 128 GB for an 8B model and 1.1 TB for 70B, which must be sharded across many GPUs. A LoRA fine-tune of an 8B model needs the frozen BF16 weights (16 GB) plus a tiny trainable adapter, and fits on one 80 GB GPU with room for activations.
So we have two very different workloads. Around 2,000 small jobs a week at about a GPU-hour each is only ~12 GPUs busy on average, but their startup overhead (scheduling, pulling a 16 GB base model, loading data) can easily exceed their training time. A hundred big jobs a week at 64 GPUs × 3 hours is ~19,000 GPU-hours, the bulk of the fleet, and they need gang scheduling, fast interconnect and checkpointing.
Saying "fine-tuning needs a lot of GPUs" isn't enough. The good answer notices that most jobs are small, single-GPU LoRA runs where startup latency dominates, while a few huge jobs dominate GPU-hours, and designs for both.