Merging and Exporting
An adapter is a convenient thing to keep — small, swappable, and honest about what it changed. But some tools want a whole model, not a model plus an adapter, and some deployments want the adapter's effect baked in. This chapter covers the two ways out, and is documented-only: the lab trained and compared through the adapter directly and did not run an export, so what follows is the shape of the work, from the libraries' documentation, with the unverified steps labelled.
Merging: folding the adapter in
Merging adds the adapter's learned change into the base model's weights, producing one ordinary model that behaves as base-plus-adapter did. In the PEFT library it is a few lines:
model = PeftModel.from_pretrained(base, "adapter")
model = model.merge_and_unload()
model.save_pretrained("merged-model")
Two honest costs. The merged model is the size of the base model — you have traded the adapter's smallness for a self-contained file. And merging is a one-way door for that copy: the adapter can no longer be dialled down or swapped, because it no longer exists separately. Keep the adapter even if you merge; it is the source.
Exporting to GGUF
The local-model ecosystem — llama.cpp, Ollama, and friends (both have guides in this series) — mostly runs GGUF files: a whole model in one file, usually quantised, its numbers stored at reduced precision so it fits and runs fast on ordinary hardware. The usual route from a merged model to a runnable GGUF is:
- Save the merged model in its ordinary (safetensors) form.
- Convert it with llama.cpp's
convert_hf_to_gguf.pyscript, which writes an unquantised or half-precision GGUF. - Quantise that file with llama.cpp's
llama-quantizeto the size/quality point you want (Q4_K_M is the common compromise). - Load it in your runner and repeat chapter 8's held-out questions against it — quantisation is a change to the model, and a change earns a re-test.
Tools also exist that convert a LoRA adapter itself to GGUF form, to be applied over a GGUF base at load time. The ecosystem moves quickly; check the llama.cpp documentation for the current state rather than trusting this paragraph for long.
None of these steps was run in this
guide's lab: the sandbox had no need
of a GGUF artefact, and the chapter
you are reading is a map, not a
transcript. criteria.md lists it as
documented-only, in those words.