SysDesignAtlas

Build a Fine-Tuning Platform

Multi-tenant training and serving of customer-specific models — dataset validation, LoRA job scheduling, and serving 500 adapters in the memory of one base model.

HLDHard11 min readlevel-5aifine-tuninglora
Confidence

#The product

Customers upload a dataset, get a fine-tuned model, and call it through the same API as the base model. You run the training and the serving.

Fine-tuning means taking an existing trained model and nudging it with your own examples so it behaves the way you want. The naive way rewrites all of the model's weights, producing a whole new 140 GB model per customer.

LoRA avoids that. Instead of changing the original weights, it trains a small set of extra weights that sit alongside them — an adapter of perhaps 50 MB — and the base model stays untouched and shared.

The entire business depends on that one fact: adapters are small enough to share a base model. Without it, serving 500 customer models means 500 × 140 GB, which is not a product.

#Phase 1 — One job, one GPU

   POST /fine-tune {dataset_url, base_model}
        ↓
   validate the dataset
        ↓
   allocate a GPU, run LoRA training  (30-90 min)
        ↓
   save the adapter (~50 MB) to object storage
        ↓
   customer calls: POST /completions {model: "ft:cust-42:abc"}
        → load the base + this adapter, generate, unload

Survives to: a few dozen customers, occasional retraining, tolerant latency expectations.

What breaks first: loading and unloading an adapter per request. Each swap is a memory copy and a scheduler stall, and it destroys batching — you cannot batch requests using different adapters if you're swapping between them.

#Phase 2 — Multi-adapter serving

This is the phase that makes the product viable, and it's worth understanding precisely.

   ONE BASE MODEL, MANY ADAPTERS, ONE BATCH

     GPU memory:
       base model weights          70 GB   (loaded once)
       adapter A (customer 42)   0.05 GB
       adapter B (customer 91)   0.05 GB
       ...
       adapter Z (200 more)        10 GB
       KV cache                    remainder

     A single batch contains requests from different
     customers. The kernel applies each request's own
     adapter during the forward pass:

       h = W·x  +  (B_i · A_i)·x    ← i varies per row
           ────     ─────────────
           shared    per-request

   → 200 "models" in the memory of one, with full
     batching efficiency.

Reading the formula: W·x is the base model's normal calculation, and it's identical for every request, so the whole batch shares it. B_i · A_i is request i's adapter — two small matrices — and adding (B_i · A_i)·x nudges the result toward that customer's fine-tuned behaviour. The kernel (the GPU routine doing this maths) looks up the right adapter for each row of the batch, so one pass serves many customers at once.

The engineering that makes it work:

Adapter cache with LRU. Not every adapter is hot. Keep the active ones in GPU memory, the recent ones in host memory, the rest in object storage. An adapter is 50 MB — a host-to-device copy is under a millisecond, so a cache miss is cheap. Unlike KV cache, this tier is genuinely easy.

Rank grouping. An adapter's rank is the inner size of its two small matrices — higher rank means more trainable weights and a slightly bigger adapter. Batched multi-adapter kernels are simplest when all adapters in a batch share a rank. Either fix the rank platform-wide (simplest, and rank 16 is fine for most tasks) or pad to a common rank within a batch.

Route by adapter affinity. Requests for the same adapter should prefer the replica that already has it resident — the same cache-affinity routing logic as prefix caching, with a much cheaper miss.

Survives to: hundreds of customers.

What breaks first: a customer uploads a dataset that produces a model which is worse, and blames you. You need evaluation in the pipeline.

#Phase 3 — Dataset validation and evaluation gates

Most fine-tuning failures are data failures, and they are detectable before you spend a GPU-hour.

   VALIDATION, BEFORE THE JOB IS QUEUED

   Structural    valid JSONL, required fields present,
                 messages in the expected role sequence
   Format        renders correctly under the base model's
                 CHAT TEMPLATE — the single most common
                 cause of "the fine-tune didn't work"
   Size          enough examples (< 50 is usually pointless),
                 token count within limits
   Quality       duplicate detection, length distribution,
                 label consistency on similar inputs
   Safety        PII scan, content classification
   Leakage       overlap between the training split and any
                 held-out evaluation set

   → Reject with SPECIFIC, actionable errors:
     "line 847: 'assistant' message is empty"
     not "invalid dataset"

A chat template is the exact text format a model was trained to see a conversation in — the special markers for where a system message, a user turn and an assistant turn begin and end. Training data rendered in a different format teaches the model the wrong pattern, and the fine-tune quietly underperforms.

Then split, train, and evaluate automatically. The split is stratified: each kind of example appears in the same proportion in the training and held-out sets, so the evaluation reflects the whole dataset.

   dataset → 90% train / 10% held-out (stratified)
        ↓
   train the adapter
        ↓
   EVALUATE on the held-out split:
     · task metric vs the BASE model — did it improve?
     · general benchmarks — did it forget everything else?
        ↓
   report both to the customer BEFORE they deploy it

What breaks first: training jobs queue behind each other, and a customer waiting six hours for a thirty-minute job is unhappy.

#Phase 4 — The training scheduler

   JOB QUEUE with fair scheduling

     tiers:      free (best effort, preemptible)
                 paid (guaranteed start within 1 hour)
                 enterprise (dedicated capacity)

     per-tenant concurrency cap  → no one customer floods
     gang scheduling             → multi-GPU jobs get all
                                   or nothing
     preemption                  → free-tier jobs yield to
                                   paid, with a checkpoint
                                   signal and a grace period
     spot instances for free tier → checkpointed every
                                   ~10 minutes, resumes
                                   automatically

All of this is GPU cluster scheduling with tenants attached. The specific additions for this product:

  • Cost estimation before queueing. Dataset size and epoch count give a good estimate of GPU-minutes; show it, and let the customer confirm.
  • Hard job cost ceilings. A dataset 100× larger than expected should fail admission, not consume a day of GPU time.
  • Checkpointing even for short jobs. A 40-minute job on spot capacity that loses 35 minutes of work is worse than one that resumes from minute 30.

#Phase 5 — Versioning and rollout

Customers retrain. They need to compare, roll out gradually, and roll back.

   ft:customer-42:v1   (deployed, 100% of their traffic)
   ft:customer-42:v2   (trained, evaluated, not deployed)

   Customer-facing controls:
     · compare v1 vs v2 on their own held-out set
     · deploy v2 to a percentage of their traffic
     · promote or roll back

   Platform-side:
     · both adapters resident during the split — cheap,
       they're 50 MB
     · per-version metrics and cost attribution
     · adapters are immutable; a retrain is a NEW version,
       never an overwrite

Immutability is the important one. A customer who overwrites v1 and finds v2 worse has no way back, and "which adapter produced this output" becomes unanswerable — which matters for support and for compliance.

#Phase 6 — Isolation and multi-tenancy

The security surface of a platform that runs customer data through shared infrastructure:

BoundaryRiskControl
Training dataLeaking into another customer's modelPer-tenant storage with separate encryption keys; no cross-tenant batching in training
AdaptersServing customer A's adapter to customer BAdapter ID resolved from the authenticated tenant, never from the request body
Prefix cacheCached KV shared across tenantsKey the cache by (tenant, model, adapter, tokens)
Base modelShared by designFine — it's public weights
Logs and tracesPrompts containing customer dataPer-tenant retention and redaction policy

The adapter-resolution one is the sharp edge. If the request specifies model: "ft:cust-91:abc" and the server trusts it, any authenticated customer can invoke any other customer's model. Resolve the adapter from the tenant's own namespace and reject anything outside it.

#The decision log

DecisionRejectedBecause
LoRA adaptersFull fine-tuning per customer200× memory reduction; full FT makes the product impossible
Shared base, batched multi-adapterAdapter swap per requestSwapping destroys batching, which is where all the throughput is
Fixed platform-wide rankPer-customer rankSimplifies batched kernels; rank 16 suffices for most tasks
Validate before queueingFail during trainingMost failures are data failures and are detectable in seconds
Auto-evaluate on a held-out splitTrust the customer to evaluateThey mostly won't, and will blame the platform
Report general-benchmark regressionReport task improvement onlyForgetting is the default; hiding it destroys trust later
Immutable versioned adaptersOverwrite on retrainNo rollback, and no answer to "which model produced this"
Adapter resolved from tenant identityTrust the model ID in the requestOtherwise any customer can invoke any other's model
Spot + checkpointing for free tierOn-demand for everythingTraining tolerates preemption; it's the natural fit

