| 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 | # the root directory of this source tree. |
| 6 | |
| 7 | import argparse |
| 8 | |
| 9 | from llama_models.sku_list import all_registered_models |
| 10 | |
| 11 | from llama_stack.cli.subcommand import Subcommand |
| 12 | from llama_stack.cli.table import print_table |
| 13 | |
| 14 | |
| 15 | class ModelList(Subcommand): |
| 16 | """List available llama models""" |
| 17 | |
| 18 | def __init__(self, subparsers: argparse._SubParsersAction): |
| 19 | super().__init__() |
| 20 | self.parser = subparsers.add_parser( |
| 21 | "list", |
| 22 | prog="llama model list", |
| 23 | description="Show available llama models", |
| 24 | formatter_class=argparse.RawTextHelpFormatter, |
| 25 | ) |
| 26 | self._add_arguments() |
| 27 | self.parser.set_defaults(func=self._run_model_list_cmd) |
| 28 | |
| 29 | def _add_arguments(self): |
| 30 | self.parser.add_argument( |
| 31 | "--show-all", |
| 32 | action="store_true", |
| 33 | help="Show all models (not just defaults)", |
| 34 | ) |
| 35 | |
| 36 | def _run_model_list_cmd(self, args: argparse.Namespace) -> None: |
| 37 | headers = [ |
| 38 | "Model Descriptor", |
| 39 | "Hugging Face Repo", |
| 40 | "Context Length", |
| 41 | ] |
| 42 | |
| 43 | rows = [] |
| 44 | for model in all_registered_models(): |
| 45 | if not args.show_all and not model.is_featured: |
| 46 | continue |
| 47 | |
| 48 | descriptor = model.descriptor() |
| 49 | rows.append( |
| 50 | [ |
| 51 | descriptor, |
| 52 | model.huggingface_repo, |
| 53 | f"{model.max_seq_length // 1024}K", |
| 54 | ] |
| 55 | ) |
| 56 | print_table( |
| 57 | rows, |
| 58 | headers, |
| 59 | separate_rows=True, |
| 60 | ) |