Damodar Kamani
Gardenml-systemsloravllminference

Distributed Inference for PEFT Models

Shallow rabbit holes in inference engineering and fine-tuning. TLDR; throughput went up 5x and was exactly zero points smarter.

28 min read

Finally got to it.

I'd wanted to try fine-tuning for a while. Then one afternoon I watched someone fine-tune Llama 2 in a Colab notebook in about twenty minutes, so I opened a notebook of my own, grabbed a small medical dataset 1 off Hugging Face, and pointed it at Qwen.

Training took five minutes. That left me holding an adapter right when my X feed was full of people talking about "inference engineering," and I'd been reading this book from Baseten 2 and the AI Engineering Guidebook. So I kept going.

The rest of this post is me building from a notebook then to three ways of serving the same model:

  • one GPU
  • one model split across two GPUs
  • two copies of the model, one per GPU

The best of those pushed ~5x the tokens per second of the first one at 64 concurrent users (and most of that was my own fault, which I'll get to). After that I finally ran evals, which turned into its own little side story (the excerpt spoils it).

Everything's in this repo, benchmark tables included.

The short version#

One flag got 2.5x. On a single A10G, letting vLLM run 32 requests at once instead of 8 took throughput from 117 to 296 tokens per second at 64 users. Same GPU and same model.

A second GPU doubled that, but only as a copy. Two independent copies of the model hit 590 tokens per second, 5x where I started. Splitting one model across both GPUs managed 315, because the two halves have to talk over PCIe at every layer. The split model does earn its keep on long prompts: 313 tokens per second against 170 on one GPU.

The scheduler from the paper lost. I implemented RAD, a scheduler that's provably throughput-optimal under its paper's model of a GPU. vLLM's default scheduler beat it by 20%.

Merging the adapter is free speed. Folding the LoRA weights into the model served up to 22% more tokens per second with the same benchmark scores.

The fine-tune learned a format and zero medicine. It looked 17 points better on MedQA under strict scoring. Scored by log-probability, it was 63.2% against the base model's 63.1%.

Figure 1. The whole project, from one notebook to three serving stacks.

A Llama dataset, adapted for Qwen... (what could go wrong)#

The video used a 1,000-example dataset in Llama 2's chat format. I wanted the same size but medical (because why not), and found a set of a thousand medical questions with answers. Small enough to train in one sitting.

A training example looks like this:

Is D-bifunctional protein deficiency inherited?

This condition is inherited in an autosomal recessive pattern, which means both copies of the gene in each cell have mutations...

Except every row is wrapped in Llama 2's chat syntax, so the raw text really looks like <s>[INST] Human: ... [/INST] Assistant: ... </s>. That syntax belongs to Llama. Other models use their own templates, and one of the first walls I hit was assuming Qwen would read it the way Llama does. Qwen has never seen [INST] in its life. If you train on those strings directly, you'd teach it to write Llama tags (a funny way to break a model).

So the first real code I wrote was preprocessing. A regex pulls the question and answer out, and each pair gets rebuilt as a conversation so Qwen's tokenizer can apply its own template later:

qwen_peft_medical.ipynbPython
match = re.fullmatch(
    r"\s*<s>\s*\[INST\]\s*(.*?)\s*\[/INST\]\s*(.*?)\s*</s>\s*",
    text, flags=re.DOTALL,
)
return {
    "prompt":     [{"role": "user",      "content": question}],
    "completion": [{"role": "assistant", "content": answer}],
}

Keeping the prompt and completion separate matters later, when we get to the loss.

LoRA, or how to fine-tune 2% of a model#

Qwen3-8B is about 8 billion numbers arranged in matrices, and full fine-tuning updates all of them. With the usual mixed-precision Adam setup, each parameter costs about 16 bytes during training (the weight, its gradient, the optimizer state), which comes to

8.2×109×16 bytes≈130 GB8.2 \times 10^9 \times 16\ \text{bytes} \approx 130\ \text{GB}

before you've stored a single activation. One GPU isn't even close.

This is where the LoRA paper3 comes in. A 4096 by 4096 update can be approximated by two thin matrices multiplied together, so you freeze the original WW and train only AA and BB. The paper writes it as

W′=W+αr BA,A∈Rr×k,  B∈Rd×rW' = W + \frac{\alpha}{r}\, B A, \qquad A \in \mathbb{R}^{r \times k},\; B \in \mathbb{R}^{d \times r}
Figure 2. One adapted layer. The frozen weight does the original work, and the adapter adds a small correction on the side.

At r=64r = 64, a 4096 to 4096 projection trains 64×(4096+4096)=524,28864 \times (4096 + 4096) = 524{,}288 parameters instead of 16,777,216. That's 3%.

The three MLP projections go between 4096 and 12288, so they cost more. Across all seven targets:

ProjectionShapeLoRA parameters at r = 64
q, o4096 to 4096524,288 each
k, v4096 to 1024327,680 each
gate, up, down4096 to 122881,048,576 each
One layer4,849,664
36 layers174,587,904

The trainer printed 174,587,904 trainable parameters out of 8.37 billion, or 2.09% of the model.

QLoRA4 goes one step further and barely changes anything. If the base weights are frozen anyway, why keep them in 16 bits? Store them in 4 (a format called NF4) and convert back up to 16 only when doing the math. That's half a byte per parameter, which puts the model around ~5 GB instead of 16.

Here's the config as the notebook has it:

qwen_peft_medical.ipynbPython
lora_r = 64            # width of the bottleneck
lora_alpha = 16        # updates get scaled by 16 / 64 = 0.25
lora_dropout = 0.1
target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                  "gate_proj", "up_proj", "down_proj"]

