|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
| 3 | +import argparse |
3 | 4 | import os
|
4 |
| -import signal |
5 | 5 | import subprocess
|
6 | 6 | import sys
|
7 | 7 |
|
|
21 | 21 | "temp", "tfs", "top-k", "top-p", "typical", "verbose-prompt"
|
22 | 22 | ]
|
23 | 23 |
|
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)) |
26 | 58 |
|
27 | 59 | props = {prop.replace("_", "-"): val for prop, val in props.items()}
|
28 | 60 |
|
|
61 | 93 | if value != "True":
|
62 | 94 | command_list.append(str(value))
|
63 | 95 |
|
64 |
| -print(command_list) |
| 96 | +command_list += unknown_args |
65 | 97 |
|
66 | 98 | sp = subprocess.Popen(command_list)
|
67 | 99 |
|
|
0 commit comments