| 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 | from typing import Optional |
| 8 | |
| 9 | from llama_models.datatypes import * # noqa: F403 |
| 10 | from llama_models.sku_list import all_registered_models, resolve_model |
| 11 | |
| 12 | from llama_stack.apis.inference import * # noqa: F401, F403 |
| 13 | |
| 14 | from pydantic import BaseModel, Field, field_validator |
| 15 | |
| 16 | |
| 17 | class MetaReferenceImplConfig(BaseModel): |
| 18 | model: str = Field( |
| 19 | default="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 in {ModelFamily.llama3_1, ModelFamily.llama3_2} |
| 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 | # 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 | resolved = resolve_model(self.model) |
| 49 | assert resolved is not None |
| 50 | return resolved.pth_file_count |