Skip to content

Commit 0e0b8c5

Browse files
authored
feat(cli): add llama-models CLI for standalone model management (#403)
This adds a complete command-line interface for managing Llama models independently of llama-stack. Users can now install llama-models and use the 'llama-model' command to list, download, describe, and verify models from both Meta and HuggingFace. The CLI provides model discovery (list/describe), downloading from Meta's signed URLs or HuggingFace repos, checksum verification for Meta downloads, and local model management (list downloaded, remove). All model SKU definitions and download logic are now self-contained in this package. This separation allows partners and users to manage models without requiring the full llama-stack installation, improving modularity and reducing dependency bloat. Test Plan: - Verified `llama-model --help` shows all subcommands - Tested `llama-model model list` displays model table - Tested `llama-model model describe -m Llama3.2-1B` shows model details - Confirmed all imports resolve correctly - Pre-commit hooks pass (license headers, ruff, formatting)
1 parent a9c89c4 commit 0e0b8c5

19 files changed

Lines changed: 2562 additions & 4 deletions

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,31 @@ To download the model weights and tokenizer:
3939
1. Visit the [Meta Llama website](https://llama.meta.com/llama-downloads/).
4040
2. Read and accept the license.
4141
3. Once your request is approved you will receive a signed URL via email.
42-
4. Install the [Llama CLI](https://github.com/meta-llama/llama-stack): `pip install llama-stack`. (**<-- Start Here if you have received an email already.**)
43-
5. Run `llama model list` to show the latest available models and determine the model ID you wish to download. **NOTE**:
44-
If you want older versions of models, run `llama model list --show-all` to show all the available Llama models.
42+
4. Install the Llama Models CLI: `pip install llama-models`. (**<-- Start Here if you have received an email already.**)
43+
5. Run `llama-model list` to show the latest available models and determine the model ID you wish to download. **NOTE**:
44+
If you want older versions of models, run `llama-model list --show-all` to show all the available Llama models.
4545

46-
6. Run: `llama download --source meta --model-id CHOSEN_MODEL_ID`
46+
6. Run: `llama-model download --source meta --model-id CHOSEN_MODEL_ID`
4747
7. Pass the URL provided when prompted to start the download.
4848

4949
Remember that the links expire after 24 hours and a certain amount of downloads. You can always re-request a link if you start seeing errors such as `403: Forbidden`.
5050

51+
### CLI Commands Reference
52+
53+
Once installed, the `llama-model` CLI provides the following commands:
54+
55+
```bash
56+
llama-model list # List available models
57+
llama-model list --show-all # List all models (including older versions)
58+
llama-model describe -m MODEL_ID # Show detailed information about a model
59+
llama-model download # Download models from Meta or Hugging Face
60+
llama-model verify-download # Verify integrity of downloaded models
61+
llama-model remove -m MODEL_ID # Remove a downloaded model
62+
llama-model prompt-format -m MODEL_ID # Show the prompt format for a model
63+
```
64+
65+
For detailed help on any command, run `llama-model COMMAND --help`.
66+
5167
## Running the models
5268

5369
In order to run the models, you will need to install dependencies after checking out the repository.

models/cli/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the terms described in the LICENSE file in
5+
# top-level folder for each specific model found within the models/ directory at
6+
# the top-level of this source tree.

models/cli/describe.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the terms described in the LICENSE file in
5+
# top-level folder for each specific model found within the models/ directory at
6+
# the top-level of this source tree.
7+
8+
import argparse
9+
import json
10+
11+
from llama_models.cli.subcommand import Subcommand
12+
from llama_models.cli.table import print_table
13+
from llama_models.sku_list import resolve_model
14+
15+
16+
class Describe(Subcommand):
17+
"""Show details about a model"""
18+
19+
def __init__(self, subparsers: argparse._SubParsersAction):
20+
super().__init__()
21+
self.parser = subparsers.add_parser(
22+
"describe",
23+
prog="llama-model describe",
24+
description="Show details about a llama model",
25+
formatter_class=argparse.RawTextHelpFormatter,
26+
)
27+
self._add_arguments()
28+
self.parser.set_defaults(func=self._run_model_describe_cmd)
29+
30+
def _add_arguments(self):
31+
self.parser.add_argument(
32+
"-m",
33+
"--model-id",
34+
type=str,
35+
required=True,
36+
help="See `llama-model list` or `llama-model list --show-all` for the list of available models",
37+
)
38+
39+
def _run_model_describe_cmd(self, args: argparse.Namespace) -> None:
40+
from llama_models.cli.safety_models import prompt_guard_model_sku_map
41+
42+
prompt_guard_model_map = prompt_guard_model_sku_map()
43+
if args.model_id in prompt_guard_model_map.keys():
44+
model = prompt_guard_model_map[args.model_id]
45+
else:
46+
model = resolve_model(args.model_id)
47+
48+
if model is None:
49+
self.parser.error(
50+
f"Model {args.model_id} not found; try 'llama-model list' for a list of available models."
51+
)
52+
return
53+
54+
headers = [
55+
"Model",
56+
model.descriptor(),
57+
]
58+
59+
rows = [
60+
("Hugging Face ID", model.huggingface_repo or "<Not Available>"),
61+
("Description", model.description),
62+
("Context Length", f"{model.max_seq_length // 1024}K tokens"),
63+
("Weights format", model.quantization_format.value),
64+
("Model params.json", json.dumps(model.arch_args, indent=4)),
65+
]
66+
67+
print_table(
68+
rows,
69+
headers,
70+
separate_rows=True,
71+
)

0 commit comments

Comments
 (0)