|
24 | 24 | ).expanduser() |
25 | 25 |
|
26 | 26 |
|
27 | | -KNOWN_VERBS = ["chat", "browser", "download", "generate", "eval", "export", "list", "remove", "where"] |
| 27 | +# Subcommands related to downloading and managing model artifacts |
| 28 | +INVENTORY_VERBS = ["download", "list", "remove", "where"] |
| 29 | + |
| 30 | +# List of all supported subcommands in torchchat |
| 31 | +KNOWN_VERBS = ["chat", "browser", "generate", "eval", "export"] + INVENTORY_VERBS |
28 | 32 |
|
29 | 33 | # Handle CLI arguments that are common to a majority of subcommands. |
30 | 34 | def check_args(args, verb: str) -> None: |
31 | 35 | # Handle model download. Skip this for download, since it has slightly |
32 | 36 | # different semantics. |
33 | 37 | if ( |
34 | | - verb not in ["download", "list", "remove"] |
| 38 | + verb not in INVENTORY_VERBS |
35 | 39 | and args.model |
36 | 40 | and not is_model_downloaded(args.model, args.model_directory) |
37 | 41 | ): |
38 | 42 | download_and_convert(args.model, args.model_directory, args.hf_token) |
39 | 43 |
|
40 | 44 |
|
41 | | -def add_arguments_for_verb(parser, verb: str): |
| 45 | +def add_arguments_for_verb(parser, verb: str) -> None: |
42 | 46 | # Model specification. TODO Simplify this. |
43 | 47 | # A model can be specified using a positional model name or HuggingFace |
44 | 48 | # path. Alternatively, the model can be specified via --gguf-path or via |
45 | 49 | # an explicit --checkpoint-dir, --checkpoint-path, or --tokenizer-path. |
| 50 | + |
| 51 | + if verb in INVENTORY_VERBS: |
| 52 | + _configure_artifact_inventory_args(parser, verb) |
| 53 | + _add_cli_metadata_args(parser) |
| 54 | + return |
| 55 | + |
46 | 56 | parser.add_argument( |
47 | 57 | "model", |
48 | 58 | type=str, |
@@ -197,12 +207,6 @@ def add_arguments_for_verb(parser, verb: str): |
197 | 207 | choices=allowable_dtype_names(), |
198 | 208 | help="Override the dtype of the model (default is the checkpoint dtype). Options: bf16, fp16, fp32, fast16, fast", |
199 | 209 | ) |
200 | | - parser.add_argument( |
201 | | - "-v", |
202 | | - "--verbose", |
203 | | - action="store_true", |
204 | | - help="Verbose output", |
205 | | - ) |
206 | 210 | parser.add_argument( |
207 | 211 | "--quantize", |
208 | 212 | type=str, |
@@ -258,6 +262,46 @@ def add_arguments_for_verb(parser, verb: str): |
258 | 262 | default=5000, |
259 | 263 | help="Port for the web server in browser mode", |
260 | 264 | ) |
| 265 | + _add_cli_metadata_args(parser) |
| 266 | + |
| 267 | + |
| 268 | +# Add CLI Args that are relevant to any subcommand execution |
| 269 | +def _add_cli_metadata_args(parser) -> None: |
| 270 | + parser.add_argument( |
| 271 | + "-v", |
| 272 | + "--verbose", |
| 273 | + action="store_true", |
| 274 | + help="Verbose output", |
| 275 | + ) |
| 276 | + |
| 277 | + |
| 278 | +# Configure CLI Args specific to Model Artifact Management |
| 279 | +def _configure_artifact_inventory_args(parser, verb: str) -> None: |
| 280 | + if verb in ["download", "remove", "where"]: |
| 281 | + parser.add_argument( |
| 282 | + "model", |
| 283 | + type=str, |
| 284 | + nargs="?", |
| 285 | + default=None, |
| 286 | + help="Model name for well-known models", |
| 287 | + ) |
| 288 | + |
| 289 | + if verb in INVENTORY_VERBS: |
| 290 | + parser.add_argument( |
| 291 | + "--model-directory", |
| 292 | + type=Path, |
| 293 | + default=default_model_dir, |
| 294 | + help=f"The directory to store downloaded model artifacts. Default: {default_model_dir}", |
| 295 | + ) |
| 296 | + |
| 297 | + if verb == "download": |
| 298 | + parser.add_argument( |
| 299 | + "--hf-token", |
| 300 | + type=str, |
| 301 | + default=None, |
| 302 | + help="A HuggingFace API token to use when downloading model artifacts", |
| 303 | + ) |
| 304 | + |
261 | 305 |
|
262 | 306 | # Add CLI Args specific to Model Evaluation |
263 | 307 | def _add_evaluation_args(parser) -> None: |
|
0 commit comments