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 | |
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
219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
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
234 235 236 237 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 | |
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
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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
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, 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.
validate_modal_token_pair() -> ModalOrchestratorConfig
Validate that Modal token fields are configured together.
Source code in src/zenml/integrations/modal/flavors/modal_orchestrator_flavor.py
83 84 85 86 87 88 89 90 91 92 93 94 | |
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: BaseSettings
Settings for Modal sandboxes created by the orchestrator.
These settings can apply to the sandbox that controls the run and to child sandboxes that execute individual steps.
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, ModalSandboxSettings, ModalStepOperatorConfig
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 | |
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, ModalStepOperatorSettings
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, ModalStepOperatorSettings
Configuration for the Modal step operator.
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. |
Note: If token_id and token_secret are provided, both fields must be set. If they are not provided, Modal falls back to its default authentication (~/.modal.toml or environment variables). All other configuration options (modal_environment, gpu, region, etc.) are inherited from ModalStepOperatorSettings.
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. |
validate_modal_token_pair() -> ModalStepOperatorConfig
Validate that Modal token fields are configured together.
Source code in src/zenml/integrations/modal/flavors/modal_step_operator_flavor.py
110 111 112 113 114 115 116 117 118 119 120 121 | |
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: BaseSettings
Settings for the Modal step operator.
Specifying the region and cloud provider is only available for Enterprise and Team plan customers.
Certain combinations of settings are not available. It is suggested to err on the side of looser settings rather than more restrictive ones to avoid pipeline execution failures. In the case of failures, however, Modal provides detailed error messages that can help identify what is incompatible. See more in the Modal docs at https://modal.com/docs/guide/region-selection.
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_orchestrator_flavor
Modal orchestrator flavor.
ModalOrchestratorConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseOrchestratorConfig, 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.
validate_modal_token_pair() -> ModalOrchestratorConfig
Validate that Modal token fields are configured together.
Source code in src/zenml/integrations/modal/flavors/modal_orchestrator_flavor.py
83 84 85 86 87 88 89 90 91 92 93 94 | |
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: BaseSettings
Settings for Modal sandboxes created by the orchestrator.
These settings can apply to the sandbox that controls the run and to child sandboxes that execute individual steps.
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, ModalSandboxSettings, ModalStepOperatorConfig
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 | |
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, ModalStepOperatorSettings
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, ModalStepOperatorSettings
Configuration for the Modal step operator.
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. |
Note: If token_id and token_secret are provided, both fields must be set. If they are not provided, Modal falls back to its default authentication (~/.modal.toml or environment variables). All other configuration options (modal_environment, gpu, region, etc.) are inherited from ModalStepOperatorSettings.
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. |
validate_modal_token_pair() -> ModalStepOperatorConfig
Validate that Modal token fields are configured together.
Source code in src/zenml/integrations/modal/flavors/modal_step_operator_flavor.py
110 111 112 113 114 115 116 117 118 119 120 121 | |
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: BaseSettings
Settings for the Modal step operator.
Specifying the region and cloud provider is only available for Enterprise and Team plan customers.
Certain combinations of settings are not available. It is suggested to err on the side of looser settings rather than more restrictive ones to avoid pipeline execution failures. In the case of failures, however, Modal provides detailed error messages that can help identify what is incompatible. See more in the Modal docs at https://modal.com/docs/guide/region-selection.
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
119 120 121 122 123 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
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 499 500 501 502 503 504 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | |
get_isolated_step_status(step_run: StepRunResponse) -> ExecutionStatus
Get the status of a dynamic isolated step sandbox.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
get_modal_client() -> Optional[modal.Client]
Get the Modal client used by orchestrator entrypoints.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
get_orchestrator_run_id() -> str
Return the stable Modal run ID from the sandbox environment.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
245 246 247 248 249 250 251 252 253 | |
get_pipeline_run_metadata(run_id: UUID) -> Dict[str, MetadataType]
Get run metadata from the Modal sandbox environment.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
842 843 844 845 846 847 848 849 850 851 | |
get_step_sandbox_metadata(settings: ModalOrchestratorSettings, sandbox_id: str) -> Dict[str, MetadataType]
staticmethod
Build step sandbox metadata for orchestrator entrypoints.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
stop_isolated_step(step_run: StepRunResponse) -> None
Stop a dynamic isolated step sandbox if it is still running.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
submit_isolated_step(step_run_info: StepRunInfo, environment: Dict[str, str]) -> None
Submit a dynamic isolated step sandbox to Modal.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
428 429 430 431 432 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 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
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 | |
terminate_sandbox_if_running(*, sandbox_id: str, description: str) -> None
Terminate a running Modal sandbox for an orchestrator entrypoint.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
119 120 121 122 123 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
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 499 500 501 502 503 504 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | |
get_isolated_step_status(step_run: StepRunResponse) -> ExecutionStatus
Get the status of a dynamic isolated step sandbox.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
get_modal_client() -> Optional[modal.Client]
Get the Modal client used by orchestrator entrypoints.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
get_orchestrator_run_id() -> str
Return the stable Modal run ID from the sandbox environment.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
245 246 247 248 249 250 251 252 253 | |
get_pipeline_run_metadata(run_id: UUID) -> Dict[str, MetadataType]
Get run metadata from the Modal sandbox environment.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
842 843 844 845 846 847 848 849 850 851 | |
get_step_sandbox_metadata(settings: ModalOrchestratorSettings, sandbox_id: str) -> Dict[str, MetadataType]
staticmethod
Build step sandbox metadata for orchestrator entrypoints.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
stop_isolated_step(step_run: StepRunResponse) -> None
Stop a dynamic isolated step sandbox if it is still running.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
submit_isolated_step(step_run_info: StepRunInfo, environment: Dict[str, str]) -> None
Submit a dynamic isolated step sandbox to Modal.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
428 429 430 431 432 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 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
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 | |
terminate_sandbox_if_running(*, sandbox_id: str, description: str) -> None
Terminate a running Modal sandbox for an orchestrator entrypoint.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
get_modal_app_name(modal_run_id: str) -> str
Build the deterministic Modal app name for a ZenML run.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
81 82 83 | |
get_static_step_sandbox_metadata_key(step_name: str) -> str
Build an append-safe run metadata key for a static child sandbox.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator.py
111 112 113 | |
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.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator_entrypoint.py
380 381 382 383 384 385 386 | |
get_entrypoint_options() -> Dict[str, bool]
classmethod
Get options required by the static Modal controller.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator_entrypoint.py
375 376 377 378 | |
run() -> None
Start child Modal sandboxes for all steps in a static pipeline.
Source code in src/zenml/integrations/modal/orchestrators/modal_orchestrator_entrypoint.py
388 389 390 391 392 393 394 395 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 435 436 | |
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.
Source code in src/zenml/integrations/modal/sandbox_utils.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
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.
Source code in src/zenml/integrations/modal/sandbox_utils.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 | |
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.
Source code in src/zenml/integrations/modal/sandbox_utils.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
create_runtime_secrets(sensitive_environment: Dict[str, Optional[str]]) -> List[modal.Secret]
Create Modal secrets for sensitive runtime environment values.
Source code in src/zenml/integrations/modal/sandbox_utils.py
277 278 279 280 281 282 283 284 | |
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
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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
get_memory_mb(resource_settings: ResourceSettings) -> Optional[int]
Convert ZenML memory resource settings to Modal MiB.
Source code in src/zenml/integrations/modal/sandbox_utils.py
271 272 273 274 | |
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.
Source code in src/zenml/integrations/modal/sandbox_utils.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
get_sandbox_by_id(sandbox_id: str, *, modal_client: Optional[modal.Client]) -> modal.Sandbox
Reconstruct a Modal sandbox handle by ID.
Source code in src/zenml/integrations/modal/sandbox_utils.py
375 376 377 378 379 380 381 | |
get_sandbox_status(sandbox_id: str, *, modal_client: Optional[modal.Client]) -> ExecutionStatus
Get the ZenML execution status for a Modal sandbox.
Source code in src/zenml/integrations/modal/sandbox_utils.py
384 385 386 387 388 389 390 391 | |
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.
Source code in src/zenml/integrations/modal/sandbox_utils.py
198 199 200 201 202 203 204 205 206 207 208 209 210 | |
normalize_optional_config_value(value: Optional[str]) -> Optional[str]
Normalize optional string config values.
Source code in src/zenml/integrations/modal/sandbox_utils.py
77 78 79 80 81 82 83 | |
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
130 131 132 133 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 174 175 176 177 | |
sandbox_status_from_return_code(return_code: Optional[int]) -> ExecutionStatus
Map a Modal sandbox return code to a ZenML execution status.
Source code in src/zenml/integrations/modal/sandbox_utils.py
364 365 366 367 368 369 370 371 372 | |
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.
Source code in src/zenml/integrations/modal/sandbox_utils.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
terminate_sandbox(sandbox_id: str, *, modal_client: Optional[modal.Client]) -> None
Terminate a Modal sandbox by ID.
Source code in src/zenml/integrations/modal/sandbox_utils.py
394 395 396 397 398 399 400 401 | |
wait_for_sandbox(sandbox: modal.Sandbox, poll_interval: float = 1.0) -> int
Wait for a Modal sandbox by polling its return code.
Source code in src/zenml/integrations/modal/sandbox_utils.py
353 354 355 356 357 358 359 360 361 | |
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
296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
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
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 | |
create_session(settings: Optional[BaseSandboxSettings] = None) -> SandboxSession
Boot a fresh Modal Sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional per-step overrides for image / env. |
None
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
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
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
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)
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 |
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 | |
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
296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
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
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 | |
create_session(settings: Optional[BaseSandboxSettings] = None) -> SandboxSession
Boot a fresh Modal Sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional per-step overrides for image / env. |
None
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A |
Source code in src/zenml/integrations/modal/sandboxes/modal_sandbox.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
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
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
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)
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 |
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 | |
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.
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
53 54 55 56 57 | |
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
261 262 263 264 265 266 267 268 269 | |
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
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
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
246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
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
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 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 | |
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.
Source code in src/zenml/integrations/modal/step_operators/modal_step_operator.py
53 54 55 56 57 | |
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
261 262 263 264 265 266 267 268 269 | |
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
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
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
246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
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
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 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 | |