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

Run command in pyflyte-fast-execute in the same process #3029

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

thomasjpfan
Copy link
Member

@thomasjpfan thomasjpfan commented Jan 3, 2025

Why are the changes needed?

With this PR, pyflyte-fast-execute does not run the command in another process, which saves ~7 seconds.

What changes were proposed in this pull request?

With this PR, pyflyte-fast-execute will run pyflyte-map-execute and pyflyte-execute in the same process, which improves startup time. There is a FLYTE_FAST_EXECUTE_CMD_IN_NEW_PROCESS env var that triggers the previous behavior.

How was this patch tested?

I ran:

from flytekit import task


@task(container_image="localhost:30000/flytekit:0.1.3")
def hello(name: str) -> str:
    return f"Hello! {name}"

With pyflyte run --remote wf.py hello --name flyte, it took 8s:

SCR-20250103-nocr

With pyflyte run --remote --env FLYTE_FAST_EXECUTE_CMD_IN_NEW_PROCESS=1 wf.py hello --name flyte, which took 15 s:

SCR-20250103-noxh

Summary by Bito

This PR includes multiple changes: (1) pyflyte-fast-execute optimization with in-process command execution for ~7 second startup time gains, (2) new Environment class for task configurations, (3) VLLM integration and Optuna plugin, (4) improved package management with uv.lock and poetry.lock support, and (5) dependency updates including jinja2 upgrade to 3.1.5 and modified version constraints for grpcio packages.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 5

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 3, 2025

Code Review Agent Run #ff52b8

Actionable Suggestions - 3
  • flytekit/bin/entrypoint.py - 3
Review Details
  • Files reviewed - 2 · Commit Range: c8a5915..c8a5915
    • flytekit/bin/entrypoint.py
    • flytekit/core/constants.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 3, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Optimize Command Execution in pyflyte-fast-execute

entrypoint.py - Added in-process command execution capability with fallback to subprocess

constants.py - Added new environment variable for controlling process execution mode

test_remote.py - Added tests for new in-process execution functionality


command(args)


Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding error handling for Popen

Consider adding error handling around subprocess.Popen() call to catch potential OSError or ValueError exceptions that could occur during process creation.

Code suggestion
Check the AI-generated fix before applying
Suggested change
try:
p = subprocess.Popen(cmd, env=env)
except (OSError, ValueError) as e:
logger.error(f"Failed to start subprocess: {e}")
exit(1)