bnb_4bit_quant_type = "nf4"   # frozen base stored in 4 bits
learning_rate = 2e-4          # only the adapter moves
lr_scheduler_type = "cosine"
optim = "paged_adamw_32bit"   
max_grad_norm = 0.3
num_train_epochs = 1
per_device_train_batch_size = 4
completion_only_loss = True   # learn answers
max_length = 1024
<br />

On an A100 the whole run took 5 minutes and 3 seconds.

Training loss
loss
Step
Figure 3. Training loss every 25 steps. Most of the drop is over by step 50.

Loss fell from 1.47 to about 1.0 by step 50 and then wandered. At the time I read that as "it's learning." Looking back, it was the first hint of what the evals would say much later. The model grabbed whatever was easy and repeated across these answers almost right away, and after that there wasn't much left to take.

What does one request actually cost?#

Now I had a 175-million-parameter adapter. Using it means something has to load the 8B base model, attach the adapter, and answer requests. I went with vLLM5 because it serves a LoRA adapter on top of a base model out of the box, and Modal6 because it only runs (and bills) a GPU container while someone's using it, and the developer experience is genuinely smooth (I'd recommend it).

Before building anything I wanted a rough model of where the time and memory go.

Prefill, decode and the KV cache#

Prefill reads the whole prompt in one go and records what it learned about every token. It's one big matrix multiply, which is exactly the work GPUs are built for.

Decode is a reply one token at a time. Each step is tiny, one token's worth of math per request, and a single decode step leaves most of the GPU idle. The GPU only earns its keep when lots of requests decode together.

What prefill records is the KV cache, the attention keys and values for every token so far. It ends up limiting how many people one GPU can serve, so I worked out how big it is:

36⏟layers×8⏟KV heads×128⏟dims×2⏟K, V×2⏟bytes≈147 KB per token\underbrace{36}_{\text{layers}} \times \underbrace{8}_{\text{KV heads}} \times \underbrace{128}_{\text{dims}} \times \underbrace{2}_{K,\,V} \times \underbrace{2}_{\text{bytes}} \approx 147\ \text{KB per token}

A 24 GB GPU at 90% utilization gives you about 21.6 GB. The weights eat about 16.4 GB in 16-bit, which leaves roughly 5 GB, or about 35,000 tokens of cache shared by everyone on that GPU. With 750-token prompts and 128-token replies, that's room for about 40 conversations.

Keep that 35,000 in your head.

v1: why did it stop at 8 users?#

The first version was the obvious one. One 24 GB GPU, the whole model on it, vLLM with its default scheduler.

Figure 4. v1. The browser never sees Modal credentials. A small CPU app checks the GitHub login and proxies the stream.
serving/modal_app.pyBash
vllm serve Qwen/Qwen3-8B \
  --dtype bfloat16 --max-model-len 2048 --max-num-seqs 8 \
  --gpu-memory-utilization 0.90 --enforce-eager \
  --enable-lora --max-lora-rank 64 \
  --lora-modules qwen-medical=/adapters/medical

