Develop a Custom Step Operator
Learning how to develop a custom step operator.
Base Abstraction
from abc import ABC, abstractmethod
from typing import List, Type
from zenml.enums import StackComponentType
from zenml.stack import StackComponent, StackComponentConfig, Flavor
from zenml.config.step_run_info import StepRunInfo
class BaseStepOperatorConfig(StackComponentConfig):
"""Base config for step operators."""
class BaseStepOperator(StackComponent, ABC):
"""Base class for all ZenML step operators."""
def submit(
self,
info: "StepRunInfo",
entrypoint_command: List[str],
environment: Dict[str, str],
) -> None:
"""Submit a step run.
This method should submit the step run and return without waiting for
it to finish.
Args:
info: Information about the step run.
entrypoint_command: Command that executes the step.
environment: Environment variables to set in the step operator
environment.
"""
def get_status(self, step_run: "StepRunResponse") -> ExecutionStatus:
"""Get the status of a step run.
Args:
step_run: The step run to get the status of.
"""
def cancel(self, step_run: "StepRunResponse") -> None:
"""Cancel a step run.
Args:
step_run: The step run to cancel.
"""
class BaseStepOperatorFlavor(Flavor):
"""Base class for all ZenML step operator flavors."""
@property
@abstractmethod
def name(self) -> str:
"""Returns the name of the flavor."""
@property
def type(self) -> StackComponentType:
"""Returns the flavor type."""
return StackComponentType.STEP_OPERATOR
@property
def config_class(self) -> Type[BaseStepOperatorConfig]:
"""Returns the config class for this flavor."""
return BaseStepOperatorConfig
@property
@abstractmethod
def implementation_class(self) -> Type[BaseStepOperator]:
"""Returns the implementation class for this flavor."""Build your own custom step operator
Enabling CUDA for GPU-backed hardware
Last updated
Was this helpful?