Modal
zenml.integrations.modal
Modal integration for cloud-native pipeline and step execution.
The Modal integration sub-module provides stack component flavors that allow executing pipelines and individual steps on Modal's cloud infrastructure.
Attributes
MODAL = 'modal'
module-attribute
MODAL_ORCHESTRATOR_FLAVOR = 'modal'
module-attribute
MODAL_SANDBOX_FLAVOR = 'modal'
module-attribute
MODAL_STEP_OPERATOR_FLAVOR = 'modal'
module-attribute
Classes
Flavor
Class for ZenML Flavors.
Attributes
config_class: Type[StackComponentConfig]
abstractmethod
property
Returns StackComponentConfig config class.
Returns:
| Type | Description |
|---|---|
Type[StackComponentConfig]
|
The config class. |
config_schema: Dict[str, Any]
property
The config schema for a flavor.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
The config schema. |
display_name: Optional[str]
property
The display name of the flavor.
By default, converts the technical name to a human-readable format. For example, "vm_kubernetes" becomes "VM Kubernetes". Flavors can override this to provide custom display names.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The display name of the flavor. |
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[StackComponent]
abstractmethod
property
Implementation class for this flavor.
Returns:
| Type | Description |
|---|---|
Type[StackComponent]
|
The implementation class for this flavor. |
logo_url: Optional[str]
property
A url to represent the flavor in the dashboard.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor logo. |
name: str
abstractmethod
property
The flavor name.
Returns:
| Type | Description |
|---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
A url to point at SDK docs explaining this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
A flavor SDK docs url. |
service_connector_requirements: Optional[ServiceConnectorRequirements]
property
Service connector resource requirements for service connectors.
Specifies resource requirements that are used to filter the available service connector types that are compatible with this flavor.
Returns:
| Type | Description |
|---|---|
Optional[ServiceConnectorRequirements]
|
Requirements for compatible service connectors, if a service |
Optional[ServiceConnectorRequirements]
|
connector is required for this flavor. |
type: StackComponentType
abstractmethod
property
Methods:
from_model(flavor_model: FlavorResponse) -> Flavor
classmethod
Loads a flavor from a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flavor_model
|
FlavorResponse
|
The model to load from. |
required |
Raises:
| Type | Description |
|---|---|
CustomFlavorImportError
|
If the custom flavor can't be imported. |
ImportError
|
If the flavor can't be imported. |
Returns:
| Type | Description |
|---|---|
Flavor
|
The loaded flavor. |
Source code in src/zenml/stack/flavor.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
generate_default_docs_url() -> str
Generate the doc urls for all inbuilt and integration flavors.
Note that this method is not going to be useful for custom flavors, which do not have any docs in the main zenml docs.
Returns:
| Type | Description |
|---|---|
str
|
The complete url to the zenml documentation |
Source code in src/zenml/stack/flavor.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
generate_default_sdk_docs_url() -> str
Generate SDK docs url for a flavor.
Returns:
| Type | Description |
|---|---|
str
|
The complete url to the zenml SDK docs |
Source code in src/zenml/stack/flavor.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
to_model(integration: Optional[str] = None, is_custom: bool = True) -> FlavorRequest
Converts a flavor to a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integration
|
Optional[str]
|
The integration to use for the model. |
None
|
is_custom
|
bool
|
Whether the flavor is a custom flavor. |
True
|
Returns:
| Type | Description |
|---|---|
FlavorRequest
|
The model. |
Source code in src/zenml/stack/flavor.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
Integration
Base class for integration in ZenML.
Methods:
activate() -> None
classmethod
Abstract method to activate the integration.
Source code in src/zenml/integrations/integration.py
136 137 138 | |
check_installation() -> bool
classmethod
Method to check whether the required packages are installed.
Returns:
| Type | Description |
|---|---|
bool
|
True if all required packages are installed, False otherwise. |
Source code in src/zenml/integrations/integration.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
flavors() -> List[Type[Flavor]]
classmethod
Abstract method to declare new stack component flavors.
Returns:
| Type | Description |
|---|---|
List[Type[Flavor]]
|
A list of new stack component flavors. |
Source code in src/zenml/integrations/integration.py
140 141 142 143 144 145 146 147 | |
get_requirements(target_os: Optional[str] = None, python_version: Optional[str] = None) -> List[str]
classmethod
Method to get the requirements for the integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_os
|
Optional[str]
|
The target operating system to get the requirements for. |
None
|
python_version
|
Optional[str]
|
The Python version to use for the requirements. |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of requirements. |
Source code in src/zenml/integrations/integration.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
get_uninstall_requirements(target_os: Optional[str] = None) -> List[str]
classmethod
Method to get the uninstall requirements for the integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_os
|
Optional[str]
|
The target operating system to get the requirements for. |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of requirements. |
Source code in src/zenml/integrations/integration.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
ModalIntegration
Bases: Integration
Definition of Modal integration for ZenML.
Methods:
flavors() -> List[Type[Flavor]]
classmethod
Declare the stack component flavors for the Modal integration.
Returns:
| Type | Description |
|---|---|
List[Type[Flavor]]
|
List of new stack component flavors. |
Source code in src/zenml/integrations/modal/__init__.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
Modules
flavors
Modal integration flavors.
Classes
ModalOrchestratorConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseOrchestratorConfig, ModalCredentialsMixin, ModalOrchestratorSettings
Configuration for the Modal orchestrator.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
handles_step_retries: bool
property
Whether the orchestrator handles step retries internally.
is_local: bool
property
Checks if this stack component is running locally.
is_remote: bool
property
Checks if this stack component is running remotely.
is_schedulable: bool
property
Whether the orchestrator supports schedules.
is_synchronous: bool
property
Whether the orchestrator runs synchronously or not.
supports_client_side_caching: bool
property
Whether the orchestrator supports client-side caching.
ModalOrchestratorFlavor
Bases: BaseOrchestratorFlavor
Modal orchestrator flavor.
config_class: Type[ModalOrchestratorConfig]
property
Returns the Modal orchestrator config class.
docs_url: Optional[str]
property
A URL to point at docs explaining this flavor.
implementation_class: Type[ModalOrchestrator]
property
Implementation class for this flavor.
logo_url: str
property
A URL to represent the flavor in the dashboard.
name: str
property
Name of the flavor.
sdk_docs_url: Optional[str]
property
A URL to point at SDK docs explaining this flavor.
ModalOrchestratorSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: ModalSettingsMixin
Settings for Modal sandboxes created by the orchestrator.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
ModalSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxConfig, ModalCredentialsMixin, ModalSandboxSettings
Configuration for the Modal sandbox component.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
is_remote: bool
property
Checks if this stack component is running remotely.
Modal sandboxes always run in Modal's cloud, so they require a remote ZenML server rather than a local database.
Returns:
| Type | Description |
|---|---|
bool
|
Always True, since Modal sandboxes run remotely. |
ModalSandboxFlavor
Bases: BaseSandboxFlavor
Modal sandbox flavor.
config_class: Type[ModalSandboxConfig]
property
docs_url: Optional[str]
property
URL to user-facing docs for this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor docs URL. |
implementation_class: Type[ModalSandbox]
property
logo_url: str
property
Dashboard logo URL.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo URL. |
name: str
property
Flavor name.
Returns:
| Type | Description |
|---|---|
str
|
|
sdk_docs_url: Optional[str]
property
URL to SDK docs for this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor SDK docs URL. |
ModalSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxSettings, ModalSettingsMixin
Per-step settings for the Modal sandbox.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
ModalStepOperatorConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseStepOperatorConfig, ModalCredentialsMixin, ModalStepOperatorSettings
Configuration for the Modal step operator.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
is_remote: bool
property
Checks if this stack component is running remotely.
This designation is used to determine if the stack component can be used with a local ZenML database or if it requires a remote ZenML server.
Returns:
| Type | Description |
|---|---|
bool
|
True if this config is for a remote component, False otherwise. |
ModalStepOperatorFlavor
Bases: BaseStepOperatorFlavor
Modal step operator flavor.
config_class: Type[ModalStepOperatorConfig]
property
Returns ModalStepOperatorConfig config class.
Returns:
| Type | Description |
|---|---|
Type[ModalStepOperatorConfig]
|
The config class. |
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[ModalStepOperator]
property
Implementation class for this flavor.
Returns:
| Type | Description |
|---|---|
Type[ModalStepOperator]
|
The implementation class. |
logo_url: str
property
A url to represent the flavor in the dashboard.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo. |
name: str
property
Name of the flavor.
Returns:
| Type | Description |
|---|---|
str
|
The name of the flavor. |
sdk_docs_url: Optional[str]
property
A url to point at SDK docs explaining this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
A flavor SDK docs url. |
ModalStepOperatorSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: ModalSettingsMixin
Settings for the Modal step operator.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
Modules
modal_base_flavor
Shared settings/credential mixins for Modal stack components.
ModalCredentialsMixin(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSettings
Shared Modal API token credentials.
Attributes:
| Name | Type | Description |
|---|---|---|
token_id |
Optional[str]
|
Modal API token ID (ak-xxxxx format) for authentication. |
token_secret |
Optional[str]
|
Modal API token secret (as-xxxxx format) for authentication. |
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
validate_modal_token_pair() -> ModalCredentialsMixin
Validate that Modal token fields are configured together.
Returns:
| Type | Description |
|---|---|
ModalCredentialsMixin
|
The validated instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If only one of token_id/token_secret is configured. |
Source code in src/zenml/integrations/modal/flavors/modal_base_flavor.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
ModalSettingsMixin(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSettings
Shared Modal compute and placement settings.
Attributes:
| Name | Type | Description |
|---|---|---|
gpu |
Optional[str]
|
The type of GPU to use for execution (e.g., "T4", "A100"). Use ResourceSettings.gpu_count to specify the number of GPUs. |
region |
Optional[str]
|
The region to use for execution. |
cloud |
Optional[str]
|
The cloud provider to use for execution. |
modal_environment |
Optional[str]
|
The Modal environment to use for app lookup. |
timeout |
int
|
Maximum execution time in seconds (default 24h). |
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
modal_orchestrator_flavor
Modal orchestrator flavor.
ModalOrchestratorConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseOrchestratorConfig, ModalCredentialsMixin, ModalOrchestratorSettings
Configuration for the Modal orchestrator.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
handles_step_retries: bool
property
Whether the orchestrator handles step retries internally.
is_local: bool
property
Checks if this stack component is running locally.
is_remote: bool
property
Checks if this stack component is running remotely.
is_schedulable: bool
property
Whether the orchestrator supports schedules.
is_synchronous: bool
property
Whether the orchestrator runs synchronously or not.
supports_client_side_caching: bool
property
Whether the orchestrator supports client-side caching.
ModalOrchestratorFlavor
Bases: BaseOrchestratorFlavor
Modal orchestrator flavor.
config_class: Type[ModalOrchestratorConfig]
property
Returns the Modal orchestrator config class.
docs_url: Optional[str]
property
A URL to point at docs explaining this flavor.
implementation_class: Type[ModalOrchestrator]
property
Implementation class for this flavor.
logo_url: str
property
A URL to represent the flavor in the dashboard.
name: str
property
Name of the flavor.
sdk_docs_url: Optional[str]
property
A URL to point at SDK docs explaining this flavor.
ModalOrchestratorSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: ModalSettingsMixin
Settings for Modal sandboxes created by the orchestrator.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
modal_sandbox_flavor
Modal sandbox flavor.
ModalSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxConfig, ModalCredentialsMixin, ModalSandboxSettings
Configuration for the Modal sandbox component.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
is_remote: bool
property
Checks if this stack component is running remotely.
Modal sandboxes always run in Modal's cloud, so they require a remote ZenML server rather than a local database.
Returns:
| Type | Description |
|---|---|
bool
|
Always True, since Modal sandboxes run remotely. |
ModalSandboxFlavor
Bases: BaseSandboxFlavor
Modal sandbox flavor.
config_class: Type[ModalSandboxConfig]
property
docs_url: Optional[str]
property
URL to user-facing docs for this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor docs URL. |
implementation_class: Type[ModalSandbox]
property
logo_url: str
property
Dashboard logo URL.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo URL. |
name: str
property
Flavor name.
Returns:
| Type | Description |
|---|---|
str
|
|
sdk_docs_url: Optional[str]
property
URL to SDK docs for this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor SDK docs URL. |
ModalSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxSettings, ModalSettingsMixin
Per-step settings for the Modal sandbox.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
modal_step_operator_flavor
Modal step operator flavor.
ModalStepOperatorConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseStepOperatorConfig, ModalCredentialsMixin, ModalStepOperatorSettings
Configuration for the Modal step operator.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
is_remote: bool
property
Checks if this stack component is running remotely.
This designation is used to determine if the stack component can be used with a local ZenML database or if it requires a remote ZenML server.
Returns:
| Type | Description |
|---|---|
bool
|
True if this config is for a remote component, False otherwise. |
ModalStepOperatorFlavor
Bases: BaseStepOperatorFlavor
Modal step operator flavor.
config_class: Type[ModalStepOperatorConfig]
property
Returns ModalStepOperatorConfig config class.
Returns:
| Type | Description |
|---|---|
Type[ModalStepOperatorConfig]
|
The config class. |
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[ModalStepOperator]
property
Implementation class for this flavor.
Returns:
| Type | Description |
|---|---|
Type[ModalStepOperator]
|
The implementation class. |
logo_url: str
property
A url to represent the flavor in the dashboard.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo. |
name: str
property
Name of the flavor.
Returns:
| Type | Description |
|---|---|
str
|
The name of the flavor. |
sdk_docs_url: Optional[str]
property
A url to point at SDK docs explaining this flavor.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
A flavor SDK docs url. |
ModalStepOperatorSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: ModalSettingsMixin
Settings for the Modal step operator.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
orchestrators
Modal orchestrator implementation package.
Classes
ModalOrchestrator(*args: Any, **kwargs: Any)
Bases: ContainerizedOrchestrator
Orchestrator that runs ZenML pipelines in Modal Sandboxes.
Initialize the Modal orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to the base orchestrator. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to the base orchestrator. |
{}
|
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
149 150 151 152 153 154 155 156 157 158 | |
config: ModalOrchestratorConfig
property
Get the Modal orchestrator configuration.
settings_class: Optional[Type[BaseSettings]]
property
Get the settings class for the Modal orchestrator.
supported_execution_modes: List[ExecutionMode]
property
Get the execution modes supported by the Modal orchestrator.
validator: Optional[StackValidator]
property
Validate that the active stack can run in remote Modal Sandboxes.
create_static_step_sandbox(*, snapshot: PipelineSnapshotResponse, step_name: str, environment: Dict[str, str]) -> modal.Sandbox
Create a child sandbox for a static pipeline step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotResponse
|
Static pipeline snapshot containing the step. |
required |
step_name
|
str
|
Name of the step to execute. |
required |
environment
|
Dict[str, str]
|
Runtime environment for the step sandbox. |
required |
Returns:
| Type | Description |
|---|---|
Sandbox
|
The created Modal step sandbox. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | |
fetch_status(run: PipelineRunResponse, include_steps: bool = False) -> Tuple[Optional[ExecutionStatus], Optional[Dict[str, ExecutionStatus]]]
Fetch Modal sandbox status for a pipeline run and its steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
PipelineRunResponse
|
Pipeline run backed by Modal sandboxes. |
required |
include_steps
|
bool
|
Whether to fetch statuses for child step sandboxes. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[Optional[ExecutionStatus], Optional[Dict[str, ExecutionStatus]]]
|
The pipeline sandbox status and optional step sandbox statuses. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
get_isolated_step_status(step_run: StepRunResponse) -> ExecutionStatus
Get the status of a dynamic isolated step sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
Isolated step run backed by the sandbox. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionStatus
|
The current sandbox execution status. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
get_modal_client() -> Optional[modal.Client]
Get the Modal client used by orchestrator entrypoints.
Returns:
| Type | Description |
|---|---|
Optional[Client]
|
A reusable Modal client, or |
Optional[Client]
|
not configured. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
get_orchestrator_run_id() -> str
Return the stable Modal run ID from the sandbox environment.
Returns:
| Type | Description |
|---|---|
str
|
The stable Modal orchestration run ID. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the Modal run ID environment variable is absent. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
get_pipeline_run_metadata(run_id: UUID) -> Dict[str, MetadataType]
Get run metadata from the Modal sandbox environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
UUID
|
ID of the pipeline run being described. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, MetadataType]
|
Run metadata containing Modal orchestration identifiers. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | |
get_step_sandbox_metadata(settings: ModalOrchestratorSettings, sandbox_id: str) -> Dict[str, MetadataType]
staticmethod
Build step sandbox metadata for orchestrator entrypoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ModalOrchestratorSettings
|
Modal settings used to create the sandbox. |
required |
sandbox_id
|
str
|
ID of the Modal step sandbox. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, MetadataType]
|
Run metadata describing the step sandbox. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
stop_isolated_step(step_run: StepRunResponse) -> None
Stop a dynamic isolated step sandbox if it is still running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
Isolated step run backed by the sandbox. |
required |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
submit_dynamic_pipeline(snapshot: PipelineSnapshotResponse, stack: Stack, environment: Dict[str, str], placeholder_run: Optional[PipelineRunResponse] = None) -> Optional[SubmissionResult]
Submit a dynamic pipeline orchestration sandbox to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotResponse
|
Dynamic pipeline snapshot to submit. |
required |
stack
|
Stack
|
Stack used to execute the pipeline. |
required |
environment
|
Dict[str, str]
|
Runtime environment for the orchestration sandbox. |
required |
placeholder_run
|
Optional[PipelineRunResponse]
|
Optional pre-created pipeline run. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[SubmissionResult]
|
Submission metadata and an optional completion callback. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the snapshot contains a schedule. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
submit_isolated_step(step_run_info: StepRunInfo, environment: Dict[str, str]) -> None
Submit a dynamic isolated step sandbox to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run_info
|
StepRunInfo
|
Information about the isolated step run. |
required |
environment
|
Dict[str, str]
|
Runtime environment for the step sandbox. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If sandbox metadata cannot be published after the sandbox is created. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
submit_pipeline(snapshot: PipelineSnapshotResponse, stack: Stack, base_environment: Dict[str, str], step_environments: Dict[str, Dict[str, str]], placeholder_run: Optional[PipelineRunResponse] = None) -> Optional[SubmissionResult]
Submit a static pipeline controller sandbox to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotResponse
|
Static pipeline snapshot to submit. |
required |
stack
|
Stack
|
Stack used to execute the pipeline. |
required |
base_environment
|
Dict[str, str]
|
Environment shared by the controller sandbox. |
required |
step_environments
|
Dict[str, Dict[str, str]]
|
Per-step environments, recomputed by the controller inside Modal. |
required |
placeholder_run
|
Optional[PipelineRunResponse]
|
Optional pre-created pipeline run. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[SubmissionResult]
|
Submission metadata and an optional completion callback. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the snapshot contains a schedule. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
terminate_sandbox_if_running(*, sandbox_id: str, description: str) -> None
Terminate a running Modal sandbox for an orchestrator entrypoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox_id
|
str
|
ID of the Modal sandbox. |
required |
description
|
str
|
Human-readable sandbox description for logs. |
required |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
Modules
modal_orchestrator
Modal orchestrator implementation.
ModalOrchestrator(*args: Any, **kwargs: Any)
Bases: ContainerizedOrchestrator
Orchestrator that runs ZenML pipelines in Modal Sandboxes.
Initialize the Modal orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to the base orchestrator. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to the base orchestrator. |
{}
|
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
149 150 151 152 153 154 155 156 157 158 | |
config: ModalOrchestratorConfig
property
Get the Modal orchestrator configuration.
settings_class: Optional[Type[BaseSettings]]
property
Get the settings class for the Modal orchestrator.
supported_execution_modes: List[ExecutionMode]
property
Get the execution modes supported by the Modal orchestrator.
validator: Optional[StackValidator]
property
Validate that the active stack can run in remote Modal Sandboxes.
create_static_step_sandbox(*, snapshot: PipelineSnapshotResponse, step_name: str, environment: Dict[str, str]) -> modal.Sandbox
Create a child sandbox for a static pipeline step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotResponse
|
Static pipeline snapshot containing the step. |
required |
step_name
|
str
|
Name of the step to execute. |
required |
environment
|
Dict[str, str]
|
Runtime environment for the step sandbox. |
required |
Returns:
| Type | Description |
|---|---|
Sandbox
|
The created Modal step sandbox. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | |
fetch_status(run: PipelineRunResponse, include_steps: bool = False) -> Tuple[Optional[ExecutionStatus], Optional[Dict[str, ExecutionStatus]]]
Fetch Modal sandbox status for a pipeline run and its steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
PipelineRunResponse
|
Pipeline run backed by Modal sandboxes. |
required |
include_steps
|
bool
|
Whether to fetch statuses for child step sandboxes. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[Optional[ExecutionStatus], Optional[Dict[str, ExecutionStatus]]]
|
The pipeline sandbox status and optional step sandbox statuses. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
get_isolated_step_status(step_run: StepRunResponse) -> ExecutionStatus
Get the status of a dynamic isolated step sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
Isolated step run backed by the sandbox. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionStatus
|
The current sandbox execution status. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
get_modal_client() -> Optional[modal.Client]
Get the Modal client used by orchestrator entrypoints.
Returns:
| Type | Description |
|---|---|
Optional[Client]
|
A reusable Modal client, or |
Optional[Client]
|
not configured. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
get_orchestrator_run_id() -> str
Return the stable Modal run ID from the sandbox environment.
Returns:
| Type | Description |
|---|---|
str
|
The stable Modal orchestration run ID. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the Modal run ID environment variable is absent. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
get_pipeline_run_metadata(run_id: UUID) -> Dict[str, MetadataType]
Get run metadata from the Modal sandbox environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
UUID
|
ID of the pipeline run being described. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, MetadataType]
|
Run metadata containing Modal orchestration identifiers. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | |
get_step_sandbox_metadata(settings: ModalOrchestratorSettings, sandbox_id: str) -> Dict[str, MetadataType]
staticmethod
Build step sandbox metadata for orchestrator entrypoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ModalOrchestratorSettings
|
Modal settings used to create the sandbox. |
required |
sandbox_id
|
str
|
ID of the Modal step sandbox. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, MetadataType]
|
Run metadata describing the step sandbox. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
stop_isolated_step(step_run: StepRunResponse) -> None
Stop a dynamic isolated step sandbox if it is still running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
Isolated step run backed by the sandbox. |
required |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
submit_dynamic_pipeline(snapshot: PipelineSnapshotResponse, stack: Stack, environment: Dict[str, str], placeholder_run: Optional[PipelineRunResponse] = None) -> Optional[SubmissionResult]
Submit a dynamic pipeline orchestration sandbox to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotResponse
|
Dynamic pipeline snapshot to submit. |
required |
stack
|
Stack
|
Stack used to execute the pipeline. |
required |
environment
|
Dict[str, str]
|
Runtime environment for the orchestration sandbox. |
required |
placeholder_run
|
Optional[PipelineRunResponse]
|
Optional pre-created pipeline run. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[SubmissionResult]
|
Submission metadata and an optional completion callback. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the snapshot contains a schedule. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
submit_isolated_step(step_run_info: StepRunInfo, environment: Dict[str, str]) -> None
Submit a dynamic isolated step sandbox to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run_info
|
StepRunInfo
|
Information about the isolated step run. |
required |
environment
|
Dict[str, str]
|
Runtime environment for the step sandbox. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If sandbox metadata cannot be published after the sandbox is created. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
submit_pipeline(snapshot: PipelineSnapshotResponse, stack: Stack, base_environment: Dict[str, str], step_environments: Dict[str, Dict[str, str]], placeholder_run: Optional[PipelineRunResponse] = None) -> Optional[SubmissionResult]
Submit a static pipeline controller sandbox to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotResponse
|
Static pipeline snapshot to submit. |
required |
stack
|
Stack
|
Stack used to execute the pipeline. |
required |
base_environment
|
Dict[str, str]
|
Environment shared by the controller sandbox. |
required |
step_environments
|
Dict[str, Dict[str, str]]
|
Per-step environments, recomputed by the controller inside Modal. |
required |
placeholder_run
|
Optional[PipelineRunResponse]
|
Optional pre-created pipeline run. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[SubmissionResult]
|
Submission metadata and an optional completion callback. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the snapshot contains a schedule. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
terminate_sandbox_if_running(*, sandbox_id: str, description: str) -> None
Terminate a running Modal sandbox for an orchestrator entrypoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox_id
|
str
|
ID of the Modal sandbox. |
required |
description
|
str
|
Human-readable sandbox description for logs. |
required |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
get_modal_app_name(modal_run_id: str) -> str
Build the deterministic Modal app name for a ZenML run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modal_run_id
|
str
|
Stable ID of the Modal orchestration run. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The length-limited Modal app name. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
81 82 83 84 85 86 87 88 89 90 | |
get_static_step_sandbox_metadata_key(step_name: str) -> str
Build an append-safe run metadata key for a static child sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_name
|
str
|
Name of the static pipeline step. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The run metadata key for the step's sandbox ID. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
134 135 136 137 138 139 140 141 142 143 | |
modal_orchestrator_entrypoint
Static Modal orchestration entrypoint.
ModalOrchestratorEntrypointConfiguration(arguments: List[str])
Bases: BaseEntrypointConfiguration
Entrypoint configuration for the static Modal controller sandbox.
Source code in src/zenml/entrypoints/base_entrypoint_configuration.py
61 62 63 64 65 66 67 68 | |
get_entrypoint_arguments(**kwargs: Any) -> List[str]
classmethod
Get command arguments for the static Modal controller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Entrypoint option values. |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
Command-line arguments for the controller entrypoint. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator_entrypoint.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
get_entrypoint_options() -> Dict[str, bool]
classmethod
Get options required by the static Modal controller.
Returns:
| Type | Description |
|---|---|
Dict[str, bool]
|
Entrypoint option names and whether they are required. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator_entrypoint.py
409 410 411 412 413 414 415 416 | |
run() -> None
Start child Modal sandboxes for all steps in a static pipeline.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the active orchestrator is not a Modal orchestrator or a child step sandbox fails. |
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator_entrypoint.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
sandbox_utils
Shared Modal Sandbox helpers.
Classes
ModalSandboxSettings
Bases: Protocol
Fields shared by Modal component settings that describe a sandbox.
cloud: Optional[str]
property
Cloud provider for the sandbox, if any.
gpu: Optional[str]
property
GPU type requested for the sandbox, if any.
region: Optional[str]
property
Cloud region for the sandbox, if any.
timeout: int
property
Maximum sandbox lifetime in seconds.
Functions:
build_sandbox_create_kwargs(*, app: modal.App, image: modal.Image, settings: ModalSandboxSettings, resource_settings: ResourceSettings, environment: Dict[str, str], modal_client: Optional[modal.Client], gpu_settings_field: str = DEFAULT_GPU_SETTINGS_FIELD, gpu_settings_example: str = DEFAULT_GPU_SETTINGS_EXAMPLE) -> Dict[str, Any]
Build keyword arguments for modal.Sandbox.create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
App
|
Modal app that owns the sandbox. |
required |
image
|
Image
|
Modal image used by the sandbox. |
required |
settings
|
ModalSandboxSettings
|
Modal component sandbox settings. |
required |
resource_settings
|
ResourceSettings
|
ZenML resource constraints. |
required |
environment
|
Dict[str, str]
|
Runtime environment variables. |
required |
modal_client
|
Optional[Client]
|
Optional explicit Modal client. |
required |
gpu_settings_field
|
str
|
Settings field name used in GPU errors. |
DEFAULT_GPU_SETTINGS_FIELD
|
gpu_settings_example
|
str
|
Example configuration used in GPU errors. |
DEFAULT_GPU_SETTINGS_EXAMPLE
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Keyword arguments for creating the Modal sandbox. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
create_modal_client_from_credentials(*, token_id: Optional[str], token_secret: Optional[str]) -> Optional[modal.Client]
Create an explicit Modal client from component credentials.
If no component credentials are configured, this returns None so the
Modal SDK can use its ambient authentication configuration. If only one
credential value is configured, the component configuration is invalid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_id
|
Optional[str]
|
Explicitly configured Modal token ID, if any. |
required |
token_secret
|
Optional[str]
|
Explicitly configured Modal token secret, if any. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Client]
|
An authenticated Modal client, or |
Raises:
| Type | Description |
|---|---|
StackComponentInterfaceError
|
If only one credential value is configured. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
create_modal_sandbox(entrypoint_command: List[str], *, app: modal.App, image: modal.Image, settings: ModalSandboxSettings, resource_settings: ResourceSettings, environment: Dict[str, str], modal_client: Optional[modal.Client], gpu_settings_field: str = DEFAULT_GPU_SETTINGS_FIELD, gpu_settings_example: str = DEFAULT_GPU_SETTINGS_EXAMPLE) -> modal.Sandbox
Create a Modal sandbox for a ZenML entrypoint command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entrypoint_command
|
List[str]
|
Command to run inside the sandbox. |
required |
app
|
App
|
Modal app that owns the sandbox. |
required |
image
|
Image
|
Modal image used by the sandbox. |
required |
settings
|
ModalSandboxSettings
|
Modal component sandbox settings. |
required |
resource_settings
|
ResourceSettings
|
ZenML resource constraints. |
required |
environment
|
Dict[str, str]
|
Runtime environment variables. |
required |
modal_client
|
Optional[Client]
|
Optional explicit Modal client. |
required |
gpu_settings_field
|
str
|
Settings field name used in GPU errors. |
DEFAULT_GPU_SETTINGS_FIELD
|
gpu_settings_example
|
str
|
Example configuration used in GPU errors. |
DEFAULT_GPU_SETTINGS_EXAMPLE
|
Returns:
| Type | Description |
|---|---|
Sandbox
|
The created Modal sandbox. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
create_runtime_secrets(sensitive_environment: Dict[str, Optional[str]]) -> List[modal.Secret]
Create Modal secrets for sensitive runtime environment values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensitive_environment
|
Dict[str, Optional[str]]
|
Sensitive environment values to store. |
required |
Returns:
| Type | Description |
|---|---|
List[Secret]
|
Modal secrets containing the sensitive values. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
get_gpu_values(settings: ModalSandboxSettings, resource_settings: ResourceSettings, *, gpu_settings_field: str = DEFAULT_GPU_SETTINGS_FIELD, gpu_settings_example: str = DEFAULT_GPU_SETTINGS_EXAMPLE) -> Optional[str]
Compute and validate the Modal gpu argument string.
Modal expects GPU resources as either None (CPU only), a GPU type string
like "A100" (implicitly a single GPU), or "A100:2" when multiple
GPUs of the same type are requested. Within ZenML, the GPU type is captured
in Modal component settings while the count lives in
:class:~zenml.config.resource_settings.ResourceSettings. This helper
reconciles both sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
ModalSandboxSettings
|
Modal component settings describing the GPU type. |
required |
resource_settings
|
ResourceSettings
|
Resource constraints providing the GPU count. |
required |
gpu_settings_field
|
str
|
Settings field name to mention in GPU errors. |
DEFAULT_GPU_SETTINGS_FIELD
|
gpu_settings_example
|
str
|
Example configuration to mention in GPU errors. |
DEFAULT_GPU_SETTINGS_EXAMPLE
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
A Modal-compatible GPU specification string or |
Optional[str]
|
CPU. |
Raises:
| Type | Description |
|---|---|
StackComponentInterfaceError
|
If the configuration is inconsistent or invalid. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
get_memory_mb(resource_settings: ResourceSettings) -> Optional[int]
Convert ZenML memory resource settings to Modal MiB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_settings
|
ResourceSettings
|
ZenML resource constraints. |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
The requested memory rounded up to MiB, or |
Source code in src/zenml/integrations/modal/sandbox_utils.py
312 313 314 315 316 317 318 319 320 321 322 | |
get_modal_image_from_registry(image_name: str, registry_credentials: Optional[Tuple[str, str]] = None) -> modal.Image
Create a Modal image from a registry image name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name
|
str
|
Registry image name. |
required |
registry_credentials
|
Optional[Tuple[str, str]]
|
Optional registry username and password. |
None
|
Returns:
| Type | Description |
|---|---|
Image
|
A Modal image backed by the registry image. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
get_sandbox_by_id(sandbox_id: str, *, modal_client: Optional[modal.Client]) -> modal.Sandbox
Reconstruct a Modal sandbox handle by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox_id
|
str
|
ID of the Modal sandbox. |
required |
modal_client
|
Optional[Client]
|
Optional explicit Modal client. |
required |
Returns:
| Type | Description |
|---|---|
Sandbox
|
The reconstructed Modal sandbox handle. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
get_sandbox_status(sandbox_id: str, *, modal_client: Optional[modal.Client]) -> ExecutionStatus
Get the ZenML execution status for a Modal sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox_id
|
str
|
ID of the Modal sandbox. |
required |
modal_client
|
Optional[Client]
|
Optional explicit Modal client. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionStatus
|
The current ZenML execution status. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
lookup_modal_app(app_name: str, *, modal_environment: Optional[str], modal_client: Optional[modal.Client]) -> modal.App
Look up or create a Modal app for sandbox execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Name of the Modal app. |
required |
modal_environment
|
Optional[str]
|
Optional Modal environment name. |
required |
modal_client
|
Optional[Client]
|
Optional explicit Modal client. |
required |
Returns:
| Type | Description |
|---|---|
App
|
The existing or newly created Modal app. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
normalize_optional_config_value(value: Optional[str]) -> Optional[str]
Normalize an optional string configuration value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Optional[str]
|
The optional value to normalize. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The stripped value, or |
Source code in src/zenml/integrations/modal/sandbox_utils.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
resolve_modal_token_pair(*, token_id: Optional[str], token_secret: Optional[str]) -> Optional[Tuple[str, str]]
Resolve the Modal token pair to forward into a sandbox.
The explicitly configured component token is preferred. When it is absent,
this falls back to Modal's ambient authentication config (~/.modal.toml
or the MODAL_TOKEN_ID / MODAL_TOKEN_SECRET environment variables),
the same source Modal's SDK uses when no explicit client is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_id
|
Optional[str]
|
Explicitly configured Modal token ID, if any. |
required |
token_secret
|
Optional[str]
|
Explicitly configured Modal token secret, if any. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Tuple[str, str]]
|
The resolved |
Optional[Tuple[str, str]]
|
credentials can be resolved from either source. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
sandbox_status_from_return_code(return_code: Optional[int]) -> ExecutionStatus
Map a Modal sandbox return code to a ZenML execution status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
return_code
|
Optional[int]
|
Modal sandbox return code, if the sandbox has finished. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionStatus
|
The corresponding ZenML execution status. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
split_modal_runtime_environment(environment: Dict[str, str]) -> Tuple[Dict[str, str], Dict[str, Optional[str]]]
Split runtime environment variables into plain and secret values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environment
|
Dict[str, str]
|
Runtime environment variables to split. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Dict[str, str], Dict[str, Optional[str]]]
|
The plain environment variables and sensitive environment variables. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
terminate_sandbox(sandbox_id: str, *, modal_client: Optional[modal.Client]) -> None
Terminate a Modal sandbox by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox_id
|
str
|
ID of the Modal sandbox. |
required |
modal_client
|
Optional[Client]
|
Optional explicit Modal client. |
required |
Source code in src/zenml/integrations/modal/sandbox_utils.py
509 510 511 512 513 514 515 516 517 518 519 520 521 | |
wait_for_sandbox(sandbox: modal.Sandbox, poll_interval: float = 1.0) -> int
Wait for a Modal sandbox by polling its return code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox
|
Sandbox
|
Modal sandbox to wait for. |
required |
poll_interval
|
float
|
Delay between status polls in seconds. |
1.0
|
Returns:
| Type | Description |
|---|---|
int
|
The sandbox return code. |
Source code in src/zenml/integrations/modal/sandbox_utils.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
sandboxes
Modal sandbox implementation.
Classes
ModalSandbox(*args: Any, **kwargs: Any)
Bases: BaseSandbox
Sandbox flavor backed by Modal.
Initialize the Modal sandbox component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Forwarded to |
()
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
config: ModalSandboxConfig
property
settings_class: Optional[Type[BaseSettings]]
property
attach(session_id: str) -> SandboxSession
Reconnect to a still-live Modal Sandbox by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The Modal sandbox object id (e.g. |
required |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Modal can't find a sandbox with the given id, or the sandbox has already terminated. |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
Boot a fresh Modal Sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional per-step overrides for image / env. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
restore(snapshot: SandboxSnapshot) -> SandboxSession
Boot a new Session from a stored filesystem snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
SandboxSnapshot
|
A |
required |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A new |
SandboxSession
|
in-memory state from the original Session is preserved. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Modal can't load the Image (e.g. id GC'd). |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
ModalSandboxProcess(process: ContainerProcess[str], *, session: ModalSandboxSession, started_at: float)
Bases: SandboxProcess
Wraps a Modal ContainerProcess in the SandboxProcess interface.
Initialize the process wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
ContainerProcess[str]
|
The Modal |
required |
session
|
ModalSandboxSession
|
Owning session — stdout/stderr lines forward through
|
required |
started_at
|
float
|
Wall-clock launch time, used by |
required |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
exit_code: Optional[int]
property
Exit code, or None if the command is still running.
Uses poll() instead of returncode: Modal's
ContainerProcess.returncode raises InvalidError while the
command is still running, whereas this property promises None.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
The exit code or |
kill() -> None
Killing a single command is not supported on Modal.
Modal's ContainerProcess exposes no per-command termination
(only poll/wait/stdin/stdout/stderr), and
tearing down the whole Sandbox to stop one command would also stop
every other command in the session. Rather than that surprising
side effect, per-command kill is unsupported; call
session.destroy() to stop the entire sandbox.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always — the Modal SDK has no per-command kill. |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
stderr() -> Iterator[str]
Returns a line-buffered, log-wrapped stderr iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Line iterator wrapped via |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
92 93 94 95 96 97 98 99 100 | |
stdout() -> Iterator[str]
Returns a line-buffered, log-wrapped stdout iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Line iterator wrapped via |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
82 83 84 85 86 87 88 89 90 | |
wait(timeout: Optional[float] = None) -> int
Blocks until the command exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional[float]
|
Maximum seconds to wait. Modal's own |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The exit code. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the command is still running after |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
ModalSandboxSession(sandbox: modal.Sandbox, *, parent: ModalSandbox, destroy_on_exit: bool = False)
Bases: SandboxSession
Wraps a Modal Sandbox in the SandboxSession interface.
Initialize the session wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox
|
Sandbox
|
The live Modal |
required |
parent
|
ModalSandbox
|
The owning Modal sandbox component. |
required |
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
Modules
modal_sandbox
Modal sandbox flavor implementation.
ModalSandbox(*args: Any, **kwargs: Any)
Bases: BaseSandbox
Sandbox flavor backed by Modal.
Initialize the Modal sandbox component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Forwarded to |
()
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
config: ModalSandboxConfig
property
settings_class: Optional[Type[BaseSettings]]
property
attach(session_id: str) -> SandboxSession
Reconnect to a still-live Modal Sandbox by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The Modal sandbox object id (e.g. |
required |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Modal can't find a sandbox with the given id, or the sandbox has already terminated. |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
Boot a fresh Modal Sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional per-step overrides for image / env. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
restore(snapshot: SandboxSnapshot) -> SandboxSession
Boot a new Session from a stored filesystem snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
SandboxSnapshot
|
A |
required |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A new |
SandboxSession
|
in-memory state from the original Session is preserved. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If Modal can't load the Image (e.g. id GC'd). |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
ModalSandboxProcess(process: ContainerProcess[str], *, session: ModalSandboxSession, started_at: float)
Bases: SandboxProcess
Wraps a Modal ContainerProcess in the SandboxProcess interface.
Initialize the process wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
ContainerProcess[str]
|
The Modal |
required |
session
|
ModalSandboxSession
|
Owning session — stdout/stderr lines forward through
|
required |
started_at
|
float
|
Wall-clock launch time, used by |
required |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
exit_code: Optional[int]
property
Exit code, or None if the command is still running.
Uses poll() instead of returncode: Modal's
ContainerProcess.returncode raises InvalidError while the
command is still running, whereas this property promises None.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
The exit code or |
kill() -> None
Killing a single command is not supported on Modal.
Modal's ContainerProcess exposes no per-command termination
(only poll/wait/stdin/stdout/stderr), and
tearing down the whole Sandbox to stop one command would also stop
every other command in the session. Rather than that surprising
side effect, per-command kill is unsupported; call
session.destroy() to stop the entire sandbox.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always — the Modal SDK has no per-command kill. |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
stderr() -> Iterator[str]
Returns a line-buffered, log-wrapped stderr iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Line iterator wrapped via |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
92 93 94 95 96 97 98 99 100 | |
stdout() -> Iterator[str]
Returns a line-buffered, log-wrapped stdout iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Line iterator wrapped via |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
82 83 84 85 86 87 88 89 90 | |
wait(timeout: Optional[float] = None) -> int
Blocks until the command exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional[float]
|
Maximum seconds to wait. Modal's own |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The exit code. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the command is still running after |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
ModalSandboxSession(sandbox: modal.Sandbox, *, parent: ModalSandbox, destroy_on_exit: bool = False)
Bases: SandboxSession
Wraps a Modal Sandbox in the SandboxSession interface.
Initialize the session wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sandbox
|
Sandbox
|
The live Modal |
required |
parent
|
ModalSandbox
|
The owning Modal sandbox component. |
required |
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
utils
Sandbox-process helpers (line buffering for SandboxProcess IO).
line_buffer(chunks: Iterable[Optional[Union[bytes, str]]]) -> Iterator[str]
Re-emit byte/str chunks one decoded line at a time.
Modal returns LogsReader iterables that yield byte chunks, not lines,
so callers line-buffer on this side to match the line-delimited
SandboxProcess.stdout() / stderr() contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
Iterable[Optional[Union[bytes, str]]]
|
Source iterable yielding bytes, str, or None. |
required |
Yields:
| Type | Description |
|---|---|
str
|
Lines with trailing newline when present; a final newline-less |
str
|
remainder is yielded once the source is exhausted. |
Source code in src/zenml/integrations/modal/sandboxes/utils.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
step_operators
Modal step operator.
Classes
ModalStepOperator(*args: Any, **kwargs: Any)
Bases: BaseStepOperator
Step operator to run a step on Modal.
This class defines code that can set up a Modal environment and run functions in it.
Initialize the Modal step operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to the base step operator. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to the base step operator. |
{}
|
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
53 54 55 56 57 58 59 60 61 62 | |
config: ModalStepOperatorConfig
property
Get the Modal step operator configuration.
Returns:
| Type | Description |
|---|---|
ModalStepOperatorConfig
|
The Modal step operator configuration. |
settings_class: Optional[Type[BaseSettings]]
property
Get the settings class for the Modal step operator.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSettings]]
|
The Modal step operator settings class. |
validator: Optional[StackValidator]
property
Get the stack validator for the Modal step operator.
Returns:
| Type | Description |
|---|---|
Optional[StackValidator]
|
The stack validator. |
cancel(step_run: StepRunResponse) -> None
Cancels a submitted Modal sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
The step run. |
required |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
271 272 273 274 275 276 277 278 279 | |
get_docker_builds(snapshot: PipelineSnapshotBase) -> List[BuildConfiguration]
Get the Docker build configurations for the Modal step operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotBase
|
The pipeline snapshot. |
required |
Returns:
| Type | Description |
|---|---|
List[BuildConfiguration]
|
A list of Docker build configurations. |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
get_status(step_run: StepRunResponse) -> ExecutionStatus
Gets the status of a submitted Modal sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
The step run. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionStatus
|
The step status. |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
submit(info: StepRunInfo, entrypoint_command: List[str], environment: Dict[str, str]) -> None
Submits a step run to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
StepRunInfo
|
The step run information. |
required |
entrypoint_command
|
List[str]
|
The entrypoint command for the step. |
required |
environment
|
Dict[str, str]
|
The environment variables for the step. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no container registry is found in the stack or the entrypoint command is empty. |
Exception
|
If sandbox metadata publication or local metadata update fails after sandbox creation. In this case, the sandbox is terminated before re-raising the original exception. |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
Modules
modal_step_operator
Modal step operator implementation.
ModalStepOperator(*args: Any, **kwargs: Any)
Bases: BaseStepOperator
Step operator to run a step on Modal.
This class defines code that can set up a Modal environment and run functions in it.
Initialize the Modal step operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to the base step operator. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to the base step operator. |
{}
|
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
53 54 55 56 57 58 59 60 61 62 | |
config: ModalStepOperatorConfig
property
Get the Modal step operator configuration.
Returns:
| Type | Description |
|---|---|
ModalStepOperatorConfig
|
The Modal step operator configuration. |
settings_class: Optional[Type[BaseSettings]]
property
Get the settings class for the Modal step operator.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSettings]]
|
The Modal step operator settings class. |
validator: Optional[StackValidator]
property
Get the stack validator for the Modal step operator.
Returns:
| Type | Description |
|---|---|
Optional[StackValidator]
|
The stack validator. |
cancel(step_run: StepRunResponse) -> None
Cancels a submitted Modal sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
The step run. |
required |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
271 272 273 274 275 276 277 278 279 | |
get_docker_builds(snapshot: PipelineSnapshotBase) -> List[BuildConfiguration]
Get the Docker build configurations for the Modal step operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
PipelineSnapshotBase
|
The pipeline snapshot. |
required |
Returns:
| Type | Description |
|---|---|
List[BuildConfiguration]
|
A list of Docker build configurations. |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
get_status(step_run: StepRunResponse) -> ExecutionStatus
Gets the status of a submitted Modal sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_run
|
StepRunResponse
|
The step run. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionStatus
|
The step status. |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
submit(info: StepRunInfo, entrypoint_command: List[str], environment: Dict[str, str]) -> None
Submits a step run to Modal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
StepRunInfo
|
The step run information. |
required |
entrypoint_command
|
List[str]
|
The entrypoint command for the step. |
required |
environment
|
Dict[str, str]
|
The environment variables for the step. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no container registry is found in the stack or the entrypoint command is empty. |
Exception
|
If sandbox metadata publication or local metadata update fails after sandbox creation. In this case, the sandbox is terminated before re-raising the original exception. |
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |