Skip to main content
← CONCEPTS / AI-MACHINE-LEARNING
An end-to-end domain learning journey

Punica & S-LoRA Batched
SGMV Multi-Tenant Adapter Serving.

Serving 10,000+ tenant LoRA adapters on shared 80 GB H100 GPUs hits an immediate HBM wall if each adapter duplicates the 140 GB base model or merges weights per request, which destroys continuous batching. Punica and S-LoRA solve this by keeping frozen base weights W_0 shared in a single Tensor Core GEMM while computing per-tenant low-rank deltas in parallel via Segmented Gather Matrix-Vector Multiplication (SGMV) over a Unified Paged GPU HBM Pool.
Start the journey3 sections· Last modified Nov 28, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When serving >100 LoRA adapters with skewed traffic, pair Punica SGMV kernels with unified HBM paging and consistent-hash routing to keep cold misses under 15 ms.

TL;DR30-second simplified summary
▾

By keeping W_0 frozen and shared, SGMV batches mixed-tenant tokens in one Tensor Core pass. Unified Paging prevents HBM fragmentation, while pinned CPU RAM absorbs cold adapter prefetches over PCIe Gen5 in ~2.3 ms.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Transformer attention and KV-cache memory layout (PagedAttention)
Core prerequisite: Transformer attention and KV-cache memory layout (PagedAttention).
Low-Rank Adaptation (LoRA) matrix decomposition W' = W_0 + (alpha/r)BA
Core prerequisite: Low-Rank Adaptation (LoRA) matrix decomposition W' = W_0 + (alpha/r)BA.
GPU HBM3 bandwidth vs Tensor Core FLOP arithmetic intensity
Core prerequisite: GPU HBM3 bandwidth vs Tensor Core FLOP arithmetic intensity.
Full walkthrough · 3 stages
01
STAGE 01L4 · FUNDAMENTALS

P & R: The Multi-Tenant HBM Bottleneck & Intuition.

An H100 GPU has 80 GB of HBM3 at 3.35 TB/s. After loading a 4-bit/FP8 70B base model (~38 GB) and CUDA runtime (~4 GB), only 38 GB remains for both KV-cache blocks and tenant adapters. If you merge LoRA weights into W_0 per request, you cannot batch Tenant A and Tenant B in the same forward pass. Instead, linearity of matrix multiplication lets us factor Y = X(W_0 + BA) = XW_0 + X(BA). Every tenant's token shares the exact same XW_0 GEMM, while only the tiny rank-r (r=16) correction XBA differs per tenant.

Linearity Factorization for Shared Base Batching

Mixed Batch X (B xd)Shared W_0 GEMMPunica SGMV DeltaFused Output YSegment offsets
02
STAGE 02L4 · FUNDAMENTALS

I & M: Punica SGMV Kernel & Unified Paged HBM Pool.

Punica's SGMV kernel accepts a batch of hidden states X, a segment pointer array mapping contiguous token slices to adapter IDs, and page-table pointers to each adapter's non-contiguous A and B tiles in HBM. S-LoRA eliminates external HBM fragmentation by allocating both KV-cache blocks and LoRA adapter weights from the same fixed-size page pool (e.g., 64 KB pages). When a cold adapter misses HBM, an asynchronous CUDA stream prefetches its 146.8 MB safetensors pages from pinned CPU host RAM over PCIe Gen5 (64 GB/s -> ~2.3 ms) or local NVMe (<15 ms) without stalling active decode steps.

Unified Paged HBM Pool & PCIe Prefetch Hierarchy

S3 Adapter Registry(10K+ Adapters)Cold Durable StoreLocal NVMe RAID-0(3.2 GB/s)Local Disk CachePinned Host RAM(512 GB)Warm Prefetch TierH100 HBM3 Pool (38GB Free)Active Unified PagesCold pull (~350 ms)DMA (~12 ms)PCIe Gen5 (~2.3 ms)
03
STAGE 03L5 · APPLIED DESIGN

E: Edge Cases, Adapter Thrashing & When NOT to Use S-LoRA.

If a burst of 200 distinct cold adapters hits a single GPU node simultaneously, PCIe prefetch queues saturate and LRU eviction thrashes active adapters. Mitigate this via bounded-load consistent hashing (capping per-node queue depth at 1.25x average) and admission shedding for unpinned free-tier adapters when HBM hit rate drops below 80%. When NOT to use S-LoRA: if you serve fewer than 3 high-QPS adapters per cluster, offline-merging W_0 + BA into dedicated TensorRT-LLM/vLLM replicas eliminates the ~5-8% SGMV kernel overhead.

Adapter Cache Admission & Thrashing Circuit Breaker

HBM hit rate < 85%PCIe queue > 15 msAutoscale + hit rate > 92%HEALTHY_HIT_RATEHBM hit rate >= 85%; norPREFETCH_PRESSUREPCIe DMA queue building;ADMISSION_SHEDDINGShed unpinned cold adapt

Interactive Visual Simulation

Mixed-Tenant SGMV Decode Step Trace

gateway

Inference Gateway

Bounded-Load Consistent Hash

route(adapter_id)
scheduler

Pod 07 Batch Scheduler

Continuous Batching

lookup pages
page_pool

Unified HBM Page Pool

KV + LoRA Page Table

gather A/B + W_0
sgmv_kernel

H100 Tensor Core + SGMV

Shared W_0 + Delta Compute

adapter_id

tenant-42-v2

target_pod

Pod 07

load_factor

1.08x

Consistent-Hash RoutingHealthy
Gateway hashes adapter_id='tenant-42-v2' to Pod 07 via bounded-load consistent hashing.
Engineering Decision Framework
Problem
How to serve 100 to 10,000+ tenant LoRA adapters on shared 80 GB H100 GPUs without duplicating the 140 GB base model W_0 or breaking continuous batching.
Naive Solution
Deploy dedicated GPU replicas per adapter or dynamically merge W_0 + (alpha/r)BA into GPU memory on every incoming request.
Why It Fails
Dedicated replicas exhaust GPU fleets at low utilization, while per-request weight merging serializes batches and triggers 500 ms to 2 s swap stalls.
Alternatives
Compare S-LoRA unified paging with Punica SGMV kernels against offline-merged dedicated replicas (TensorRT-LLM/vLLM) or naive dynamic LoRA swapping.
Engineering Decision
Use S-LoRA unified KV-plus-adapter paging with Punica SGMV kernels and bounded-load consistent hashing when serving 100+ Zipfian adapters; use offline-merged dedicated replicas only when serving fewer than 3 high-QPS flagship adapters.
Trade-Offs
Eliminates base model duplication and swap stalls for long-tail adapters, at the cost of ~5-8% SGMV kernel overhead and custom CUDA kernel maintenance.
Decision Exercise · Make the Call

During a product launch, 150 cold enterprise tenants hit Pod 07 simultaneously, dropping HBM adapter cache hit rate from 95% to 62% and spiking decode p99 from 45 ms to 320 ms. What is the root cause and immediate fix?

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 4
Score: 0/4

Why does merging LoRA weights (W_0 + BA) per request fail in high-throughput multi-tenant LLM serving?

Recommended Learning Flow