12 · Serve, merge and run many adapters
Merged into the weights, an adapter ran 2.1 times faster and changed 2 of 500 answers; kept apart, 32 adapters shared one base in 5.5 GB where 32 merged copies need 98.9 GB, and merging into a 4-bit base cost 18.8 points.
- Part 4
- Ship
- Model
Qwen/Qwen2.5-1.5B-Instruct- Data
- The SQL splits from lesson 3
- Hardware
- One T4, in Google Colab
Lesson 11 ended with an adapter that had passed its checks. Putting it into service raises a question that training does not: a company that owns one base model and several adapters, one per tenant, product line or language, has to decide whether to keep each adapter apart from the base, fold it into the weights, or do both. Four published cases sit at different points of that choice:
| Company | What is served | Reported |
|---|---|---|
| BMW Group (with AWS) | Task adapters on Gemma 4 E4B, all behind one real-time endpoint | One shared base on a single GPU; an adapter is "tens of megabytes" against a base of tens of gigabytes. A 12-week pilot, company-reported |
| Predibase | 25 LoRA fine-tunes of Mistral-7B-Instruct on one A100 80 GB (LoRA Land) | Time to first token 148 to 171 ms from 1 to 50 concurrent users; 12 to 13.5 ms per generated token with or without adapters. Company research and demo |
| Kasisto | A LoRA-tuned Gemma 3 12B, then quantised to 4-bit weights with 16-bit activations | 24 GB down to 8.4 GB; 0.57 s per answer on one RTX 6000 Ada. In production |
| Dialpad | Qwen2-7B served from a 4-bit base on an NVIDIA T4 | Quantised first, then trained with QLoRA: call-outcome F1 0.835 against 0.798 for a 16-bit fine-tune |
BMW and Predibase keep adapters separate so that many share one base. Kasisto ends with a single compact model. Dialpad chose the order of operations, quantise and then train, that this lesson shows to matter. None of these is a recipe for your service, but each is a decision the lesson measures on a small model.
The result first, then how it was reached; the exact setup, time and cost are in How it was built at the end. Figure 1 shows the speed result the lesson turns on: merged into the weights, an adapter costs nothing per token; kept apart, it more than doubles the time.
Merged, the adapter runs at the base model's speed; unmerged, it runs at under half
Generation speed for 64 new tokens, median of 5 runs after one warm-up: tokens per second (bar), milliseconds per step, and speed against the base model
1The lab trains two adapters on the course's Qwen2.5-1.5B-Instruct, because "many" needs more than one. Adapter w learns WikiSQL-style questions, where every table has an anonymous name such as table_name_85; adapter n learns questions about named tables (head, concert, customer) from the Spider benchmark. Each trains on 2,400 examples of its own kind. The test set is 250 + 250, stratified by kind, because a random 500 holds only about 34 named-table questions, too few to show an adapter's effect. That makes every score here incomparable with lessons 4 and 5, whose 500 questions were drawn at random from the whole test split (3,923 questions, of which 267 are named-table, so about 34 of 500). Reweighting this lesson's base-model scores to the test split's mix, 93.2% wiki-style and 6.8% named, gives about 59.3% against lesson 4's 58.4% for the same model (derived), so the base model is the same; the 47.0% overall here is simply a half-and-half mix. The ± on each score is the 95% interval for 250 questions, about 6 points.
1. Three ways to serve
A trained adapter and the base model are two artefacts. You can serve them together as separate components or combine their weights. That is a deployment choice, so compare the resulting behaviour and cost under the same workload.
A LoRA layer computes with the frozen weight and the two small matrices and . The adapter can be served in three shapes:
| Shape | What sits in GPU memory | Strength | Cost |
|---|---|---|---|
| Merged, one model per adapter | One full model per adapter, | No extra work per token | A full copy of the base each |
| Unmerged, shared base | One base and N small adapters | N adapters for almost the price of one | Extra work in every adapted layer |
| Mixed batch | The same, with rows of one batch using different adapters | Traffic for many adapters shares a batch | Extra work grows with the adapters in the batch |
The rest of the lesson measures each cost in turn. A router has to choose the adapter; here it is a rule in the schema (a table named table_... goes to w, anything else to n), and in a service it would key on a tenant or a request header.
2. Does each adapter earn its place?
Both adapters load onto one copy of the base with PEFT. set_adapter picks the active one and disable_adapter gives the base model, so the three systems share one set of base weights.
model = PeftModel.from_pretrained(base, "adapter_w", adapter_name="w")
model.load_adapter("adapter_n", adapter_name="n") # a second adapter on the same base
with model.disable_adapter(): # the bare base model
evaluate("base, no adapter", model, eval_rows)
model.set_adapter("w") # one adapter active at a time
evaluate("adapter w (unmerged)", model, eval_rows)Each adapter lifts its own kind of question and costs the other; routing between them keeps both gains
Exact match on 250 held-out questions of each kind, % (bar, 95% interval), then over all 500 and the share of queries that run
2Each adapter helps its own kind. Adapter w lifts WikiSQL-style questions from 61.2% to 70.4%; adapter n lifts named tables from 32.8% to 65.2%, which is the larger move by far, since the base model is weakest there. Each also hurts the other kind: w falls from 32.8% to 24.4% on named tables, and n from 61.2% to 54.0% on wiki questions. Treating the two scores as independent, the combined interval on a difference is about ±8 points. That puts w's gain on its own kind (+9.2) and n's gain (+32.4) outside the noise, w's loss on named tables (−8.4) at its edge, and n's loss on wiki questions (−7.2) inside it.
Routing is the point. With every question sent to the adapter trained for its kind, the system scores 70.4% and 65.2%, 67.8% over all 500, against 47.0% for the base model. A single adapter cannot do that: w alone scores 47.4% overall and n alone 59.6%. The business reading is that adapters should be split along a line the routing rule can see, such as a tenant or a product, and that an adapter trained for one kind of traffic should not be sent another.
3. Why merging is exact on paper
Matrix multiplication is associative and distributes over addition, so
The merged weight has the shape of the original, so the model needs no extra branch, and the original is recoverable as . The LoRA paper states the consequence: merged, an adapted model adds no inference latency. It also states the limit this lesson returns to in section 8, that merged weights cannot serve a batch whose rows use different adapters.
On paper nothing is approximated. In a real model must be stored in the dtype of . A 16-bit float carries 10 fraction bits, so the spacing between neighbouring values near a weight is between and , and an update entry smaller than half that spacing disappears when it is added. Rounding errors are of the order of that spacing, so the share of the update lost is roughly
The notebook checks both halves. On random matrices the two forms agree to 4.4 × 10⁻¹⁵ in float64 and to 2.0 × 10⁻³ in fp16, where outputs are of size 0.64. On the real adapter it merges by hand into each of the 196 adapted layers the way PEFT does, in float32, then stores in fp16:
delta = (m.lora_B["w"].weight @ m.lora_A["w"].weight) * m.scaling["w"] # s·BA, float32
exact = Wt.float() + delta # W' exactly
merged = exact.to(Wt.dtype) # stored in fp16
lost = (merged.float() - exact).norm() / delta.norm() # update lost
same = (merged == Wt).float().mean() # entries unchangedRounding to fp16 loses 3% to 7% of the update, and loses most where the update is smallest beside the weight
Adapter w merged by hand into each of the 196 adapted layers (computed in float32, stored in fp16); median by layer type
3The update is small: 0.3% to 0.7% of the weight's rms. Between 3.0% and 6.8% of it is rounded away, and 3.3% to 7.8% of weights do not change at all. The proportionality is visible in the numbers: the share lost times the update's size relative to the weight comes to 2.0 to 2.1 × 10⁻⁴ in all seven layer types. down_proj, whose update is half the relative size of the others, loses twice the share. The rounding is also exactly what the formula predicted: the merged weight of layer 14's down_proj equals the weight computed by hand in all 13,762,560 entries.
4. Does the merged model write the same answers?
merge_and_unload() folds the adapter in and returns a plain Qwen2ForCausalLM with no LoRA layers left. It was loaded from the saved adapter on a fresh base, so what is scored is what was saved.
merged_w = PeftModel.from_pretrained(
AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype=DTYPE, device_map={"": DEVICE}), "adapter_w"
).merge_and_unload().eval() # a plain model| Adapter w, 500 questions | Unmerged | Merged |
|---|---|---|
| Exact match | 47.4% | 47.4% |
| Queries that run | 93.8% | 93.6% |
| Answers that differ from the unmerged ones | 2 of 500 | |
| Exact-match flips, either way | 0 | |
| Queries that stopped running | 1 |
Two answers out of 500 changed, neither affecting exact match, and one no longer runs. It is a named-table question answered by the wrong adapter, where the model is on a knife edge:
unmerged: SELECT cust_name, acc_type, acc_bal FROM customer WHERE credit_score = (SELECT MAX(credit_score) FROM customer)
merged: SELECT cust_name, acc_type, acc_bal FROM customer WHERE credit_score = MAX(credit_score)Adapter w, a named-table question where merging changed the answer (Spider, customer table)
- Gold
- SELECT cust_name, acc_type, acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
- Unmerged
- SELECT cust_name, acc_type, acc_bal FROM customer WHERE credit_score = (SELECT MAX(credit_score) FROM customer)
- Merged
- SELECT cust_name, acc_type, acc_bal FROM customer WHERE credit_score = MAX(credit_score)
The unmerged answer is a valid alternative to the gold query; the merged one no longer runs. Both come from the wrong adapter, which is why the model is near a tie.
The second of the two answers that differed
- Gold
- SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'
- Unmerged
- SELECT cust_name FROM customer WHERE acc_type = "saving"
- Merged
- SELECT cust_name FROM customer WHERE acc_type = "Savings"
Both are wrong in the same way (the gold query asks for the opposite set); only the literal moved.
To see whether merging is the lossy step, the notebook compares the next-token scores of both against a float32 merged model, the nearest thing to the exact value. The unmerged model differs from it by 0.0088 on average and the merged model by 0.0096, and both pick the same top token as the reference on all 32 test prompts. Merging is not the lossy step; the unmerged model rounds twice and the merged one once, in a different place, and each is within rounding of the exact result. For a single adapter in fp16, merging changes a rare answer and does not move the score.
5. Is merged faster?
An unmerged adapter adds, in each of 196 layers, two small matrix products and a cast. Each is tiny, but at batch 1 a decoding step is a few hundred small kernels, so the extra launches should matter. At batch 16 each kernel does more work, so the gap should shrink. AWS's post on multi-tenant LoRA serving states the trade in these terms: merged weights add no latency while running but cost something to apply or remove and suit a few adapters, while unmerged adapters add latency and support mixed batches. The notebook measures 64 new tokens, the median of 5 runs after a warm-up; the result is Figure 1, at the top of the page.
The merged model runs at the base model's speed (0.99× and 1.01×), and the unmerged adapter at 0.46× and 0.48×: merging is 2.17 times faster at batch 1 and 2.09 times at batch 16. The prediction that the gap shrinks with batch size was wrong. The extra time per step is almost constant, 38.7 ms at batch 1 and 41.5 ms at batch 16, which is what a cost per kernel looks like and not a cost per number multiplied. Part of it comes from PEFT keeping the adapter in float32 beside an fp16 base, which adds casts; fp16 adapters would narrow the gap and were not measured. Scored over the 500 questions, answers took 103 ms merged against 202 ms unmerged.
6. What changes when the base is 4-bit?
A 4-bit weight is a code from a table of 16 values, shared by a block of 64 weights through the block's largest value. To merge, PEFT dequantises, adds the update and quantises again. The update is under 1% of a typical weight, while neighbouring levels near zero in NF4 sit about 8% to 9% of the block's largest weight apart (lesson 5's table: 0.0796 and −0.0911). Half that spacing is always much more than the update. A weight already on a level therefore returns to the same level for most entries, and the update vanishes. Merging in fp16 first and quantising after behaves differently, because the sum falls somewhere inside a cell and the update nudges which level is chosen. That is the explanation the numbers below are consistent with; the notebook does not measure how many weights returned to their level. PEFT warns that merging into a 4-bit layer "may get different generations due to rounding errors".
Three ways to serve adapter w, on the 250 WikiSQL-style questions, against the fp16 reference:
m4 = PeftModel.from_pretrained(load_4bit(MODEL_ID), "adapter_w").eval() # A
m4 = m4.merge_and_unload() # B
m4c = load_4bit("merged_w_fp16") # CMerging into a 4-bit base cost 18.8 points; merging in fp16 first and quantising after cost 2.0, inside the noise
Adapter w on 250 WikiSQL-style questions: exact match, % (dot, 95% interval); answers that differ from the fp16 reference; queries that run; time per example
4A, the adapter kept apart on a 4-bit base, scores 67.6%, 2.8 points under the reference and inside the noise. C, merged in fp16 and quantised once, scores 68.4%, also inside the noise, and A and C do not differ from each other. B scores 51.6%, 18.8 points below the reference and well outside it, and 9.6 points under the fp16 base model with no adapter on these questions (61.2%). A trained adapter absorbs the first rounding, as lesson 5 found, and loses most of its effect when merged into weights already rounded.
A score inside the noise is not the same behaviour: A and C each differ from the reference in about one answer in eight (29 and 31 of 250), and B and C differ from each other in 92. Re-run the evaluation after every change of precision.
The published record points the same way. QA-LoRA reports that quantising after a QLoRA fine-tune costs accuracy (LLaMA-7B on Alpaca, 5-shot MMLU: 38.4 kept in 4+16 bits, 36.0 quantised to 4 bits after merging, 39.4 with QA-LoRA's own method), a different model and task but the same step. Dialpad avoided the step by quantising first and then training. Kasisto's paper reports the result of quantising its fine-tuned 12B model without describing the merge. I could not find a company that says it merged adapters into 4-bit weights.
The two safe options have different costs. C gives one 4-bit model of about 1.1 GB (derived) for each adapter, so it is the right shape for a single adapter on a small GPU. A keeps one base for all adapters and runs slower: 262 ms per example against 135 ms for C.
7. How many adapters fit?
An adapter is a file of 74 MB in this lab, and loading it adds 74 MB of GPU memory. A merged model costs a full copy of the base, 3.09 GB.
for name in pool[2:]: # copies, new names
model.load_adapter("adapter_w", adapter_name=name) # 74 MB eachThirty-two adapters share one base in 5.5 GB; thirty-two merged copies would need 98.9 GB, six times a T4
GPU memory to hold N adapters: one shared base plus N adapters (measured growth) against N separate merged models (computed), GB, log scales
5Thirty-two adapters on one base take 5.5 GB, and 32 merged copies would take 98.9 GB, 18 times more. The shared layout would hold on the order of 170 adapters on this GPU by weights alone (an extrapolation from 74 MB each, before activations). Predibase's LoRA Land puts 25 adapters on one A100 80 GB and reports no significant difference in time to first token between the base model and the adapters; the benchmark is the company's own, on its own server. BMW describes the same layout for its adapters, loaded from GPU, CPU or disk "in milliseconds", which is a claim about its container and was not tested here.
Switching costs are separate from memory, and the notebook measures three:
| Operation | Time | Note |
|---|---|---|
load_adapter from local disk | 691 ms (median of 30) | A cold load; a server keeps adapters resident |
set_adapter | 95 ms (200 switches, 32 adapters loaded) | Not a pointer change: longer than a decoding step of the unmerged model, 71 ms at batch 1 |
merge_adapter or unmerge_adapter | 124 ms and 123 ms | One adapter, all 28 layers |
Changing adapter by merging and unmerging has a second cost: it is not reversible in fp16. After merging w and unmerging it, 683,841 of the 66,060,288 q_proj entries (1.04%) differed from the originals, by as much as 2.4 × 10⁻⁴. The merge had changed 96.4% of those entries. The base weights drift each time, so a service that swaps adapters this way should reload the base from disk now and then. A model that never swaps, one adapter merged once, does not have the problem.
8. Can different adapters share a batch?
LoRA's authors noted that merged weights cannot serve a batch whose rows need different adapters, and that unmerged adapters can, at some latency. PEFT supports it with one adapter name per row:
# row i uses adapter routed[i]; refused if merged
answers, ms = generate(model, tok, prompts, adapter_names=routed)Its mixed-batch code runs the base layer once for the whole batch, then, for each distinct adapter in it, selects that adapter's rows and adds its two small products. The result is correct: the routed system served in mixed batches of 16 gave the same answers as the two single-adapter runs for all 500 questions (0 differ), at 67.8% exact match and 97.2% of queries running. It was slow, 726 ms per example against 202 and 272 ms for w and n alone, about three times their average. Cost grows with the number of distinct adapters in the batch:
In PEFT's mixed batches each extra adapter adds about 67 ms to every step, so 16 adapters run at 14 tokens per second
Batch of 16 questions served by k distinct adapters in one generate call: tokens per second (left) and milliseconds per decoding step (right)
6With one adapter named, mixed mode gives 113 tokens per second, against 205 for the same adapter set with set_adapter and 416 merged. The step time then rises by about 67 ms for each additional adapter, and 16 adapters in a batch of 16 run at 14 tokens per second, 3% of the merged model. A loop over adapters inside every layer is the wrong shape for much traffic; it is correct, and it does not scale.
Servers built for this batch the adapter work in one kernel instead of one pass per adapter. Punica's kernel serves different LoRA models in a batch at 1,044 tokens per second on a 7B model on an A100 whatever the mix, where baselines fell to batch sizes of 1 to 3 when requests used different adapters. S-LoRA adds a unified memory pool for adapter weights and the attention cache, and a table of its published throughput follows.
A server built for many adapters holds 7.6 requests per second at 2,000 adapters; one merged copy per adapter runs out of memory by 100
Llama-7B on one A100 80 GB, published serving throughput in requests per second, by number of adapters (S-LoRA paper, table 3, first setting)
7At 5 adapters S-LoRA serves 8.05 requests per second against 2.04 for one merged copy per adapter and 0.88 for PEFT; at 100 adapters the merged copies no longer fit, and at 2,000 S-LoRA still serves 7.61. These are the paper's numbers on an A100 80 GB, not this lab's. AWS's SageMaker container for multi-adapter serving uses vLLM, which builds on S-LoRA and Punica. The vLLM flags for the shape, which the lab did not run because vLLM pins its own torch and transformers versions:
# Not run in the lab: vLLM pins its own torch and transformers versions.
vllm serve Qwen/Qwen2.5-1.5B-Instruct --enable-lora \
--lora-modules sql-wiki=/adapters/w sql-named=/adapters/n --max-lora-rank 16
# a request picks an adapter with "model": "sql-wiki"vLLM's documentation also describes loading adapters at run time through /v1/load_lora_adapter (with VLLM_ALLOW_RUNTIME_LORA_UPDATING) and warns that this has security risks and should be used in production only in an isolated, fully trusted environment. Adapter files are code-adjacent weights from a training job; load only those your own pipeline produced.
9. Faster decoding
A different speed-up leaves the weights alone. In speculative decoding a small draft model proposes several tokens and the main model checks them together, keeping those it would have produced itself, so the output is unchanged. NVIDIA's Nemotron 3.5 Parse reports a draft that proposes up to 32 tokens with about 14 accepted per step. On one H200 in BF16, over 2,078 pages, throughput was 7.62 times higher at concurrency 1 and 1.52 times higher at concurrency 512 (13.48 to 20.44 pages per second). The company's own figures show the pattern: the gain is large when the GPU is idle and small when batching already keeps it busy. This lab did not measure it.
Export and check quantisation drift
An export path starts with the merged FP16 checkpoint and produces GGUF variants such as Q4 and Q8. vLLM documents this as an experimental plugin path. Check that it supports the model and quantisation, and keep the tokenizer and prompt fixed. Save the FP16 scores as the reference so you can tell which answers changed after export. vLLM GGUF support
Version the adapter with its prompt template and tool schema, including function names and result formats. When the serving interface changes, replay the same cases against the new interface before promoting that pairing.
What to keep
| Situation | Serve as | The measurement behind it |
|---|---|---|
| One adapter, fp16 fits, latency matters | Merge in fp16 | 2.1× faster; 2 of 500 answers changed, no exact-match flip |
| A few adapters, each with its own traffic | One merged model per adapter | 3.09 GB each; 4 fit a T4 |
| Many tenants, uneven traffic | One base, adapters kept apart, routed by tenant | 32 adapters in 5.5 GB; 74 MB each |
| Many adapters in the same batch | A server with multi-adapter kernels (vLLM, LoRAX, S-LoRA) | PEFT's per-adapter loop: 67 ms per step for each extra adapter |
| 4-bit base | Adapter unmerged, or merge in fp16 and quantise once | 67.6% and 68.4% against 51.6% for merging into 4-bit |
| Swapping adapters at run time | Keep them apart; do not merge and unmerge | 1.04% of weights differ after one round trip |
If you have a task like this one:
- Merge in fp16 when one adapter serves the traffic and latency matters. It ran at 0.99 to 1.01 times the base model's speed (2.17 times faster than unmerged at batch 1 and 2.09 at batch 16), and changed 2 of 500 answers with no exact-match flip. Keep the unmerged adapter file to roll back.
- Keep adapters apart when there are many, when they change often or when memory is the limit. 32 adapters took 5.5 GB on one base against 98.9 GB for 32 merged copies (derived), at 74 MB each.
- Split adapters along a line the router can see, and route every request. Each adapter gained on its own kind (+9.2 and +32.4 points) and lost on the other (−8.4 and −7.2); routed, the system scored 67.8% over 500 against 47.0% for the base model.
- Never merge into a 4-bit base without re-running your evaluation. Merging into 4-bit scored 51.6%; keeping the adapter apart (67.6%) or merging in fp16 and quantising once (68.4%) stayed within noise of the fp16 reference (70.4%).
- Use a multi-adapter server when one batch mixes tenants. PEFT's loop over adapters is correct (0 of 500 answers differ from the single-adapter runs) but falls from 113 to 14 tokens per second as distinct adapters grow from 1 to 16.
- Compare scores on a held-out set, not strings, after any change of precision. Two answers of 500 changed on merging with no score moving, while the 4-bit variants that matched the reference's score still differed from it in about one answer in eight (29 and 31 of 250).
| Symptom | Cause | Fix |
|---|---|---|
| Merged answers differ slightly from the adapter's | fp16 rounds the update once instead of twice | Compare scores on a held-out set, not strings |
| Accuracy collapses after merging into a quantised model | The update is smaller than the gap between levels and is rounded away | Merge in fp16 and quantise once, or keep the adapter apart |
adapter_names is refused | The adapters are merged or the model is in training mode | Unmerge, and call eval() |
| Throughput falls as tenants are added to a batch | One pass per distinct adapter in each layer | Use a server with batched multi-adapter kernels |
| Outputs drift after swapping adapters by merge and unmerge | fp16 subtraction is not the inverse of the addition | Reload the base weights, or keep adapters apart |
Next to try, not tested here: fp16 adapters (autocast_adapter_dtype=False), to see how much of the unmerged slowdown is PEFT's float32 adapter and its casts.
Next to try, not tested here: a multi-adapter server (vLLM with --enable-lora) on the same two adapters, since the lab measured only PEFT's per-adapter loop and relied on published figures for S-LoRA and Punica.
Next to try, not tested here: counting how many 4-bit weights return to their original level after the merge in variant B, to test the explanation in section 6.
Next to try, not tested here: one adapter trained on both kinds against routing between two, on the same 500 questions.
How it was built
| Item | Setting |
|---|---|
| Base model | Qwen/Qwen2.5-1.5B-Instruct, fp16, 3.09 GB; a second copy in 4-bit NF4 with double quantisation and fp16 compute for section 6 |
| Data | sql-create-context at lesson 3's pinned commit, cleaned and split by table (train 69,170, validation 3,817, test 3,923); 2,400 training examples sampled at random per adapter from the train examples of its own kind (wiki-style for w, named-table for n), seed 42 |
| Test | 250 wiki-style + 250 named-table questions from the test split (3,656 and 267 available), seed 42, shuffled so every batch of 16 mixes both kinds (10 and 6 in the first); the 4-bit comparison uses the 250 wiki-style ones; exact match after normalising case, white space, a trailing semicolon and quote characters, plus whether the query runs in SQLite on the empty schema |
| Method | LoRA through TRL SFTTrainer, one per adapter: r=16, lora_alpha=32, lora_dropout=0.05, target_modules="all-linear" (196 adapted layers), 18,464,768 trainable weights |
| Training | 1 epoch, 150 optimizer steps, batch 8 × 2 accumulation = 16, learning rate 2e-4 with cosine decay and 3% warm-up, fp16, gradient checkpointing, max_length=256, loss on the answer only, seed 42, no validation pass |
| Decoding | Greedy, batches of 16, up to 128 new tokens, the zero-shot prompt; timing runs generate exactly 64 tokens, median of 5 after one warm-up |
| Hardware | One Tesla T4 (15.6 GB) on Google Colab; transformers 4.51.3, peft 0.15.2, trl 0.19.1, accelerate 1.6.0, datasets 3.6.0, bitsandbytes 0.50.2 |
Time and cost. Training took 4.2 minutes for w (1,128 padded tokens per second, 6.34 GB peak, loss 0.127 to 0.034) and 5.1 minutes for n (1,149 per second, 7.33 GB peak, loss 0.151 to 0.064); each adapter is 73.9 MB beside a 3.09 GB base. Scoring the 500 questions took 148 ms per answer for the base model, 202 ms for w unmerged, 272 ms for n unmerged and 103 ms for w merged; on the 250 wiki-style questions the 4-bit variants took 262 ms (A), 152 ms (B) and 135 ms (C). Merging into the 4-bit base took 2.6 s; merge_adapter and unmerge_adapter took 124 and 123 ms. The whole notebook takes about 45 minutes on a T4 by its own estimate. The 500-question scores in sections 2 to 5 and 8 come from the stratified set; the section 6 scores come from its 250 wiki-style questions, so they match the wiki column of Figure 2, not the 500-question totals; and none of them is comparable with lessons 4 and 5 except through the reweighting in the introduction.
Run it yourself
The notebook runs on a free Colab T4 and trains each adapter in about 4 to 5 minutes (4.2 for w, 5.1 for n); its own estimate for the whole run is about 45 minutes, most of it the 4-bit variants and the benchmarks. Its sections follow this page: 1 trains the adapters (How it was built), 2 is each adapter against the base, 3 the rounding, 4 the merged answers, 5 the speed (Figure 1), 6 the 4-bit base, 7 the adapter count and the weight drift, 8 mixed batches, and the closing summary is What to keep. Three changes to try:
- Load the adapter with
autocast_adapter_dtype=Falseso it stays in fp16. Does the unmerged speed move toward the merged model's, and does the rounding table change? - Put the router's rule in the training data: train one adapter on both kinds, 2,400 of each, and compare it with routing between two adapters on the same 500 questions.
- Measure how many entries of the 4-bit weights return to their original level after the merge in variant B. Does that match the share of the update lost?
Next to try
Predict which SQL queries are most sensitive to quantisation, then re-score the same held-out questions with merged FP16, GGUF Q8 and GGUF Q4 one at a time. Keep prompt and decoding fixed. Compare exact match and execution against FP16 and inspect the first query whose returned rows change.
Lesson 13 closes the course by releasing the adapter as a governed release: the decision, the gate, the rollback.
Sources
AWS Industries Blog, how BMW builds toward industry AI on SageMaker · AWS ML Blog, multi-tenant LoRA serving with SageMaker · Zhao et al., LoRA Land · Kasisto and Backbase, FinRAG-12B · Dialpad, call-summary models · Hu et al., LoRA · Sheng et al., S-LoRA · Chen et al., Punica · Xu et al., QA-LoRA · NVIDIA, Nemotron 3.5 Parse · vLLM, LoRA adapters
How is this page?
Last updated on