Develop a custom artifact store
Learning how to develop a custom artifact store.
Develop a custom artifact store
Base Abstraction
As ZenML only supports filesystem-based artifact stores, it features a configuration parameter called
path
, which will indicate the root path of the artifact store. When registering an artifact store, users will have to define this parameter.Moreover, there is another variable in the config class called
SUPPORTED_SCHEMES
. This is a class variable that needs to be defined in every subclass of the base artifact store configuration. It indicates the supported file path schemes for the corresponding implementation. For instance, for the Azure artifact store, this set will be defined as{"abfs://", "az://"}
.Lastly, the base class features a set of
abstractmethod
s:open
,copyfile
,exists
,glob
,isdir
,listdir
,makedirs
,mkdir
,remove
,rename
,rmtree
,stat
,walk
. In the implementation of everyArtifactStore
flavor, it is required to define these methods with respect to the flavor at hand.
Putting all these considerations together, we end up with the following implementation:
The effect on the zenml.io.fileio
If you created an instance of an artifact store, added it to your stack, and activated the stack, it will create a filesystem each time you run a ZenML pipeline and make it available to the zenml.io.fileio
module.
This means that when you utilize a method such as fileio.open(...)
with a file path that starts with one of the SUPPORTED_SCHEMES
within your steps or materializers, it will be able to use the open(...)
method that you defined within your artifact store.
Build your own custom artifact store
If you want to implement your own custom Artifact Store, you can follow the following steps:
Once you are done with the implementation, you can register it through the CLI. Please ensure you point to the flavor class via dot notation:
For example, if your flavor class MyArtifactStoreFlavor
is defined in flavors/my_flavor.py
, you'd register it by doing:
If ZenML does not find an initialized ZenML repository in any parent directory, it will default to the current working directory, but usually, it's better to not have to rely on this mechanism and initialize zenml at the root.
Afterward, you should see the new custom artifact store flavor in the list of available artifact store flavors:
It is important to draw attention to when and how these base abstractions are coming into play in a ZenML workflow.
The CustomArtifactStoreFlavor class is imported and utilized upon the creation of the custom flavor through the CLI.
The CustomArtifactStoreConfig class is imported when someone tries to register/update a stack component with this custom flavor. Especially, during the registration process of the stack component, the config will be used to validate the values given by the user. As
Config
objects are inherentlypydantic
objects, you can also add your own custom validators here.The CustomArtifactStore 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 CustomArtifactStoreFlavor
and the CustomArtifactStoreConfig
are implemented in a different module/path than the actual CustomArtifactStore
).
Enabling Artifact Visualizations with Custom Artifact Stores
ZenML automatically saves visualizations for many common data types and allows you to view these visualizations in the ZenML dashboard. Under the hood, this works by saving the visualizations together with the artifacts in the artifact store.
In order to load and display these visualizations, ZenML needs to be able to load and access the corresponding artifact store. This means that your custom artifact store needs to be configured in a way that allows authenticating to the back-end without relying on the local environment, e.g., by embedding the authentication credentials in the stack component configuration or by referencing a secret.
Furthermore, for deployed ZenML instances, you need to install the package dependencies of your artifact store implementation in the environment where you have deployed ZenML.
Last updated