Skip to content

The platform for continuously improving AI agents.

4.5 KB
Raw Blame
"""FamilySpec — plain data describing one model family.

All fields are JSON-serializable primitives so this module stays stdlib-only
and can ship into training / serving containers without torch or Django.
"""

from __future__ import annotations

from dataclasses import dataclass, field


@dataclass(frozen=True)
class FamilySpec:
    """Per-family flags + patches. Behavior hooks live elsewhere (see hooks_module)."""

    key: str
    # Ordered substrings matched against lowercased model_id. First match wins
    # across the global registry order — put specific patterns before general ones.
    patterns: tuple[str, ...]
    # Modal Unsloth image key — frozen stack id in modal_shared.stacks.
    train_image: str = "u2026_8_18"
    # Family default when the catalog row omits dedicated_engine / serverless_engine.
    serve_image: str = "vllm"
    trust_remote_code: bool = False
    # Antares/Granite MoE hybrid — skip Unsloth for_inference / use_cache.
    is_hybrid: bool = False
    # Explicit LoRA targets when Unsloth all-linear expands wrong (LFM2).
    lora_target_modules: str | None = None
    # Regex pattern strings for pretok multi-header masking (compiled at use site).
    pretok_headers: tuple[str, ...] = ()
    # Tool-result spans inside assistant turns that lack a role header.
    force_mask_pairs: tuple[tuple[str, str], ...] = ()
    # vLLM --tool-call-parser value.
    tool_call_parser: str = "hermes"
    # vLLM --reasoning-parser when set (e.g. "qwen3", "openai_gptoss").
    reasoning_parser: str | None = None
    # Chat-completions defaults (gateway merges when the client omitted them).
    # Harmony rejects reasoning_effort=none — use "low" + suppress output instead.
    suppress_reasoning_output: bool = False
    default_reasoning_effort: str | None = None
    # Merged into vLLM --default-chat-template-kwargs and request extras.
    default_chat_template_kwargs: tuple[tuple[str, str], ...] = ()
    # Floor for a client's max_tokens. Models whose chat template always spends
    # a chunk of the budget on a hidden preamble (e.g. reasoning that can't be
    # switched fully off) return content=null under this floor, no matter how
    # low reasoning effort is set.
    min_max_tokens: int | None = None
    # Force --dtype (e.g. "bfloat16" for LFM even when FP8).
    dtype_override: str | None = None
    mixed_moe_lora_format: bool = False
    # Text-only fine-tune of a multimodal base needs --language-model-only.
    natively_multimodal: bool = False
    # Normalized id tokens for multimodal detection (qwen3-5, gemma-4, …).
    multimodal_id_tokens: tuple[str, ...] = ()
    # Keys dispatched by weight_ops.fix_model_type (pure data, no callables).
    # Known: nest_qwen3_5_text, lfm_layer_types, granite_layer_types, nemotron_h.
    config_fixups: tuple[str, ...] = ()
    notes: str = ""
    # Optional TrainerHooks module path relative to sft_assets (e.g. "families.gemma4").
    hooks_module: str | None = None
    # Extra substrings that flip trust_remote / llama31 helpers without changing key.
    llama31_patterns: tuple[str, ...] = field(default_factory=tuple)
    # False when packing fills the step to MAX_LENGTH and the family OOMs.
    packing: bool = True
    # Modal refuses a larger GPU count and moves the run to clamped_train_gpu.
    max_train_gpus: int | None = None
    clamped_train_gpu: str = "H200"
    # Set when the checkpoint does not fit the params-based GPU table.
    train_gpu: str | None = None
    # model_id substrings that force LoRA dropout to 0.
    zero_lora_dropout_tokens: tuple[str, ...] = ()
    # LoRA loads 4-bit even when the memory plan says bf16 fits.
    lora_load_in_4bit: bool = False
    # Bare string content hits the vision loader. Text parts do not.
    string_content_as_parts: bool = False
    # Dedicated forced-tool pattern. {alt} is the escaped function names.
    forced_tool_regex: str | None = None
    parallel_tool_hint: str = ""
    # SGLang --lora-target-modules when the family list is not in the image allowlist.
    sglang_serve_lora_targets: str = ""
    # Adapter tensors to keep. Empty uses lora_target_modules.
    sglang_adapter_targets: str = ""
    # Module with process_env(), imported for that engine only.
    sglang_process_env: str = ""
    # Module exposing build_args() with the same signature as serving.sglang.build_sglang_args.
    sglang_args_module: str = ""
    vllm_process_env: str = ""
    # Mistral tokenizers reject chat_template_kwargs. Their instruct templates
    # do not open a think block, so the request must not carry enable_thinking.
    emit_thinking_kwargs: bool = True