Composite structural contract for a family Config class.
A class satisfies this protocol when it simultaneously
- declares a non-empty
model_typeClassVar (HasModelType), - has been decorated with
@model_family_metaso that__model_family_meta__is set (HasFamilyMeta), - is a
@dataclass— the__dataclass_fields__ClassVar below is the witness that the dataclass transform ran.
Use this protocol in any function that accepts arbitrary family
Configs without coupling to the nominal ModelConfig
base — third-party model packages may satisfy it via duck
typing.
Attributes
model_typeClassVar[str]Inherited from
HasModelType — see that protocol.__model_family_meta__ClassVar[object]Inherited from
HasFamilyMeta — see that protocol.__dataclass_fields__ClassVar[dict[str, Any]]Standard attribute set by
dataclasses.dataclass;
used here as the runtime witness that the class went through
the dataclass transform.Notes
The protocol is runtime_checkable, so the static
validator (tools/validate_model_zoo.py --runtime) can use
isinstance(cls, ModelConfigProtocol) to catch refactor drift
(e.g. a decorator that silently strips
__model_family_meta__). See arch-models-family-contract
for the full 5-slot family layout.
Examples
Every documented family Config satisfies the contract:
>>> from lucid.models.vision.resnet import ResNetConfig
>>> from lucid.models.text.bert import BERTConfig
>>> from lucid.models._protocols import ModelConfigProtocol
>>> all(isinstance(c, ModelConfigProtocol) for c in (ResNetConfig, BERTConfig))
True
A duck-typed third-party Config with the right shape also
qualifies — no need to inherit from ModelConfig:
>>> from typing import ClassVar
>>> class Stranger:
... model_type: ClassVar[str] = "stranger"
... __model_family_meta__: ClassVar[object] = object()
... __dataclass_fields__: ClassVar[dict] = {}
>>> isinstance(Stranger, ModelConfigProtocol)
True