weights
9 memberslucid.weights`lucid.weights` — pretrained-weight system for the model zoo.
A standalone package (sibling to lucid.models) that provides the
infrastructure for pretrained checkpoints: the tagged-variant enum
base, hub download + SHA verification, loading, and a discovery
registry. Preprocessing lives in lucid.utils.transforms; a
checkpoint's WeightEntry carries one of those transforms.
It deliberately contains no architecture-specific weight
declarations. Each model family declares its own checkpoints in a
_weights.py module inside the model package (e.g.
lucid.models.vision.resnet._weights.ResNet18Weights), importing the
primitives below. This keeps lucid.weights a pure porting
substrate and the dependency one-directional (models → weights,
never the reverse).
Notes
Each architecture declares a WeightsEnum (e.g.
ResNet18Weights) whose members are WeightEntry manifests —
one per tagged checkpoint (IMAGENET1K_V1, …) plus a DEFAULT
alias. This mirrors the torchvision Weights enum so call sites are
familiar:
import lucid.models as models
import lucid.weights as weights
# default tag
model = models.resnet_18(pretrained=True)
# explicit tag — enum or string
from lucid.models.vision.resnet import ResNet18Weights
model = models.resnet_18_cls(weights=ResNet18Weights.IMAGENET1K_V1)
model = models.resnet_18_cls(pretrained="IMAGENET1K_V1")
# discover + preprocess (after the model package is imported)
weights.list_pretrained("resnet_18") # ['IMAGENET1K_V1']
w = weights.get_weight("ResNet18Weights.IMAGENET1K_V1")
x = w.transforms()(image)
The package depends only on lucid.serialization (for SafeTensors
loading); model factories depend on it, never the reverse, so there is
no circular import. Crucially, WeightEntry carries no model
config — named factories already pin their own.
Checkpoints are hosted on the Hugging Face Hub under the lucid-dl
org, converted from torchvision / timm / transformers sources by the
offline tools/convert_weights pipeline.
Classes
Functions
download→ pathlib.PathDownload url to the local cache, verify SHA-256, return the path.
load_weight_entry→ objectDownload the checkpoint described by weights and load it.
resolve_weights→ WeightsEnum or NoneResolve a factory's pretrained / weights args to a member.
get_weight→ WeightsEnumResolve a dotted "EnumName.TAG" string to a weights member.
list_pretrained→ list of strList the available weight tags for a model.
register_weights→ Callable[[type[WeightsEnum]], type[WeightsEnum]]Class decorator registering a WeightsEnum for discovery.
weights_for→ type[WeightsEnum] or NoneReturn the WeightsEnum registered for model_name.