The prepared model in a complete system
The trained model returns to a larger system. Merging and quantization each create a validation boundary. Deploy the complete input, execution, state, and evaluation contract rather than checking only the model file.
#Section 67Base model + adapter inference
Training saved a small adapter, and inference still needs the model it corrects. An adapter file alone is not a language model.
Loading base weights and loading LoRA
Base-plus-adapter inference loads the exact frozen checkpoint and applies the trained factors at the selected projections. Verify base revision, tokenizer, chat template, target modules, rank, alpha, scaling convention, and dtype, and set evaluation mode so dropout does not change the result.
Runtime adapter application
Runtime adapter application computes Wx + sB(Ax) in every targeted projection. A Finch query adapter has intermediate width 8 between base widths of 512; the tensors are small, but the full model still runs.
Switching the active adapter invalidates dependent KV-cache states: identical tokens produced different keys and values under different effective weights. Rebuild the affected cache rather than comparing message text.
#Section 68Adapter merge
A runtime that cannot apply adapter branches needs a standalone artifact. Merging gives it ordinary weight tensors, which must contain exactly the trained correction.
Merge into base weights and save merged model
Build W_merged = W + (alpha/r)BA for each target under the stored convention. Save the merged model with configuration, tokenizer, template, and provenance, and record that the adapter is already included so nobody applies it again.
Verify parity
Parity is agreement under a stated test and tolerance. Compare merged and unmerged functions before trusting the artifact.
Test both the in-memory merge and the saved-and-reloaded artifact; serialization can change dtype, drop a tensor, or mishandle tied weights. A successful merge call proves neither the artifact nor the serving path.
Build the correction in higher precision when possible, then cast for the target runtime. Keep the unmerged sources so a failed comparison can be traced to the merge rather than an unknown base.
#Section 69Post-merge validation
The merged model answers an easy prompt the same way. That proves little, since many wrong models share a common first word. Look below the sampled text and at complete tasks.
Logits and generation
Post-merge validation starts by comparing logits for identical tokenized inputs under deterministic settings. Logits are the unnormalized vocabulary scores before the probability transform. Report a statistic such as maximum absolute difference, on inputs that include tool boundaries and long prefixes.
Generation tests compare serving behavior. Greedy output can flip on a tiny logit change near a tie, so exact text equality is sometimes stronger and sometimes weaker than a numerical tolerance, and sampled runs also depend on RNG and earlier choices.
Tool evaluation
Rerun the fixed tool benchmark on the reloaded merged model: calls, arguments, recovery, final state, regressions. Near-matching logits on a few prompts do not prove task parity, and unchanged success does not prove numerical equivalence.
Compare logits at matching positions under identical rendered inputs.
#Section 70Quantizing the fine-tuned model
The merged weights take two bytes each in 16-bit storage. Integers can shrink that, but they approximate the values and may change tool behavior.
Merge then quantize and INT8 conversion
Quantization represents values on a discrete grid with scale metadata; INT8 stores eight-bit integers. A simple deployment merges the correction in floating point and then quantizes the effective weights with the runtime’s supported method. Quantized-base adapters and QLoRA-style training are separate routes.
Memory changes and quality regression
Quantization adds scales, packing, and buffers. Real memory savings differ from the ideal integer-weight ratio.
Re-evaluate task success and regressions after quantizing, since a small numerical shift can change a tool name, a quantity token, or a stop decision. When the quantizer calibrates, calibration data should match the workload. QLoRA trains adapters over a frozen quantized base, a different route from post-merge INT8 conversion.
#Section 71Final agent evaluation
The quantized model is smaller on disk, but the agent may still be slower if tools dominate latency or the integer path is poorly supported. Evaluate the deployed combination, not the tensor conversion.
Accuracy, speed, memory, and tool reliability
A final agent evaluation reruns the benchmark on the real serving configuration. Accuracy covers task correctness and the call diagnostics. Speed covers prefill, decode, tool time, and end-to-end latency with named boundaries. Memory covers resident weights, KV cache, and peak allocation.
Tool reliability covers dispatch, timeout semantics, retry deduplication, and result formatting on the real service. An adapter can improve call choice while an outage lowers completion; report both so model quality is not confused with service availability.
The KV cache has its own dtype and grows with history. Quantizing weights does not quantize the cache.
Evaluate the original, unmerged adapted, reloaded merged, and quantized systems on the same tasks to see where each gain or regression entered. Save the report with artifact hashes and runtime configuration so the claim points to a reproducible object.
#Section 72End-to-end agent architecture
Back to the request: reserve 3 bolts if enough are available, then report what remains. Every component below must work for “3 reserved; 9 remain” to be justified.
Model, tokenizer, and chat template
The tokenizer maps rendered text and control tokens to vocabulary IDs. The chat template renders current tools and role-correct history. The model maps that causal sequence to candidate assistant outputs, using base, adapter, merged, or quantized weights.
Harness, tools, state, and evaluation
The runtime parses complete calls, validates arguments and authorization, dispatches trusted tools, keeps state, and enforces budgets. Tools read or change the environment and return evidence. Evaluation watches each boundary and checks that the final inventory and answer satisfy the request.
| Component | One job | Failure if missing |
|---|---|---|
| Tokenizer | Encode the intended vocabulary IDs | Different input sequence |
| Chat template | Preserve roles and call boundaries | Wrong learned continuation |
| Model and adapter | Propose the next assistant decision | Wrong choice or value |
| Runtime parser and checks | Convert a permitted complete call to an action | Ambiguous or unauthorized execution |
| Tool service | Enforce the operation atomically | Incorrect external state |
| State record | Retain evidence and identities | Lost dependencies or duplicate effects |
| Evaluation | Compare the outcome with the goal | Unsupported improvement claims |
This chapter covered supervised specialization and a bounded tool loop, not preference optimization, reinforcement learning, distributed training, or open-ended planning. The next chapter studies architectural changes and the experiments that decide whether they improve a decoder.