Skip to content

Commit b7400b6

Browse files
committed
Introduce ModalExecutionMode enum for execution modes
1 parent d8318b1 commit b7400b6

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/zenml/integrations/modal/flavors/modal_orchestrator_flavor.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# permissions and limitations under the License.
1414
"""Modal orchestrator flavor."""
1515

16+
from enum import Enum
1617
from typing import TYPE_CHECKING, Optional, Type
1718

1819
from pydantic import SecretStr
@@ -26,6 +27,18 @@
2627
MODAL_ORCHESTRATOR_FLAVOR = "modal"
2728

2829

30+
class ModalExecutionMode(str, Enum):
31+
"""Execution modes for the Modal orchestrator.
32+
33+
Attributes:
34+
PIPELINE: Execute entire pipeline in one Modal function (fastest, default).
35+
PER_STEP: Execute each step in a separate Modal function (granular control).
36+
"""
37+
38+
PIPELINE = "pipeline"
39+
PER_STEP = "per_step"
40+
41+
2942
class ModalOrchestratorSettings(BaseSettings):
3043
"""Modal orchestrator settings.
3144
@@ -38,7 +51,7 @@ class ModalOrchestratorSettings(BaseSettings):
3851
timeout: Maximum execution time in seconds (default 24h).
3952
min_containers: Minimum containers to keep warm (replaces keep_warm).
4053
max_containers: Maximum concurrent containers (replaces concurrency_limit).
41-
execution_mode: Execution mode - "pipeline" (default, fastest) or "per_step" (granular control).
54+
execution_mode: Execution mode - PIPELINE (default, fastest) or PER_STEP (granular control).
4255
synchronous: Wait for completion (True) or fire-and-forget (False).
4356
app_warming_window_hours: Hours for app name window to enable container reuse.
4457
Apps are reused within this time window for efficiency. Default 2 hours.
@@ -53,7 +66,9 @@ class ModalOrchestratorSettings(BaseSettings):
5366
1 # Keep 1 container warm for sequential execution
5467
)
5568
max_containers: Optional[int] = 10 # Allow up to 10 concurrent containers
56-
execution_mode: str = "pipeline" # Default to fastest mode
69+
execution_mode: ModalExecutionMode = (
70+
ModalExecutionMode.PIPELINE
71+
) # Default to fastest mode
5772
synchronous: bool = (
5873
True # Wait for completion (True) or fire-and-forget (False)
5974
)

src/zenml/integrations/modal/orchestrators/modal_orchestrator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
ModalOrchestratorConfig,
6565
ModalOrchestratorSettings,
6666
)
67+
68+
from zenml.integrations.modal.flavors.modal_orchestrator_flavor import (
69+
ModalExecutionMode,
70+
)
71+
72+
if TYPE_CHECKING:
6773
from zenml.models import PipelineDeploymentResponse, PipelineRunResponse
6874
from zenml.models.v2.core.pipeline_deployment import PipelineDeploymentBase
6975

@@ -335,7 +341,7 @@ def prepare_or_run_pipeline(
335341

336342
# Create the execution function based on execution mode
337343
execution_mode = settings.execution_mode or self.config.execution_mode
338-
if execution_mode == "per_step":
344+
if execution_mode == ModalExecutionMode.PER_STEP:
339345
logger.debug("Creating per-step mode for granular execution")
340346
execution_func: Any = run_step_in_modal
341347
function_name = "run_step_in_modal"
@@ -345,7 +351,7 @@ def prepare_or_run_pipeline(
345351
function_name = "run_entire_pipeline"
346352

347353
# Get or deploy persistent Modal app with warm containers
348-
mode_suffix = execution_mode.replace("_", "-")
354+
mode_suffix = execution_mode.value.replace("_", "-")
349355
app_name_base = f"zenml-{deployment.pipeline_configuration.name.replace('_', '-')}-{mode_suffix}"
350356

351357
execute_step, full_app_name = get_or_deploy_persistent_modal_app(
@@ -406,7 +412,7 @@ def execute_modal_function(
406412
)
407413
return function_call
408414

409-
if execution_mode == "per_step":
415+
if execution_mode == ModalExecutionMode.PER_STEP:
410416
logger.info("Using per-step mode for granular execution")
411417
# Execute steps individually
412418
for step_name in step_names:

0 commit comments

Comments
 (0)