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

All python function tasks can now be dynamic #320

Merged
merged 8 commits into from
Jan 14, 2021
Merged

Conversation

katrogan
Copy link
Contributor

@katrogan katrogan commented Jan 8, 2021

No description provided.

@katrogan
Copy link
Contributor Author

@kumare3 @wild-endeavor mind reviewing? I'd like to leave dynamic tasks as a separate mixin because of the way they overwrite the execute method

@katrogan
Copy link
Contributor Author

ping @kumare3

@kumare3
Copy link
Contributor

kumare3 commented Jan 12, 2021

@katrogan after thinking a little more, I feel we can covert the dynamic logic to be a boolean switch in the base task. this way, truly all tasks can by dynamic without extension. Thus if you use the @dynamic decorator - then, the boolean switch is automatically turned on and hence, a dynamic futures file is always expcted? WDYT?

@katrogan
Copy link
Contributor Author

@kumare3 I like it! i will update this PR

@katrogan
Copy link
Contributor Author

PTAL @kumare3 @wild-endeavor not really sure if it's worth keeping the dynamic code as a mixing separate from PythonFunctionTask but the latter is quite clean/simple as is

tested on my local flyte sandbox with dynamic sidecar and vanilla dynamic tasks

@katrogan katrogan changed the title Dynamic pod task and dynamic task mixin All python function tasks can now be dynamic Jan 12, 2021
)
) as ctx:
with ctx.new_execution_context(mode=ExecutionState.Mode.TASK_EXECUTION) as ctx:
dynamic_job_spec = dynamic_pod_task.compile_into_workflow(ctx, dynamic_pod_task._task_function, a=5)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there anything else here worth checking for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wrt the dynamic mixin? i used the existing dynamic unit test as a model which only verifies this

@wild-endeavor
Copy link
Contributor

we can always decide in the future about the mixin status.

return self._task_function(**kwargs)
if self.execution_mode == self.ExecutionMode.DEFAULT:
return self._task_function(**kwargs)
elif self.execution_mode == self.ExecutionMode.DYNAMIC:
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a new execution mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh yes. should i call it something else?

from flytekit.models import literals as _literal_models


class DynamicWorkflowTaskMixin(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

why keep this separate? Whats the use of a mixin? We will never use it elsewhere right?

Copy link
Contributor

Choose a reason for hiding this comment

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

if you want you can just make these has helper methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, see my comment above I wasn't sure whether it was cleaner to leave PythonFunctionTask as is given it's so simple. I'll fold this in.

@@ -167,9 +174,17 @@ def __init__(
**kwargs,
)
self._task_function = task_function
self._execution_mode = execution_mode if execution_mode is not None else self.ExecutionMode.DEFAULT
Copy link
Contributor

Choose a reason for hiding this comment

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

this has been bugging me to. Can we just start with an ExecutionMode always set to something like DEFAULT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@katrogan
Copy link
Contributor Author

ping @kumare3

self._wf.compile(**kwargs)

wf = self._wf
sdk_workflow = wf.get_registerable_entity()
Copy link
Contributor

Choose a reason for hiding this comment

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

this might impact what @wild-endeavor is doing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will wait and rebase after his change is in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

talked offline, i'll merge this as is

if self.execution_mode == self.ExecutionBehavior.DEFAULT:
return self._task_function(**kwargs)
elif self.execution_mode == self.ExecutionBehavior.DYNAMIC:
return self.dynamic_execute(self._task_function, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

ohh this is interesting. This will break for cases in which execute is overriden right? Which happens quite a few times? Are we sure this is the best place to do it?

Copy link
Contributor

Choose a reason for hiding this comment

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

so the contract is that execute is overridable. but dispatch_execute should not be overriden

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess now that I have added pre-execute and post-execute, we can document that execute should not be overriden in most cases unless absolutely required and in that case, unless you replicate the dynamic execute call, ability to dynamically execute will be lost! I am ok with that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so the contract is that execute is overridable. but dispatch_execute should not be overriden

yes precisely. added documentation that execute can be overwritten if dynamic execute is handled too

@katrogan katrogan merged commit 531c059 into annotations Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants