Elffuss BraidHub

kikocis/llama-stack public

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