From 187524d4aeb7477297e580d2bbace7481109ca75 Mon Sep 17 00:00:00 2001 From: Reid <61492567+reidliu41@users.noreply.github.com> Date: Sat, 22 Feb 2025 08:38:10 +0800 Subject: [PATCH] feat: add substring search for model list (#1099) # 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` or `llama model list --show-all` will list more or all for the models, so add the `search` option to simplify the output. ``` $ llama model list --help usage: llama model list [-h] [--show-all] [-s SEARCH] Show available llama models options: -h, --help show this help message and exit --show-all Show all models (not just defaults) -s SEARCH, --search SEARCH Search for the input string as a substring in the model descriptor(ID) $ llama model list -s 70b +-----------------------+-----------------------------------+----------------+ | Model Descriptor(ID) | Hugging Face Repo | Context Length | +-----------------------+-----------------------------------+----------------+ | Llama3.1-70B | meta-llama/Llama-3.1-70B | 128K | +-----------------------+-----------------------------------+----------------+ | Llama3.1-70B-Instruct | meta-llama/Llama-3.1-70B-Instruct | 128K | +-----------------------+-----------------------------------+----------------+ | Llama3.3-70B-Instruct | meta-llama/Llama-3.3-70B-Instruct | 128K | +-----------------------+-----------------------------------+----------------+ $ llama model list -s 3.1-8b +----------------------+----------------------------------+----------------+ | Model Descriptor(ID) | Hugging Face Repo | Context Length | +----------------------+----------------------------------+----------------+ | Llama3.1-8B | meta-llama/Llama-3.1-8B | 128K | +----------------------+----------------------------------+----------------+ | Llama3.1-8B-Instruct | meta-llama/Llama-3.1-8B-Instruct | 128K | +----------------------+----------------------------------+----------------+ $ llama model list --show-all -s pro +----------------------+-----------------------------+----------------+ | Model Descriptor(ID) | Hugging Face Repo | Context Length | +----------------------+-----------------------------+----------------+ | Prompt-Guard-86M | meta-llama/Prompt-Guard-86M | 2K | +----------------------+-----------------------------+----------------+ $ llama model list -s k Not found for search. ``` [//]: # (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 Co-authored-by: reidliu --- llama_stack/cli/model/list.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/llama_stack/cli/model/list.py b/llama_stack/cli/model/list.py index 622a6b4e7..b9499f06d 100644 --- a/llama_stack/cli/model/list.py +++ b/llama_stack/cli/model/list.py @@ -75,6 +75,13 @@ class ModelList(Subcommand): action="store_true", help="List the downloaded models", ) + self.parser.add_argument( + "-s", + "--search", + type=str, + required=False, + help="Search for the input string as a substring in the model descriptor(ID)", + ) def _run_model_list_cmd(self, args: argparse.Namespace) -> None: from .safety_models import prompt_guard_model_sku @@ -94,15 +101,19 @@ class ModelList(Subcommand): continue descriptor = model.descriptor() - rows.append( - [ - descriptor, - model.huggingface_repo, - f"{model.max_seq_length // 1024}K", - ] + if not args.search or args.search.lower() in descriptor.lower(): + rows.append( + [ + descriptor, + model.huggingface_repo, + f"{model.max_seq_length // 1024}K", + ] + ) + if len(rows) == 0: + print(f"Did not find any model matching `{args.search}`.") + else: + print_table( + rows, + headers, + separate_rows=True, ) - print_table( - rows, - headers, - separate_rows=True, - )