Python · 1245 bytes Raw Blame History
1 """Convert a PEFT adapter checkpoint to `adapter.gguf`.
2
3 llama.cpp's `convert_lora_to_gguf.py` takes the adapter directory as
4 a **positional** argument and reads `adapter_config.json` to discover
5 the base model. Earlier drafts (pre-audit F09) invented a `--base`
6 flag; the upstream CLI does not have one. This module assembles the
7 exact upstream signature so a snapshot test against `--help` catches
8 drift.
9 """
10
11 from __future__ import annotations
12
13 import sys
14 from pathlib import Path
15
16 from dlm.export import vendoring
17
18
19 def build_convert_lora_args(
20 adapter_dir: Path,
21 *,
22 out_gguf: Path,
23 outtype: str = "f16",
24 script_override: Path | None = None,
25 python_exe: str | None = None,
26 ) -> list[str]:
27 """Assemble the `python convert_lora_to_gguf.py <adapter> ...` argv.
28
29 Audit F09: the signature must match the pinned upstream CLI. A
30 snapshot test under `tests/unit/export/test_subprocess_args.py`
31 diffs this against the expected form and fails on drift.
32 """
33 script = vendoring.convert_lora_to_gguf_py(script_override)
34 return [
35 python_exe or sys.executable,
36 str(script),
37 str(adapter_dir),
38 "--outfile",
39 str(out_gguf),
40 "--outtype",
41 outtype,
42 ]