Most of these choices are about cost. The container scales to zero after five idle minutes, so an endpoint nobody's using costs nothing. I asked Modal for an L4 with an A10G as the fallback (in practice my runs landed on A10s and A10Gs). --enforce-eager skips CUDA graphs, which would shave some latency but eat memory and startup time on a server that cold-starts a lot.

For one person chatting, v1 was great. About ~18 tokens per second, first token in a third of a second.

Then I wrote a load test that pretends a bunch of people are typing at once. Each fake user sends a 750-token prompt full of unique text (nothing gets served from cache). At 8 users v1 was fine. At 16 it produced exactly the same throughput, and the wait for the first token jumped from 2 seconds to 9. At 64 users the median wait was 35 seconds.

The GPU hadn't slowed down. It was full. v1 admits 8 sequences and user number 9 waits in line until someone finishes, so throughput flattens at about 118 tokens per second and every extra user just makes the line longer.

And that 8 was my doing. The cache math said there was room for about 40 conversations, and I'd capped it at 8 to be safe, which meant one GPU configured my way simply wouldn't let anyone else in.

So how much was the cap costing me? I deployed a copy of v1 with one change, --max-num-seqs 32 instead of 8, pinned both versions to the same GPU type (an A10G), and ran the same test three times each.

64 users, ~750-token promptstokens/sfirst token, medianseconds per token
1 GPU, 8 in flight11735.4 s0.058
1 GPU, 32 in flight29613.9 s0.078

Same single GPU, one number changed, 2.5x the throughput. Each user's stream gets a bit slower (a bigger batch per step), but nobody's stuck in line for 35 seconds. Keep that 296 in mind, because every multi-GPU number below has to beat it, not 117.

v2: one model, two GPUs#

Intuitively, If the limit is admission, you need more KV cache, and the most direct way to get it is splitting the model across two GPUs. With tensor parallelism every weight matrix gets cut in half and each GPU holds one half, which frees up memory for cache.

On paper it's great. Each GPU holds about 8.2 GB of weights instead of 16.4, so the pair has roughly 26 GB for cache. That's about 175,000 tokens under one scheduler, five times what v1 had.

The two halves have to talk, though. Twice in every layer, once after attention and once after the MLP, the GPUs swap partial results (an all-reduce), and on Modal these GPUs connect over PCIe rather than NVLink. That exchange is slow, and it happens 72 times for every token.

Figure 5. v2. One model, split in half. Twice in every layer the two GPUs swap partial results.

More cache means more requests in flight, which raises an important question: in what order should the GPU work on them?

