Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegistryMixin - tooling for easier registry/plugin patterns across NM repos #365

Merged
merged 8 commits into from
Oct 5, 2023

Conversation

bfineran
Copy link
Contributor

@bfineran bfineran commented Sep 12, 2023

proposes a structure that can be used as a universal registry for NM parent classes that follow a registry pattern or future plugins

Classes or factories that require a registry can add RegistryMixin as a parent class to get access to the functionality. The included classmethods should work for each class that contains the mixin separately.

Supports either loading values either from the registered names or a file:name pattern for custom file impelementations.

brief example from doc

class Dataset(RegistryMixin):
    pass


# register with default name
@Dataset.register()
class ImageNetDataset(Dataset):
    pass

# load as "ImageNetDataset"
imagenet = Dataset.load("ImageNetDataset")

# register with custom name
@Dataset.register(name="cifar-dataset")
class Cifar(Dataset):
    pass

# load as "cifar-dataset"
cifar = Dataset.load_from_registry("cifar-dataset")

# load from custom file that implements a dataset
mnist = Dataset.load_from_registry("/path/to/mnnist_dataset.py:MnistDataset")

test_plan:
simple unit tests included

@bfineran bfineran self-assigned this Sep 12, 2023
Satrat
Satrat previously approved these changes Sep 20, 2023
src/sparsezoo/utils/registry.py Show resolved Hide resolved
src/sparsezoo/utils/registry.py Show resolved Hide resolved
src/sparsezoo/utils/registry.py Show resolved Hide resolved
src/sparsezoo/utils/registry.py Show resolved Hide resolved
src/sparsezoo/utils/registry.py Outdated Show resolved Hide resolved
src/sparsezoo/utils/registry.py Show resolved Hide resolved
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
@bfineran bfineran merged commit 23f40e7 into main Oct 5, 2023
2 checks passed
@bfineran bfineran deleted the registry-mixin branch October 5, 2023 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants