factory
orchard.architectures.factory
¶
Models Factory Module.
Implements the Factory Pattern using a registry-based approach to decouple model instantiation from execution logic. Architectures are dynamically adapted to geometric constraints (channels, classes) resolved at runtime.
Architecture:
- Registry Pattern: Internal _MODEL_REGISTRY maps names to builders
- Dynamic Adaptation: Structural parameters derived from DatasetConfig
- Device Management: Automatic model transfer to target accelerator
Key Components:
get_model: Factory function for architecture resolution and instantiation_MODEL_REGISTRY: Internal mapping of architecture names to builders
Example
from orchard.architectures.factory import get_model model = get_model(device, dataset_cfg=cfg.dataset, arch_cfg=cfg.architecture) print(f"Parameters: {sum(p.numel() for p in model.parameters()):,}")
get_model(device, dataset_cfg, arch_cfg, verbose=True)
¶
Factory function to resolve, instantiate, and prepare architectures.
It maps configuration identifiers to specific builder functions via an internal registry. Structural parameters like input channels and class cardinality are derived from the 'effective' geometry resolved by the DatasetConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device
|
Hardware accelerator target. |
required |
dataset_cfg
|
DatasetConfig
|
Dataset sub-config with resolved metadata. |
required |
arch_cfg
|
ArchitectureConfig
|
Architecture sub-config with model selection. |
required |
verbose
|
bool
|
If True, emit builder-internal INFO logging. |
True
|
Returns:
| Type | Description |
|---|---|
Module
|
nn.Module: The instantiated model synchronized with the target device. |
Example
model = get_model(device, dataset_cfg=cfg.dataset, arch_cfg=cfg.architecture)
Raises:
| Type | Description |
|---|---|
ValueError
|
If the requested architecture is not found in the registry. |