Base class for every model's configuration dataclass.
A ModelConfig subclass holds the hyper-parameters that fully
determine a model's architecture (depths, widths, vocab sizes,
activation choices, …). Configs are immutable, JSON-serialisable,
and the single argument every concrete PretrainedModel
constructor accepts.
Subclasses must:
- Use
@dataclass(frozen=True)(immutability +fields()introspection). - Set the
model_typeClassVar[str]to a unique family identifier (e.g."resnet","bert"). - Optionally implement
__post_init__for cross-field validation.
Attributes
model_typeClassVar[str]config.json on
disk and used by directory-based loading to find the correct
registry entry.Notes
The base class provides a JSON round-trip via to_dict /
from_dict / save / load. Unknown fields are
tolerated on load with a UserWarning — this lets newer
checkpoints (which may have added fields) load into older code
without crashing.
Examples
>>> from dataclasses import dataclass
>>> @dataclass(frozen=True)
... class MyConfig(ModelConfig):
... model_type: ClassVar[str] = "myfamily"
... hidden_size: int = 768
... num_layers: int = 12
>>> cfg = MyConfig(hidden_size=1024)
>>> cfg.to_dict()["model_type"]
'myfamily'See Also
lucid.models._meta.model_family_metaClass decorator that attaches paper / theory / display metadata(canonical_name / citation / theory) to a Configsubclass. Concrete families wrap their Config with this so thedocs site can render family-root index pages.
Used by 50
- lucid.models
- lucid.models._auto
- lucid.models._meta
- lucid.models._registry
- lucid.models.generative._config
- lucid.models.text._config
- lucid.models.vision.alexnet._config
- lucid.models.vision.attention_unet._config
- lucid.models.vision.coatnet._config
- lucid.models.vision.convnext._config
- lucid.models.vision.crossvit._config
- lucid.models.vision.cspnet._config
… 38 more
Class methods
2Reconstruct a config from a plain dict (inverse of to_dict).
Parameters
ddict[str, object]model_type is silently
stripped (it's a ClassVar, not a constructor arg).Returns
SelfNew instance of cls populated from d.
Raises
TypeErrorcls is not a @dataclass.Examples
>>> cfg = MyConfig.from_dict({"hidden_size": 512, "model_type": "myfamily"})
>>> cfg.hidden_size
512Load a config from a JSON file (inverse of save).
Parameters
pathstrsave.Returns
SelfReconstructed config instance.
Raises
ValueErrorpath does not contain a JSON object.Examples
>>> cfg = MyConfig.load("/tmp/myconfig.json")Instance methods
2Write the config as pretty-printed JSON to path.
Parameters
pathstrExamples
>>> cfg = MyConfig(hidden_size=1024)
>>> cfg.save("/tmp/myconfig.json")Serialise the config (including model_type) to a plain dict.
Returns
dict[str, object]JSON-friendly mapping of every dataclass field plus the
model_type ClassVar.
Raises
TypeErrorself is not a @dataclass.Examples
>>> cfg = MyConfig(hidden_size=1024)
>>> d = cfg.to_dict()
>>> d["hidden_size"], d["model_type"]
(1024, 'myfamily')