Elffuss BraidHub

kikocis/llama-stack public

7bf84b9a642d · 1.8 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
7from typing import Optional
8
9from llama_models.datatypes import ModelFamily
10
11from llama_models.schema_utils import json_schema_type
12from llama_models.sku_list import all_registered_models, resolve_model
13
14from llama_stack.apis.inference import QuantizationConfig
15
16from pydantic import BaseModel, Field, field_validator
17
18
19@json_schema_type
20class MetaReferenceImplConfig(BaseModel):
21 model: str = Field(
22 default="Meta-Llama3.1-8B-Instruct",
23 description="Model descriptor from `llama model list`",
24 )
25 quantization: Optional[QuantizationConfig] = None
26 torch_seed: Optional[int] = None
27 max_seq_len: int
28 max_batch_size: int = 1
29
30 @field_validator("model")
31 @classmethod
32 def validate_model(cls, model: str) -> str:
33 permitted_models = [
34 m.descriptor()
35 for m in all_registered_models()
36 if m.model_family == ModelFamily.llama3_1
37 ]
38 if model not in permitted_models:
39 model_list = "\n\t".join(permitted_models)
40 raise ValueError(
41 f"Unknown model: `{model}`. Choose from [\n\t{model_list}\n]"
42 )
43 return model
44
45 @property
46 def model_parallel_size(self) -> int:
47 # HUGE HACK ALERT: this will be fixed when we move inference configuration
48 # to ModelsRegistry and we can explicitly ask for `model_parallel_size`
49 # as configuration there
50 gpu_count = 1
51 resolved = resolve_model(self.model)
52 assert resolved is not None
53 descriptor = resolved.descriptor().lower()
54 if "-70b" in descriptor or "-405b" in descriptor:
55 gpu_count = 8
56
57 return gpu_count