mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 02:53:30 +00:00
feat: add a option to list the downloaded models (#1127)
# What does this PR do? [Provide a short summary of what this PR does and why. Link to relevant issues if applicable.] ``` $ llama model list --help usage: llama model list [-h] [--show-all] [--downloaded] Show available llama models options: -h, --help show this help message and exit --show-all Show all models (not just defaults) --downloaded List the downloaded models $ llama model list --downloaded +-------------+----------+---------------------+ | Model | Size | Modified Time | +-------------+----------+---------------------+ | Llama3.2-1B | 2.31 GB | 2025-02-16 13:38:04 | +-------------+----------+---------------------+ | Llama3.1-8B | 14.97 GB | 2025-02-16 10:36:37 | +-------------+----------+---------------------+ ``` [//]: # (If resolving an issue, uncomment and update the line below) [//]: # (Closes #[issue-number]) ## Test Plan [Describe the tests you ran to verify your changes with result summaries. *Provide clear instructions so the plan can be easily re-executed.*] [//]: # (## Documentation) --------- Signed-off-by: reidliu <reid201711@gmail.com> Co-authored-by: reidliu <reid201711@gmail.com>
This commit is contained in:
parent
7504cb16c6
commit
af377e844d
1 changed files with 40 additions and 0 deletions
|
@ -5,12 +5,44 @@
|
||||||
# the root directory of this source tree.
|
# the root directory of this source tree.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from llama_stack.cli.subcommand import Subcommand
|
from llama_stack.cli.subcommand import Subcommand
|
||||||
from llama_stack.cli.table import print_table
|
from llama_stack.cli.table import print_table
|
||||||
|
from llama_stack.distribution.utils.config_dirs import DEFAULT_CHECKPOINT_DIR
|
||||||
from llama_stack.models.llama.sku_list import all_registered_models
|
from llama_stack.models.llama.sku_list import all_registered_models
|
||||||
|
|
||||||
|
|
||||||
|
def _get_model_size(model_dir):
|
||||||
|
return sum(f.stat().st_size for f in Path(model_dir).rglob("*") if f.is_file())
|
||||||
|
|
||||||
|
|
||||||
|
def _run_model_list_downloaded_cmd() -> None:
|
||||||
|
headers = ["Model", "Size", "Modified Time"]
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
for model in os.listdir(DEFAULT_CHECKPOINT_DIR):
|
||||||
|
abs_path = os.path.join(DEFAULT_CHECKPOINT_DIR, model)
|
||||||
|
space_usage = _get_model_size(abs_path)
|
||||||
|
model_size = f"{space_usage / (1024**3):.2f} GB"
|
||||||
|
modified_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(os.path.getmtime(abs_path)))
|
||||||
|
rows.append(
|
||||||
|
[
|
||||||
|
model,
|
||||||
|
model_size,
|
||||||
|
modified_time,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
print_table(
|
||||||
|
rows,
|
||||||
|
headers,
|
||||||
|
separate_rows=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ModelList(Subcommand):
|
class ModelList(Subcommand):
|
||||||
"""List available llama models"""
|
"""List available llama models"""
|
||||||
|
|
||||||
|
@ -31,10 +63,18 @@ class ModelList(Subcommand):
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Show all models (not just defaults)",
|
help="Show all models (not just defaults)",
|
||||||
)
|
)
|
||||||
|
self.parser.add_argument(
|
||||||
|
"--downloaded",
|
||||||
|
action="store_true",
|
||||||
|
help="List the downloaded models",
|
||||||
|
)
|
||||||
|
|
||||||
def _run_model_list_cmd(self, args: argparse.Namespace) -> None:
|
def _run_model_list_cmd(self, args: argparse.Namespace) -> None:
|
||||||
from .safety_models import prompt_guard_model_sku
|
from .safety_models import prompt_guard_model_sku
|
||||||
|
|
||||||
|
if args.downloaded:
|
||||||
|
return _run_model_list_downloaded_cmd()
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
"Model Descriptor(ID)",
|
"Model Descriptor(ID)",
|
||||||
"Hugging Face Repo",
|
"Hugging Face Repo",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue