Abstract codebase with utilities to register generic modules.
Project description
abstract-codebase
An abstract codebase with utilities for registering generic modules with an optional configuration setup and accreditation system.
Installation
The codebase can be installed from PyPI using pip
, or your package manager of choice, with
$ pip install abstract-codebase
Dependencies
No dependencies to use the minimal Registry functionality. The configuration setup depends on yaml and hydra.
Usage
RegistryFactory
The codebase provides a way to register generic modules into a codebase. First a specific Registry is created, e.g. for deep learning models.
from abstract_codebase.registration import RegistryFactory
class ModelRegistry(RegistryFactory):
pass
Next, any models can be added to the ModelRegistry as such.
import torch.nn as nn
@ModelRegistry.register(call_name="simple_model")
class SimpleModel(nn.Module):
def __init__(self, layer_sizes) -> None:
super(SimpleModel, self).__init__()
dropout_rate = 0.25
self.layers = nn.ModuleList()
for layer in range(len(layer_sizes)-2):
self.layers.append(
nn.Sequential(
nn.Linear(hidden_layers[layer], hidden_layers[layer+1]),
nn.ReLU(),
nn.Dropout(p=dropout_rate)
)
)
self.layers.append(
nn.Sequential(
nn.Linear(hidden_layers[-2], hidden_layers[-1])
)
)
def forward(self, x):
for layer in self.layers:
x = layer(x)
return x
Configurations
Each registered module can be accompanied with a dataclass of settings with default values.
@ModelRegistry.register(call_name="simple_model")
@dataclass(unsafe_hash=True)
class SimpleModelArguments():
dropout_rate = 0.25
As such, the model can rather be defined as.
@ModelRegistry.register(call_name="simple_mlp")
class SimpleModel(nn.Module):
def __init__(self, layer_sizes, args: SimpleModelArguments) -> None:
super(SimpleMLP, self).__init__()
dropout_rate = args.dropout_rate
...
Further, the Config class can be used to read and update configurations across all modules, through yaml files or the command line interface.
Accreditation
At registration of a module, additional information can be supplied such as author, credit type and more. This information can be used to collect a summary of the accreditation required for all modules used in a given script.
@ModelRegistry.register(
call_name="simple_model",
author="Author name",
credit_type=CreditType.REFERENCE,
additional_information="Reference published work in (link)."
)
class SimpleModel(nn.Module):
...
TODO exemplify an accreditation summery.
ModelRegistry.get_accreditation()
Code of Conduct
Everyone interacting in the codebase, issue trackers, chat rooms, and mailing lists is expected to follow the PyPA Code of Conduct.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for registry_factory-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ea1cffee25b64c52690e1000b0eb351cdcd9d280a52a04633f88bcb1e330ce1 |
|
MD5 | 5887fe38d054d75715ac810ac6d43502 |
|
BLAKE2b-256 | a3011bc3fdd07c51fbebf7da449e7c0dc2ff581055c61e7d929ea33da7f55934 |