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. Common values:
"base", "image-classification", "object-detection",
"semantic-segmentation", "causal-lm", "masked-lm",
"seq2seq-lm", "sequence-classification",
"token-classification", "question-answering",
"image-generation".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 53
- lucid.models
- lucid.models.generative.ddpm._pretrained
- lucid.models.generative.ncsn._pretrained
- lucid.models.generative.vae._pretrained
- lucid.models.text.bert._pretrained
- lucid.models.text.gpt._pretrained
- lucid.models.text.gpt2._pretrained
- lucid.models.text.roformer._pretrained
- lucid.models.text.transformer._pretrained
- lucid.models.vision.alexnet._pretrained
- lucid.models.vision.attention_unet._pretrained
- lucid.models.vision.coatnet._pretrained
… 41 more