File size: 1,243 Bytes
7825400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Runtime configuration schemas for model adapters."""

from typing import Any
from pydantic import BaseModel, Field


class GenerationConfig(BaseModel):
    """Parameters controlling text/token generation for models."""

    max_new_tokens: int = Field(default=512, ge=1)
    temperature: float = Field(default=0.0, ge=0.0)
    top_p: float = Field(default=1.0, ge=0.0, le=1.0)
    top_k: int | None = Field(default=None, ge=0)
    do_sample: bool = Field(default=False)
    extra: dict[str, Any] = Field(default_factory=dict)


class PromptConfig(BaseModel):
    """Parameters for prompt preparation and template formatting."""

    image_token: str = Field(default="<|image|>")
    add_generation_prompt: bool = Field(default=True)
    system_prompt: str | None = Field(default=None)
    extra: dict[str, Any] = Field(default_factory=dict)


class ModelRuntimeConfig(BaseModel):
    """Runtime configuration contract for model adapters."""

    model_name: str
    model_id: str
    device: str | None = None
    dtype: str | None = None
    generation: GenerationConfig = Field(default_factory=GenerationConfig)
    prompt: PromptConfig = Field(default_factory=PromptConfig)
    extra_kwargs: dict[str, Any] = Field(default_factory=dict)