See, every step, the GPU can spend its time on prefill (someone's new prompt) or decode (one more token for everyone already going). It's an opportunity cost problem of sorts. Lean toward prefill and the people mid-answer start to stutter. Lean toward decode and new people wait in line before they see a single token. By default, vLLM admits new prompts eagerly, but I wanted a principled answer.

What I took from the RAD paper#

Around here I read Optimal Scheduling Algorithms for LLM Inference: Theory and Practice by Bari, Hegde and de Veciana7 (funny enough some of the authors went to my uni!). Most scheduling papers I'd skimmed start from an experiment. This one starts from a model of how a GPU does matrix math, derives what a throughput-optimal scheduler has to look like, and only then builds one. They call it RAD, for Resource-Aware Dynamic.

Below goes in some of the ideas I took to implement in here.

1. GPU charges by the tile#

A GPU doesn't multiply a matrix all at once. It cuts the output into fixed-size tiles and hands each tile to a processor (an SM), and the Tensor Cores only run at full speed for certain tile shapes. On an A100 a typical good tile is 128 by 256, with the shared inner dimension handled 32 at a time.

So a batch's time climbs in steps as you add tokens. As a back-of-the-envelope calculation, the linear layers cost

Tlinear(n)∝⌈nbrow⌉T_{\text{linear}}(n) \propto \left\lceil \frac{n}{b_{\text{row}}} \right\rceil

where nn is the number of tokens in the batch and browb_{\text{row}} is the tile height. With brow=128b_{\text{row}} = 128, a batch of 129 tokens costs the same as a batch of 256, and the extra 127 slots are padding the GPU computes and throws away.

I'd seen staircase-shaped latency plots before and written them off as noise (they come from that ceiling).

The solution in the paper is simple. Always prefill in chunks of LCM(brow,bcol,bred)\text{LCM}(b_{\text{row}}, b_{\text{col}}, b_{\text{red}}) tokens so every chunk tiles perfectly. For the A100 numbers above that's LCM(128,256,32)=256\text{LCM}(128, 256, 32) = 256, which is where my chunk = 256 default comes from.

2. Decode only pays off in a crowd#

The second assumption sounds obvious. Doing many matrix-vector multiplies separately is slower than stacking the vectors into a matrix and doing one matrix-matrix multiply.

Decode is matrix-vector work. Stacking 32 decoding requests together allows linear layers to become one real matrix multiply. (Attention can't be stacked the same way, since every request reads its own KV cache. The paper keeps that term separate, and I appreciated the honesty.)

So RAD has a decode mode. Once enough requests have finished prefill, it runs one decode step for all of them together and nothing else.

I could see this directly in the step counters my scheduler logs. Each request returned 128 tokens, with the first coming out of prefill, which leaves 127 to decode. At 8, 16, and 32 users every run finished in about 127 decode steps total. One shared pass per token regardless of how many people were in the batch, sitting right there in a log file.

The prefill counters checked out too. Prompts were 694 to 764 tokens, which is ⌈764/256⌉=3\lceil 764 / 256 \rceil = 3 chunks each. The logs said 25, 49, and 97 prefill steps at 8, 16, and 32 users, which works out to 3×8+13 \times 8 + 1, 3×16+13 \times 16 + 1, and 3×32+13 \times 32 + 1.

3. Cap...who's allowed to hold memory#

RAD limits the number of active requests (anything currently holding KV cache) to bcolb_{\text{col}}, the batch size that tiles decode perfectly. In my code that's max_active, defaulting to 64.

The assumption attached to it is where I got stuck. The proofs need GPU memory to hold the KV cache for bcolb_{\text{col}} requests at their maximum possible length, and the authors call that mild because bcolb_{\text{col}} is usually 64 or 128 and paged attention packs memory well.

On a big GPU, sure, but 24 GB card is not enough. My v1 cache held about 40 normal conversations or 20 long ones, so "64 at max length" was never true for me. I added an escape hatch the paper doesn't need. If a prefill step can't allocate cache blocks, the next step is forced to decode, which finishes requests and frees memory before another prefill tries:

serving/rad_policy.pyPython
def choose_mode(*, decoding, prefilling, waiting, started,
                params, prefill_blocked=False):
    if not (decoding or prefilling or waiting):
        return "idle"
    if decoding and (decoding >= params.max_active or prefill_blocked
                     or not (prefilling or waiting)
                     or (not prefilling and started >= params.cycle_requests)):
        return "decode"
    if not (prefilling or waiting) or (not prefilling and started >= params.cycle_requests):
        return "idle"
    return "prefill"

That's Algorithm 1 from the paper plus prefill_blocked. Remember this assumption, because a later benchmark makes use of it.

4. Cycles have to end#

RAD works in cycles. Within a cycle it admits up to NN new requests. Once NN have started it stops admitting and finishes everyone still decoding, even if those last batches don't tile perfectly. Then the next cycle starts.

As far as I can tell, this is what makes the proof work. Draining guarantees every cycle ends in finite time, so they can treat the system as a Markov chain that keeps returning to empty. Without it, a steady stream of arrivals could hold one cycle open forever.

5. What the paper assumes away#

The paper is upfront about what it simplifies which leads to some differences in what I did

A tensor-parallel group is modeled as one GPU. The paper calls this "without loss of generality". Modal uses PCIe which is slower compared to using NVLink that's a fair simplification.

Routing across identical nodes can be random. With multiple inference nodes, the paper shows that sending each request to a uniformly random node is enough for throughput optimality.

Nodes don't turn on and off. The authors mention systems that power nodes up under load and explicitly leave them out of the analysis. That one comes back too.

Throughput is our target. RAD maximizes requests per second, and the paper admits it can give bad time-between-tokens. If a request finishes in nearly every decode batch, RAD has to squeeze a whole new prefill between consecutive decode steps and everyone stutters. They also mention SLAI which is something I didn't implement here, but maybe for a future direciton.

How RAD plugs into vLLM#

I had zero interest in writing my own scheduler. vLLM's already handles memory allocation, preemption, and LoRA, and messing up memory accounting is a great way to get garbage outputs. So RAD subclasses it. Each step it asks the policy which mode to be in, hides the requests that mode shouldn't run, and lets vLLM's scheduler handle whatever's left.

Figure 6. RAD's modes, as I implemented them. The policy lives in its own file with no vLLM imports, so it can be unit-tested on a laptop.
Figure 7. One scheduling step. RAD only decides who's visible, and vLLM still does the real work.

So how do you tell which requests are decoding? In vLLM, a request is decoding when it has at most one token left uncomputed. That one line, num_tokens - num_computed_tokens <= 1, is the entire boundary between the paper's two sets.

If vLLM preempts a request while others are hidden, that preempted request has to land back at the front of the real waiting queue, or it just goes away.

max_active and chunk get read from a small key-value store every two seconds, which let you sweep without paying for a two-GPU cold start each time.

My first benchmark said v2 was worse#

The first run was pretty easy, one to eight users with short prompts. v2 lost everywhere. One user got 13.3 tokens per second against v1's 17.9, and the first token took two to four times longer. RAD and vLLM's stock scheduler, both on v2, matched each other almost exactly.

I was annoyed for about an hour before I realized the numbers matched the design. Eight short requests fit on one GPU, so v2's extra cache had nothing to do, and all the second GPU added was a PCIe round trip on every token (the cost the paper's model leaves out and the fact that modal uses PCIe and not NVLink).

v2 only makes sense when more people show up than one GPU will let in. Same day (6 November, both stacks on A10Gs), ~750-token prompts, 8 to 32 users:

Users at oncev1 tokens/sv1 first token (median)v2 tokens/sv2 first token (median)
896.61.9 s102.61.2 s
16101.410.4 s180.61.9 s
32102.920.2 s308.93.2 s

At 32 users v2 produced three times the tokens and started streaming in 3 seconds where v1 took 20. I reran it five minutes later and got the same numbers within a few percent. (This is the run where the step counters came out to 127 decodes and 3n+13n + 1 prefills.) v1 plateaus near 100 tokens per second here and near 118 in the 7 November runs below, which ran on a different GPU (an A10).

Did RAD actually help?#

That table says v2 beat v1. It doesn't say RAD did, since v1 also had a smaller cache and a smaller cap. So I ran v2 with vLLM's stock scheduler and with RAD on the same two pinned A10Gs, back to back, three times.

v2, ~750-token prompts, usersstock vLLM tokens/sRAD tokens/sstock first tokenRAD first token
892862.1 s2.2 s
161541382.8 s3.6 s
322321915.0 s6.7 s
643152528.7 s12.1 s

It didn't. RAD was behind at every load, about 20% at 64 users, and people waited longer for their first token. A run with long prompts said the same thing (313 tokens per second stock, 281 with RAD).

If I were to say why, it would be due to RAD prefilling one prompt at a time in 256-token chunks, while vLLM's default packs up to 2,048 tokens of prefill into a step. So I think I paid for small chunks and got none of what they're supposed to get back in gains.

v3: what if each GPU just had its own copy? (the easiest approach)#

v2 can be annoying for 2 reasons. It bills two GPUs all the time and every token pays for more overhead via PCIe whether or not extra cache is needed.

So I went back to the simpler question. What if each GPU had its own replica of the model, with something in front spreading requests across them?

That's data parallelism, two replicas you have (think like database replicas). Each request runs start to finish on one GPU at single-GPU speed. You get two separate caches and two batches, and give up the one big shared cache.

It's also almost exactly the setup from the paper's routing section, identical nodes with something in front picking one per request. On Modal that something is the autoscaler, and each replica is just a v1-style container.

Figure 8. v3. Modal routes the requests and starts the second replica only under load.

Here it departs from the paper. Remember the assumption that nodes don't turn on and off? Mine do. The second replica takes about 70 seconds to boot.

Figure 9. Scaling out. The second replica's cold start falls on people already in line.

I built two versions to pull the effects apart. Narrow gives each replica 8 slots, so it's literally two v1s. Wide gives each replica 32, matching v2's total of 64. Wide is for reasons bet on cache: about 40 normal conversations fit on one GPU, so 32 should be safe.

Before running anything, I wrote down some hypotheses for v3 to win and lose:

  1. Beat v1 above 8 users.
  2. Beat v2 on per-token speed, since there's no cross-GPU exchange.
  3. Cost less than v2 when traffic is light.
  4. Lose to v2 on long prompts, where two small caches can't match one big one.
  5. Lose on sudden bursts, for cold starts.

Five kinds of traffic on four servers#

The final run put all four stacks (v1, v2, v3-narrow, v3-wide) through five scenarios on 7 November. Every request streamed a fixed number of tokens, and every prompt carried unique text so prefix caching couldn't skip any work. The whole campaign, including two runs I had to redo, cost about $3.70.

Lots of users, normal prompts#

Output tokens per second, capacity scenario
tokens / s
Users at once
  • v1
  • v2 (RAD)
  • v3-narrow
  • v3-wide
Figure 10. Throughput with ~750-token prompts. v1 flattens at its 8-slot cap, and v3-narrow at 2 x 8.
Time to first token (median)
seconds
Users at once
  • v1
  • v2 (RAD)
  • v3-wide
Figure 11. Median wait for the first token. v1's wait is just the length of its queue.

Prediction 1 held. v3-wide won outright with 522 tokens per second at 64 users, against v2's 401.

Prediction 2 held only under load. At 64 users each v3-wide stream got 0.083 seconds per token against v2's 0.116, since no token waits on a cross-GPU exchange. With one user, though, v2 decoded at 0.058 seconds per token, close to v1's 0.054. Part of v2's slowdown under load is just bigger batches: v3-wide has no cross-GPU traffic at all and still goes from 0.061 to 0.083 as each replica fills up. v2 pays for the exchange on top of that, and the exchange carries more data the bigger the batch, so the "PCIe tax" mostly shows up in a crowd.

Time per output token (median)
seconds / token
Users at once
  • v1
  • v2 (RAD)
  • v3-narrow
  • v3-wide
Figure 12. What each user feels: median seconds per output token. v1 and v3-narrow stay flat because they never batch more than 8. v2's cross-GPU exchange grows with the batch.

v3-narrow tops out around 220 because 2 x 8 slots is all it has, and it wakes the second GPU at just 6 requests in flight, paying for two GPUs long before it needs them.

Long prompts#

Prediction 4 is the one the cache math said v3 should lose. With 1,500-token prompts and 256-token replies, each conversation needs about twice the cache.

Output tokens per second, long-context scenario
tokens / s
Users at once
  • v1
  • v2 (RAD)
  • v3-narrow
  • v3-wide
Figure 13. Throughput with ~1,500-token prompts. v2's pooled cache wins, and v3-wide had to evict and recompute requests.

It lost, which five lines of arithmetic had told me before I sent a single request. At 1,7561{,}756 tokens per conversation, 35,000 tokens of cache holds about 20 conversations per GPU, and v3-wide lets in 32.

This is the memory assumption from earlier, broken on purpose. v3 runs vLLM's default scheduler rather than RAD, but it breaks the same assumption RAD rely's on, that the cache can hold every active request at full length. v3-wide lies about having more than fit, so vLLM preempts:

Users at oncev2 first token, p99v3-wide first token, p99v3-wide preemptions
162.8 s4.2 s0
325.6 s22.8 s3
6415.3 s30.6 s6

v2's 175,000-token pool never had to evict anything.

A sudden burst#

Twenty-four users arrive at once (idle server):

tokens/sfirst token, medianfirst token, p99GPUs
v111910.3 s19.0 s1
v22622.4 s4.2 s2
v3-narrow, second replica cold9711.2 s23.4 s2 (one booting)
v3-wide2412.7 s4.8 s1

Prediction 5 was half right. v3-narrow tried to scale out, and its second replica spent most of the burst booting, so it ended up slower than v1 while paying for two GPUs. That's the 70-second boot the paper's model has no room for. v3-wide had no need.

Light use, long answers, and the bill#

With one to eight users every stack delivered 16 to 19 tokens per second per user, so nobody won on speed, and v1 did it on one GPU while v2 billed two. With 512-token replies at 16 users, the multi-GPU stacks hit 246 to 263 tokens per second against v1's 143, because half of v1's users were stuck in its queue.

Prediction 3 held for v3-wide and missed for v3-narrow. v3-wide stayed on one GPU through 8 users, so at light load it costs what v1 costs, about half of v2. v3-narrow's 6-request trigger fired at 8 users and it started paying for a second GPU it didn't need.

Cost per 1M output tokens, light scenario
dollars
Users at once
  • v1
  • v2 (RAD)
  • v3-narrow
  • v3-wide
Figure 14. GPU dollars per million output tokens at light load. v2 bills two GPUs from the first request. v3-narrow jumps at 8 users, when its second replica wakes.

Once the GPUs are busy, the order flips. v1 ran about $2.60 per million output tokens at full load, while v3-wide (64 normal users) and v2 (64 long-prompt users) both got down to $1.17, because two busy GPUs serve far more than twice the users. A single user is the expensive case: with 512-token replies, the two-GPU setups cost around $33 to $36 per million tokens, about twice v1, because the second GPU just sits there.

v3-narrow never won a single scenario, so it's gone.

Same hardware, three runs each#

The comparisons that decide the design ran on one GPU type (A10G, no fallback), three runs each, and the runs agreed within a few percent.

Output tokens per second, capacity scenario
tokens / s
Users at once
  • 1 GPU, 8 in flight
  • 1 GPU, 32 in flight
  • 2 copies (v3-wide)
Figure 15. ~750-token prompts, all on A10Gs, median of three runs. One GPU at 32 in flight gets 2.5x the cap-8 version. Two copies then double that.

So the 5x was really two things stacked. About 2.5x came from raising the cap on the same single GPU. The other 2x came from the second GPU, and it's an almost perfect 2x: 590 is basically 296 twice. Copies are able to scale cleanly because they share nothing.

Long prompts are where the cache math comes again. With 1,500-token prompts, the one GPU at 32 in flight held at about 170 tokens per second, and at 64 users vLLM had to evict and recompute 8 requests. The slowest 1% waited 79 seconds for a first token. The cap-8 version never evicted anything, but its median user waited 70 seconds just to get in line. About 20 long conversations fit on one GPU, so the right cap for long prompts sits somewhere between those two, and 32 overshoots it.

Split models are similar too. On these A10Gs, v2 with vLLM's stock scheduler reaches 315 tokens per second with normal prompts, close to one GPU at 32 in flight and about half of two copies, so copies win that workload outright. With long prompts the pooled cache earns its keep: 313 tokens per second against 170 for one GPU, and nothing evicted. (The 401 for v2 in Figure 10 comes from the scenario sweep, where v2's GPU type wasn't recorded.)

If I had to pick today: raise the cap on the first GPU to whatever the KV-cache math says fits (about 32 for normal prompts here, closer to 20 for long ones), then add copies, which scaled almost perfectly. Split one model across GPUs only when the prompts are long enough that one GPU's cache can't hold the crowd.

TrafficBestWhy
1 to 8 usersOne GPUNothing to admit, and one GPU is cheapest
Up to ~32 normal usersOne GPU, cap raised to 322.5x the cap-8 version on the same hardware
Many users, normal promptsv3-wideTwo full batches, no cross-GPU tax, scales almost exactly 2x
Many users, long promptsv2One shared cache, five times bigger
Cold burstv2 or v3-widev3-wide fits it on one GPU, v3-narrow is the worst
Idlev1 or v3Both scale to zero, v2 always bills two GPUs

Do stacks give the same answers? They should, since the weights are identical, right? I sent 16 prompts one at a time with no sampling randomness, to v1 twice and then to v2 and v3. v1 disagreed with itself on 11 of the 16. Greedy decoding on vLLM isn't bit-for-bit repeatable once batching, cache hits, and slightly different GPUs get involved. v2 and v3 drifted from v1 by no more than v1 drifted from itself, so splitting or copying the model leaves its answers alone.

Compared with v1's first runExact matchMean shared prefix
v1, asked again31%61%
v362%73%
v231%59%

So did the fine-tune actually work?#

Serving was what I set out to learn, and I'd been putting off what I originally set out to do. Is the fine-tuned model any better at medicine than plain Qwen3-8B?

I asked both models the same questions through the same server at temperature 0, across three benchmarks: all 1,273 MedQA questions (USMLE-style clinical vignettes), 1,000 from MedMCQA, and 1,000 from PubMedQA. None of them overlap the training data.

My first pass at scoring was strict. The model got 8 tokens, and the reply had to start with the answer letter.

Strict scoringMedQAMedMCQAPubMedQA
Adapter vs base63.4% vs 46.0%57.6% vs 51.2%48.3% vs 48.5%

The base model started 560 of its 3,273 replies with an explanation, something like "The clinical presentation is consistent with...", and ran out of its 8 tokens before naming a letter. Every one of those got marked wrong. The adapter did that 15 times.

The adapter had learned to be brief. Every answer in the training data gets straight to the point, so the model learned to get straight to the point, and my scoring rewarded exactly that.

To measure what each model knows separately from how it formats, I added two more ways of scoring. The lenient one re-asks any unanswered question with 384 tokens. The log-probability one ends the prompt with "The answer is (" and reads off which letter the model thinks is most likely, without generating anything. Both models put at least 97.5% of their probability on A through D, so that reads their choice directly.

Accuracy, adapter vs base
% correct
  • Base
  • Adapter
Figure 16. The same answers, scored two ways. Strict scoring puts the adapter far ahead. Read by log-probability, the two models land on top of each other.
Adapter vs baseMedQAMedMCQA
Lenient (retry with 384 tokens)63.6% vs 62.5%, p = 0.3157.8% vs 58.8%, p = 0.47
Log-probability63.2% vs 63.1%, p = 1.058.1% vs 58.5%, p = 0.73

That's a tie. (The p-values are exact McNemar tests on the paired answers, and the 95% intervals are about ±3 points either way.) PubMedQA was a wash for a different reason. Both models said "maybe" about half the time when only 11% of the true labels are "maybe," which pins both near 48%.

So the adapter picked up a style, concise and answer-first, and no measurable medical knowledge. Obvious in hindsight, since a thousand short chat answers teach tone and little else. The loss curve flattening after step 50 was telling me the same thing back in the notebook, and I didn't know how to read it yet.

For a real knowledge gain I'd train on exam-style or guideline data and score with log-probabilities from the start.

What does keeping the adapter separate cost?#

vLLM serves a LoRA adapter on the side: every adapted layer runs the base matrix multiply plus the two thin LoRA ones. The alternative is to fold the adapter into the weights once (merge_and_unload in PEFT) and serve the result as a plain model. I merged it on Modal and ran both versions on one pinned A10G at 32 in flight, for three runs each.

1 GPU, 32 in flightLoRA tokens/smerged tokens/sLoRA seconds per tokenmerged seconds per token
8 users1151400.0580.046
64 users2963190.0780.070

Merged was 22% faster at 8 users and 8% faster at 64. The LoRA overhead matters most when the batch is small, which makes sense, since that's when the extra little matrix multiplies are a bigger share of each step.

Something I didn't expect was the merged and LoRA didn't write the same words. With greedy decoding, the LoRA server matched its own earlier answers exactly 50% of the time, and the merged server matched LoRA only 19% of the time. My guess is rounding, since folding a small update into bfloat16 weights rounds it. But scored by log-probability, they're the same model:

Log-probability scoring, same dayMedQAMedMCQA
LoRA63.5%57.7%
merged63.1%58.8%

They picked the same answer letter on 98.8% of the MedQA questions and 96.8% of the MedMCQA ones. So if you're serving one adapter, merge it. You get the speed back and lose nothing measurable. Keep LoRA when one server has to host several adapters, since that's what the side-by-side setup is for.

What I'd do differently#

Write the predictions down first --> KV-cache math told me v3 would lose on long prompts before I'd sent a single request.

Read the assumptions as closely as the algorithm. My favorite parts of the RAD paper were its simplifications.

Isolate the scheduler. I'm a little embarrassed by this one. RAD was the part I spent the most time on, v2 beat v1, and I almost gave RAD the credit. Stock vLLM on the same two GPUs was 20% faster.

Fill the first GPU before buying a second. Raising one number got 2.5x. Then split based on traffic. Copies for lots of normal users, one big split model for long contexts.

Be suspicious of a big win from a small change. The 17-point jump was a bait-and-switch, and it was formatting, LOL.

Notes and references

  1. Fine-tuning medical dataset, https://huggingface.co/datasets/nihal-mp/erkamd-human_assistant-llama2-1k ↩

  2. Frontier Inference for AI Workloads, https://www.baseten.co/ ↩

  3. Hu et al., LoRA: Low-Rank Adaptation of Large Language Models, arXiv:2106.09685. ↩

  4. Dettmers et al., QLoRA: Efficient Finetuning of Quantized LLMs, arXiv:2305.14314. ↩

  5. Kwon et al., Efficient Memory Management for Large Language Model Serving with PagedAttention, arXiv:2309.06180. ↩

  6. Modal, serverless GPU containers billed per second, https://modal.com/ ↩

  7. Bari, Hegde and de Veciana, Optimal Scheduling Algorithms for LLM Inference: Theory and Practice, Proc. ACM Meas. Anal. Comput. Syst. 9(3), 2025. arXiv:2508.01002. ↩