Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile the workflow only at compile time #1311

Merged
merged 29 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion flytekit/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,10 @@ def wrapper(fn):
default_metadata=workflow_metadata_defaults,
docstring=Docstring(callable_=fn),
)
workflow_instance.compile()

ctx = FlyteContextManager.current_context()
if ctx.execution_state.mode != ctx.execution_state.Mode.TASK_EXECUTION:
Copy link
Member Author

@pingsutw pingsutw Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @kumare3 could we just skip compile in TASK_EXECUTION mode (running the workflow on flyte cluster)?

workflow_instance.compile()
update_wrapper(workflow_instance, fn)
return workflow_instance

Expand Down
18 changes: 17 additions & 1 deletion tests/flytekit/unit/core/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from typing_extensions import Annotated # type: ignore

import flytekit.configuration
from flytekit import StructuredDataset, kwtypes
from flytekit import FlyteContextManager, StructuredDataset, kwtypes
from flytekit.configuration import Image, ImageConfig
from flytekit.core import context_manager
from flytekit.core.condition import conditional
from flytekit.core.task import task
from flytekit.core.workflow import WorkflowFailurePolicy, WorkflowMetadata, WorkflowMetadataDefaults, workflow
Expand Down Expand Up @@ -320,3 +321,18 @@ def test_structured_dataset_wf():
assert_frame_equal(sd_to_schema_wf(), superset_df)
assert_frame_equal(schema_to_sd_wf()[0], subset_df)
assert_frame_equal(schema_to_sd_wf()[1], subset_df)


def test_compile_wf_at_compile_time():
ctx = FlyteContextManager.current_context()
with FlyteContextManager.with_context(
ctx.with_execution_state(
ctx.new_execution_state().with_params(mode=context_manager.ExecutionState.Mode.TASK_EXECUTION)
)
):

@workflow
def wf():
t4()

assert len(wf.nodes) == 0