Code Review Run #ff52b8


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@@ -742,24 +773,16 @@ def fast_execute_task_cmd(additional_distribution: str, dest_dir: str, task_exec
cmd.extend(["--dynamic-addl-distro", additional_distribution, "--dynamic-dest-dir", dest_dir])
cmd.append(arg)

commands_to_run_in_process = {cmd.name: cmd for cmd in [map_execute_task_cmd, execute_task_cmd]}
Copy link
Contributor

@flyte-bot flyte-bot Jan 3, 2025

Choose a reason for hiding this comment

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

Consider moving static dict to module level

Consider moving the commands_to_run_in_process dictionary definition outside the function to avoid recreating it on every call. This dictionary is static and could be defined at module level.

Code suggestion
Check the AI-generated fix before applying
 @@ -1,1 +1,3 @@
 +_commands_to_run_in_process = {cmd.name: cmd for cmd in [map_execute_task_cmd, execute_task_cmd]}
 +
  def fast_execute_task_cmd(additional_distribution: str, dest_dir: str, task_execute_cmd: List[str]):
 @@ -776,1 +778,0 @@
 -    commands_to_run_in_process = {cmd.name: cmd for cmd in [map_execute_task_cmd, execute_task_cmd]}

Code Review Run #ff52b8


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.58%. Comparing base (dfa8f04) to head (1fe153b).

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3029       +/-   ##
===========================================
+ Coverage   47.23%   79.58%   +32.34%     
===========================================
  Files         202      202               
  Lines       21355    21356        +1     
  Branches     2744     2744               
===========================================
+ Hits        10088    16996     +6908     
+ Misses      10776     3593     -7183     
- Partials      491      767      +276     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 3, 2025

Code Review Agent Run #33c19c

Actionable Suggestions - 1
  • flytekit/bin/entrypoint.py - 1
Review Details
  • Files reviewed - 1 · Commit Range: c8a5915..00abba6
    • flytekit/bin/entrypoint.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@@ -23,6 +23,9 @@
# Set this environment variable to true to force the task to return non-zero exit code on failure.
FLYTE_FAIL_ON_ERROR = "FLYTE_FAIL_ON_ERROR"

# Set this environment variable to true to force pyflyte-fast-execute to run task-execute-cmd in a separate process
FLYTE_FAST_EXECUTE_CMD_IN_NEW_PROCESS = "FLYTE_FAST_EXECUTE_CMD_IN_NEW_PROCESS"

Copy link
Member

Choose a reason for hiding this comment

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

Could we run a workflow in the integration tests with FLYTE_FAST_EXECUTE_CMD_IN_NEW_PROCESS enabled? Just want to make sure the old behavior is still working.

…r_flyte_fast_execute

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 9, 2025

Code Review Agent Run #cfcbee

Actionable Suggestions - 0
Additional Suggestions - 10
  • plugins/flytekit-spark/tests/test_environment.py - 1
    • Consider parameterizing Spark app name assertion · Line 17-19
  • tests/flytekit/integration/remote/utils.py - 1
    • Consider making parquet file path configurable · Line 89-89
  • plugins/flytekit-optuna/setup.py - 1
    • Consider adding Python 3.11 support · Line 21-21
  • tests/flytekit/unit/core/test_workflows.py - 1
    • Consider expanding workflow lhs test coverage · Line 360-363
  • tests/flytekit/integration/remote/test_remote.py - 2
    • Consider adding type hints for parameters · Line 68-68
    • Consider configurable timeout for execution wait · Line 873-873
  • plugins/flytekit-inference/tests/test_vllm.py - 1
    • Consider breaking down long assertion statement · Line 41-41
  • plugins/flytekit-inference/flytekitplugins/inference/vllm/serve.py - 1
    • Consider consolidating hf_secret validation checks · Line 44-47
  • flytekit/image_spec/default_builder.py - 1
  • tests/flytekit/unit/core/image_spec/test_default_builder.py - 1
    • Consider using complete error message pattern · Line 271-271
Review Details
  • Files reviewed - 26 · Commit Range: 00abba6..eda9c8c
    • flytekit/__init__.py
    • flytekit/core/array_node_map_task.py
    • flytekit/core/environment.py
    • flytekit/core/workflow.py
    • flytekit/image_spec/default_builder.py
    • flytekit/remote/remote.py
    • flytekit/types/directory/types.py
    • flytekit/types/file/file.py
    • plugins/flytekit-inference/flytekitplugins/inference/__init__.py
    • plugins/flytekit-inference/flytekitplugins/inference/vllm/serve.py
    • plugins/flytekit-inference/setup.py
    • plugins/flytekit-inference/tests/test_vllm.py
    • plugins/flytekit-optuna/flytekitplugins/optuna/__init__.py
    • plugins/flytekit-optuna/flytekitplugins/optuna/optimizer.py
    • plugins/flytekit-optuna/setup.py
    • plugins/flytekit-optuna/tests/test_optimizer.py
    • plugins/flytekit-spark/tests/test_environment.py
    • pyproject.toml
    • tests/flytekit/integration/remote/test_remote.py
    • tests/flytekit/integration/remote/utils.py
    • tests/flytekit/integration/remote/workflows/basic/attr_access_sd.py
    • tests/flytekit/unit/core/image_spec/test_default_builder.py
    • tests/flytekit/unit/core/test_environment.py
    • tests/flytekit/unit/core/test_flyte_directory.py
    • tests/flytekit/unit/core/test_flyte_file.py
    • tests/flytekit/unit/core/test_workflows.py
  • Files skipped - 3
    • .github/workflows/pythonbuild.yml - Reason: Filter setting
    • plugins/flytekit-inference/README.md - Reason: Filter setting
    • plugins/flytekit-optuna/README.md - Reason: Filter setting
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 9, 2025

Code Review Agent Run #53b9a2

Actionable Suggestions - 1
  • tests/flytekit/integration/remote/test_remote.py - 1
    • Parameter reordering may break API compatibility · Line 68-68
Review Details
  • Files reviewed - 1 · Commit Range: eda9c8c..b3b54a9
    • tests/flytekit/integration/remote/test_remote.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

…r_flyte_fast_execute

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 10, 2025

Code Review Agent Run #52ec9b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: b3b54a9..1fe153b
    • plugins/flytekit-onnx-pytorch/dev-requirements.txt
    • pyproject.toml
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

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