Skip to content

Commit 487f622

Browse files
better run_with_preset.py CLI
1 parent 93f7d5d commit 487f622

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

run_with_preset.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

3+
import argparse
34
import os
4-
import signal
55
import subprocess
66
import sys
77

@@ -21,8 +21,40 @@
2121
"temp", "tfs", "top-k", "top-p", "typical", "verbose-prompt"
2222
]
2323

24-
with open(sys.argv[1], "r") as f:
25-
props = yaml.load(f, yaml.SafeLoader)
24+
description = """Run llama.cpp binaries with presets from YAML file(s).
25+
To specify which binary should be run, specify the "binary" property.
26+
To get a preset file template, run a llama.cpp binary with the "--logdir" CLI argument.
27+
28+
Formatting considerations:
29+
- The YAML property names are the same as the CLI argument names of the corresponding binary.
30+
- Properties must use the long name of their corresponding llama.cpp CLI arguments.
31+
- Like the llama.cpp binaries the property names do not differentiate between hyphens and underscores.
32+
- Flags must be defined as "<PROPERTY_NAME>: true" to be effective.
33+
- To define the logit_bias property, the expected format is "<TOKEN_ID>: <BIAS>" in the "logit_bias" namespace.
34+
- To define multiple "reverse_prompt" properties simultaneously the expected format is a list of strings.
35+
- To define a tensor split, pass a list of floats.
36+
"""
37+
usage = "run_with_preset.py [-h] [yaml_files ...] [--<ARG_NAME> <ARG_VALUE> ...]"
38+
epilog = (" --<ARG_NAME> specify additional CLI ars to be passed to the binary (override all preset files). "
39+
"Unknown args will be ignored.")
40+
41+
parser = argparse.ArgumentParser(
42+
description=description, usage=usage, epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
43+
parser.add_argument("yaml_files", nargs="*",
44+
help="Arbitrary number of YAML files from which to read preset values. "
45+
"If two files specify the same values the later one will be used.")
46+
47+
known_args, unknown_args = parser.parse_known_args()
48+
49+
if not known_args.yaml_files and not unknown_args:
50+
parser.print_help()
51+
sys.exit(0)
52+
53+
props = dict()
54+
55+
for yaml_file in known_args.yaml_files:
56+
with open(yaml_file, "r") as f:
57+
props.update(yaml.load(f, yaml.SafeLoader))
2658

2759
props = {prop.replace("_", "-"): val for prop, val in props.items()}
2860

@@ -61,7 +93,7 @@
6193
if value != "True":
6294
command_list.append(str(value))
6395

64-
print(command_list)
96+
command_list += unknown_args
6597

6698
sp = subprocess.Popen(command_list)
6799

0 commit comments

Comments
 (0)