fn
register_model
→Callable[[ModelFactory], ModelFactory]register_model(task: str = 'base', family: str | None = None, model_type: str | None = None, model_class: type[PretrainedModel] | None = None, default_config: ModelConfig | None = None, params: int | None = None, summary: object = 'auto')Decorator that registers a factory function under its __name__.
The global registry is the single source of truth for which models
Lucid exposes. Every public factory in lucid/models/**/_pretrained.py
is decorated with @register_model so it becomes discoverable via
create_model, list_models, and the AutoModelFor*
family.
Parameters
taskstr= "base"Task tag used by Auto classes for typed dispatch. One of
"base" (a backbone with no head) or the eight task tags
declared in lucid.models._tasks:
"image-classification", "image-generation",
"object-detection", "semantic-segmentation",
"sequence-classification", "token-classification",
"language-modeling", "world-modeling". The tag a factory
passes must equal its model_class.task, which the suite
asserts — the two used to be independent strings and drifted.familystr or None= NoneArchitecture family identifier (e.g.
"resnet"). When None,
inferred from the factory's parent module name (the
second-to-last component of fn.__module__).model_typestr or None= NonePersistent
ModelConfig.model_type value this factory produces.
Defaults to family. Used by directory-based loading to match
on-disk config.json files against registered factories.The concrete
PretrainedModel subclass returned by this
factory. When supplied, directory-based loading
(AutoModel.from_pretrained against a path) avoids a
redundant factory call — strongly recommended.The default config produced when
pretrained=False. When
supplied, AutoConfig.from_pretrained returns it without
instantiating the model.paramsint or None= NonePaper-cited trainable-parameter count for this factory's default
config (e.g.
61_100_840 for alexnet_cls). Surfaced on
the API docs site as a "61.1M"-style tag on the factory
card and as a "Model Size" section on the detail page. Omit
(None) when no authoritative count is available — the UI
then hides the tag rather than guessing.summaryobject= "auto"Layer-tree summary used by the docs site's collapsible
"Model Size" section.
"auto" (the canonical value) tells
tools/build_model_summaries.py to introspect the model via
shadow_alloc and emit a real tree. Pass an already-built
summary dict to override the introspection (rare — used only
when shadow-alloc introspection fails for a model family).Returns
Callable[[ModelFactory], ModelFactory]Decorator that returns the original factory unmodified (only the registry side-effect occurs).
Raises
ValueErrorIf a model is already registered under the same normalised name.
Notes
The decorator uses the factory's __name__ (normalised through
_normalize) as the registry key. Same name twice raises —
this catches accidental shadowing across families.
Examples
>>> from lucid.models import register_model, PretrainedModel
>>> # Inside lucid/models/vision/myfamily/_pretrained.py:
>>> @register_model(
... task="image-classification",
... family="myfamily",
... model_type="myfamily",
... )
... def myfamily_small(pretrained: bool = False, **overrides):
... cfg = MyFamilyConfig(depth=12, **overrides)
... return MyFamilyForImageClassification(cfg)Used by 76
- lucid.models
- lucid.models.generative.ddpm._pretrained
- lucid.models.generative.diamond._pretrained
- lucid.models.generative.dit._pretrained
- lucid.models.generative.dreamer._pretrained
- lucid.models.generative.dreamer_v2._pretrained
- lucid.models.generative.dreamer_v3._pretrained
- lucid.models.generative.flow_matching._pretrained
- lucid.models.generative.genie._pretrained
- lucid.models.generative.mean_flow._pretrained
- lucid.models.generative.ncsn._pretrained
- lucid.models.generative.neural_ode._pretrained
… 64 more