Model Protocols#
Runtime-checkable Protocols for encoder/decoder extraction from models.
Overview#
The chronocratic.models.protocols module defines Protocols that allow users to check whether a model exposes its encoder (and optionally decoder) as a standalone nn.Module.
Available Protocols#
Runtime-checkable protocols for encoder/decoder extraction.
These Protocols provide a uniform, programmatically-verified interface for accessing encoder and decoder modules across all model implementations.
A model satisfies HasEncoder if it exposes a read-only .encoder property
that returns an nn.Module. Similarly, HasDecoder requires a
.decoder property. Both use @runtime_checkable so they work with
isinstance() checks — unlike plain class attributes, which fail
isinstance verification due to nn.Module.__getattr__ overriding.
- class chronocratic.models.protocols.HasEncoder(*args, **kwargs)#
Bases:
ProtocolProtocol for models with a publicly accessible encoder module.
The
encoderproperty must return annn.Modulethat can be used for representation extraction, checkpointing, or fine-tuning.- property encoder: Module#
Return the encoder submodule.
Usage#
from chronocratic.models.protocols import HasEncoder, HasDecoder
from chronocratic.models import TimeVAE
model = TimeVAE(seq_len=100, feat_dim=1, latent_dim=10)
# Check encoder availability
if isinstance(model, HasEncoder):
encoder = model.encoder # nn.Module
# Check decoder availability
if isinstance(model, HasDecoder):
decoder = model.decoder # nn.Module
Implementation Details#
HasEncoderrequires a@property encoderreturningnn.ModuleHasDecoderrequires a@property decoderreturningnn.ModuleBoth are
@runtime_checkable— useisinstance()for checksThe conformance test (
tests/test_encoder_decoder_contract.py) verifies all 9 models satisfy these contracts