Develop a Custom Model Registry
Learning how to develop a custom model registry.
Before diving into the specifics of this component type, it is beneficial to familiarize yourself with our general guide to writing custom component flavors in ZenML. This guide provides an essential understanding of ZenML's component flavor concepts.
Base abstraction in progress!
The Model registry stack component is relatively new in ZenML. While it is fully functional, it can be challenging to cover all the ways ML systems deal with model versioning. This means that the API might change in the future. We will keep this page up-to-date with the latest changes.
If you are writing a custom model registry flavor, and you found that the base abstraction is lacking or not flexible enough, please let us know by messaging us on Slack, or by opening an issue on GitHub
Base Abstraction
The BaseModelRegistry
is the abstract base class that needs to be subclassed in order to create a custom component that can be used to register and retrieve models. As model registries can come in many shapes and forms, the base class exposes a deliberately basic and generic interface:
This is a slimmed-down version of the base implementation which aims to highlight the abstraction layer. To see the full implementation and get the complete docstrings, please check the source code on GitHub .
Build your own custom model registry
If you want to create your own custom flavor for a model registry, you can follow the following steps:
Learn more about the core concepts for the model registry here. Your custom model registry will be built on top of these concepts so it helps to be aware of them.
Create a class that inherits from
BaseModelRegistry
and implements the abstract methods.Create a
ModelRegistryConfig
class that inherits fromBaseModelRegistryConfig
and adds any additional configuration parameters that you need.Bring the implementation and the configuration together by inheriting from the
BaseModelRegistryFlavor
class. Make sure that you give aname
to the flavor through its abstract property.
Once you are done with the implementation, you can register it through the CLI with the following command:
It is important to draw attention to how and when these base abstractions are coming into play in a ZenML workflow.
The CustomModelRegistryFlavor class is imported and utilized upon the creation of the custom flavor through the CLI.
The CustomModelRegistryConfig class is imported when someone tries to register/update a stack component with this custom flavor. Most of all, during the registration process of the stack component, the config will be used to validate the values given by the user. As
Config
objects arepydantic
objects under the hood, you can also add your own custom validators here.The CustomModelRegistry only comes into play when the component is ultimately in use.
The design behind this interaction lets us separate the configuration of the flavor from its implementation. This way we can register flavors and components even when the major dependencies behind their implementation are not installed in our local setting (assuming the CustomModelRegistryFlavor
and the CustomModelRegistryConfig
are implemented in a different module/path than the actual CustomModelRegistry
).
For a full implementation example, please check out the MLFlowModelRegistry
Last updated