M9-032M9: Senior ML & AI System DesignLLM Serving, RAG & Agent SysDesignHard
⚡Flashcard Drill➔Mastery:

Design a Multi-Tenant Distributed LoRA Adapter Hot-Swapping Serving Engine

🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
Next: M9-033 →
📐 Mathematical Definition
y=W0x+ΔWkx=W0x+Bk(Akx),Batch={xi∣Adapter(xi)=ki}y = W_0 x + \Delta W_k x = W_0 x + B_k (A_k x),\quad \text{Batch} = \{x_i \mid \text{Adapter}(x_i) = k_i\}
⚡ One-Sentence Core Answer
Serve thousands of fine-tuned adapters concurrently on shared frozen base weights using SGMV heterogeneous batching kernels, pinned host-RAM adapter caching, and affinity routing.

📌 Key Takeaways

  • •
    L1 Multi-Tenancy Economics: serving 1000 isolated 70B replicas is prohibitive; sharing one frozen base with ~100MB rank-16 LoRAs cuts GPU footprint 100x
  • •
    L2 Heterogeneous Batching: batch base W_0 x across all requests into one dense GEMM, then dispatch per-request B_k A_k x via Punica SGMV kernels
  • •
    L2 Tiered Adapter Cache: Unified Paging across GPU HBM (hot), pinned Host RAM (warm), and NVMe/S3 with async CUDA-stream prefetching
  • •
    L3 Adapter-Affinity Routing: route requests via bounded-load consistent hashing on adapter_id to maximize HBM adapter hit rates

📐 Mathematical Derivations

Active VRAM equals Mbase+∑k2Lrk(din+dout)b+MKVM_{\text{base}} + \sum_{k} 2 L r_k (d_{\text{in}}+d_{\text{out}})b + M_{\text{KV}}; Unified Paging allocates LoRA weights and KV blocks from one paged pool.

🏭 Production Trade-offs

1) Unmerged SGMV adds ~4% kernel latency vs merged weights but unlocks mixed-tenant batching; 2) Cap distinct adapters per batch to prevent PCIe thrashing.
⚠️ Common Interview Pitfalls
  • ✕
    Fetching cold LoRA adapters synchronously inside the decode loop, stalling co-batched tenants
  • ✕
    Allowing arbitrary high-rank adapters or resized vocabularies that break uniform paging assumptions
🎯 Interviewer Follow-up Inquiries
  • ?
    How does bounded-load consistent hashing spill over cleanly when one hot LoRA saturates a single replica?
  • ?
    How do you handle adapter hot-reloads in-flight without corrupting ongoing multi-turn decode streams?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

← PreviousM9-031: Design a Glean-Style ACL-Aware Enterprise Permissioned Search Architecture📋 Back to BankNext →M9-033: Design a Sub-350ms Full-Duplex Audio/Voice Pipeline with Instant Barge-In