Elffuss BraidHub

kikocis/llama-stack public

bb9be718c121 · 2.4 KiBRawPermalink
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
7import argparse
8import json
9
10from llama_models.sku_list import resolve_model
11
12from llama_stack.cli.subcommand import Subcommand
13from llama_stack.cli.table import print_table
14from llama_stack.distribution.utils.serialize import EnumEncoder
15
16from termcolor import colored
17
18
19class ModelDescribe(Subcommand):
20 """Show details about a model"""
21
22 def __init__(self, subparsers: argparse._SubParsersAction):
23 super().__init__()
24 self.parser = subparsers.add_parser(
25 "describe",
26 prog="llama model describe",
27 description="Show details about a llama model",
28 formatter_class=argparse.RawTextHelpFormatter,
29 )
30 self._add_arguments()
31 self.parser.set_defaults(func=self._run_model_describe_cmd)
32
33 def _add_arguments(self):
34 self.parser.add_argument(
35 "-m",
36 "--model-id",
37 type=str,
38 required=True,
39 )
40
41 def _run_model_describe_cmd(self, args: argparse.Namespace) -> None:
42 model = resolve_model(args.model_id)
43 if model is None:
44 self.parser.error(
45 f"Model {args.model_id} not found; try 'llama model list' for a list of available models."
46 )
47 return
48
49 rows = [
50 (
51 colored("Model", "white", attrs=["bold"]),
52 colored(model.descriptor(), "white", attrs=["bold"]),
53 ),
54 ("Hugging Face ID", model.huggingface_repo or "<Not Available>"),
55 ("Description", model.description),
56 ("Context Length", f"{model.max_seq_length // 1024}K tokens"),
57 ("Weights format", model.quantization_format.value),
58 ("Model params.json", json.dumps(model.arch_args, indent=4)),
59 ]
60
61 if model.recommended_sampling_params is not None:
62 sampling_params = model.recommended_sampling_params.dict()
63 for k in ("max_tokens", "repetition_penalty"):
64 del sampling_params[k]
65 rows.append(
66 (
67 "Recommended sampling params",
68 json.dumps(sampling_params, cls=EnumEncoder, indent=4),
69 )
70 )
71
72 print_table(
73 rows,
74 separate_rows=True,
75 )