#What you'd cut for v1

Phases 4–6. Ship: dataset validation, LoRA training on a fixed rank, automatic held-out evaluation with both metrics reported, and multi-adapter serving. That's the product. Fair scheduling, gradual rollout, and spot capacity are optimisations you add when the queue and the bill justify them.

Do not cut: dataset format validation against the chat template, and multi-adapter serving. Skip the first and most fine-tunes silently fail; skip the second and the unit economics don't work.

#Explaining the design

"The whole product rests on LoRA. Full fine-tuning a 70B model per customer would need 438 GPUs just to hold 500 customers' weights. With adapters at 50 MB against a shared base, it's two GPUs — a 200× reduction — and crucially, requests from different customers still batch together because the adapter is applied per row inside the kernel. Without that batching property the economics don't work at all.

Around that, the platform is mostly validation and scheduling. Most fine-tuning failures are data failures, and nearly all of them — wrong format, too few examples, template mismatch — are detectable in seconds before you spend a GPU-hour. So validation is aggressive and errors are specific.

After training I'd automatically evaluate on a held-out split against both the customer's task and general benchmarks, and report both. Catastrophic forgetting is the default outcome, and a platform that only reports the improvement is setting the customer up to discover the regression in production.

The scheduling is standard multi-tenant GPU work — fair queues, gang scheduling, spot with checkpointing for the free tier, since training tolerates preemption well.

The security detail I'd call out: the adapter must be resolved from the authenticated tenant's namespace, never from the model ID in the request. Trusting that string means any customer can invoke any other customer's model."

#Next

Build a Pretraining Cluster — the same problems at the scale where the hardware itself becomes the design constraint.

#Check yourself

What one fact makes a fine-tuning platform possible?Show answer
LoRA adapters (~50 MB) sit beside a shared, untouched base model, so 500 customers need ~95 GB instead of ~35,000 GB — two GPUs instead of ~438.
Why must adapters be served in one batch, not swapped?Show answer
Swapping per request is a memory copy and a scheduler stall and destroys batching. Batched multi-adapter kernels apply each row's own adapter (h = Wx + B_iA_i x) in one forward pass.
How are adapters cached and routed?Show answer
Hot adapters in GPU memory, recent in host memory, the rest in object storage (a miss is a sub-millisecond copy); a fixed platform-wide rank simplifies kernels; route by adapter affinity.
What should dataset validation check before queueing?Show answer
Structure, rendering under the base model's chat template (the most common failure), size, duplicates and label consistency, PII and safety, and train–eval leakage — with specific, line-level errors.
Why report general benchmarks after fine-tuning?Show answer
Catastrophic forgetting is the default: task accuracy rises while reasoning and instruction-following drop. Report both and offer mitigations — lower rank, fewer epochs, mixed general data.
What does the training scheduler add for tenants?Show answer
Tiered fair queues, per-tenant concurrency caps, gang scheduling, preemption with checkpoints, spot capacity for the free tier, and cost estimates and ceilings before admission.
Why must adapters be immutable and versioned?Show answer
A retrain is a new version, so customers can compare, split traffic, roll back, and answer "which model produced this output" for support and compliance.
What is the sharpest multi-tenant security edge?Show answer
Resolve the adapter from the authenticated tenant's namespace, never from the model ID in the request — otherwise any customer can call any other's model. Key prefix caches by tenant too.

#What to carry forward

  • LoRA plus a shared base is the whole business case.
  • Batch many adapters in one forward pass; never swap per request.
  • Validate data aggressively — most fine-tunes fail on data, especially chat templates.
  • Evaluate automatically and report forgetting alongside gains.
  • Immutable versions, fair GPU scheduling, adapters resolved from tenant identity.
00:00
/ 11m