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

Modal Step Operator #2948

Open
wants to merge 48 commits into
base: develop
Choose a base branch
from
Open

Modal Step Operator #2948

wants to merge 48 commits into from

Conversation

strickvl
Copy link
Contributor

@strickvl strickvl commented Aug 25, 2024

Seeking an earlyish review before I write the docs (in case anything major changes). This probably isn't the most elegant way of doing this, but it works at least. It supports both CPU and GPU-based workloads, and specifying CPU and memory for the instance on which the step will run.

See Demo tenant for the run details. Screenshot from Modal dashboard:

CleanShot 2024-08-25 at 17 18 35@2x

A simple dev pipeline to test this:

from pathlib import Path

import zenml
from zenml import pipeline, step
from zenml.config import DockerSettings
from zenml.integrations.modal.flavors.modal_step_operator_flavor import (
    ModalStepOperatorSettings,
)

zenml_git_root = Path(zenml.__file__).parents[2]

docker_settings = DockerSettings(
    dockerfile=str(zenml_git_root / "docker" / "zenml-dev.Dockerfile"),
    build_context_root=str(zenml_git_root),
    python_package_installer="uv",
)

modal_settings = ModalStepOperatorSettings(gpu="H100")


@step
def hello_world() -> int:
    print("Hello world!")
    return 3


@step(
    step_operator="modal",
    settings={"step_operator.modal": modal_settings},
)
def hello_world_on_modal(some_number: int) -> int:
    manipulated_number = some_number * 3
    print(f"Hello I'm inside a container! {manipulated_number}")
    return manipulated_number


@step
def final_step(some_manipulated_number: int) -> None:
    print(f"Final number: {some_manipulated_number}")


@pipeline(settings={"docker": docker_settings}, enable_cache=False)
def hello_world_pipeline():
    some_val = hello_world()
    manipulated_number = hello_world_on_modal(some_val)
    final_step(manipulated_number)


if __name__ == "__main__":
    hello_world_pipeline()

Remaining tasks

  • Write docs
  • Update integrations page

Summary by CodeRabbit

  • New Features

    • Introduced Modal integration for ZenML, enabling cloud-native step execution.
    • Added new modules and functionality related to modal operations.
    • Enhanced configuration and operational settings for Modal step operators.
  • Bug Fixes

    • Improved error handling for Docker credentials and Modal application exits.
  • Documentation

    • Updated documentation to reflect new Modal integration capabilities.
@strickvl strickvl added enhancement New feature or request internal To filter out internal PRs and issues labels Aug 25, 2024
Copy link
Contributor

coderabbitai bot commented Aug 25, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The changes introduce a new integration for the Modal platform within the ZenML framework. This includes the addition of several modules and classes that facilitate the configuration and execution of tasks on Modal's infrastructure. Key components include the ModalIntegration, constants for the integration, and specific step operators designed to interact with Modal's capabilities. The overall structure of the existing files is preserved while enhancing integration options.

Changes

Files Change Summary
docs/mocked_libs.json Added entries for "modal", "modal.cli", and "modal.cli.run" to the array of module imports.
src/zenml/integrations/__init__.py Imported ModalIntegration from zenml.integrations.modal.
src/zenml/integrations/constants.py Introduced a new constant MODAL with the value "modal".
src/zenml/integrations/modal/__init__.py Created ModalIntegration class for Modal integration, including flavors method.
src/zenml/integrations/modal/flavors/__init__.py Introduced modal integration flavors and specified the public interface.
src/zenml/integrations/modal/flavors/modal_step_operator_flavor.py Defined ModalStepOperatorSettings, ModalStepOperatorConfig, and ModalStepOperatorFlavor classes.
src/zenml/integrations/modal/step_operators/__init__.py Created module for modal step operators, exposing ModalStepOperator.
src/zenml/integrations/modal/step_operators/modal_step_operator.py Implemented ModalStepOperator class for executing steps on Modal.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZenML
    participant ModalIntegration
    participant Modal

    User->>ZenML: Initiates workflow with Modal integration
    ZenML->>ModalIntegration: Configures integration settings
    ModalIntegration->>Modal: Validates required settings
    Modal->>ZenML: Returns configuration status
    ZenML->>User: Workflow execution begins
    ZenML->>Modal: Launches step on Modal
    Modal-->>ZenML: Executes step and returns results
    ZenML->>User: Delivers results of the workflow
Loading

Poem

🐇 In the garden of code, a new path we tread,
With Modal's embrace, our workflows are spread.
Hopping through steps, with joy and delight,
Each task on the cloud, a marvelous sight!
So let’s dance with the data, in harmony play,
For the magic of Modal is here to stay! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.
@strickvl
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 26, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

coderabbitai bot commented Aug 26, 2024

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

Commits

Files that changed from the base of the PR and between 647ac95 and c3173a3.

Files selected for processing (8)
  • docs/mocked_libs.json (1 hunks)
  • src/zenml/integrations/init.py (1 hunks)
  • src/zenml/integrations/constants.py (1 hunks)
  • src/zenml/integrations/modal/init.py (1 hunks)
  • src/zenml/integrations/modal/flavors/init.py (1 hunks)
  • src/zenml/integrations/modal/flavors/modal_step_operator_flavor.py (1 hunks)
  • src/zenml/integrations/modal/step_operators/init.py (1 hunks)
  • src/zenml/integrations/modal/step_operators/modal_step_operator.py (1 hunks)
_______________________________________________
< Optimization hinders evolution. - Alan Perlis >
-----------------------------------------------
 \
  \   (\__/)
      (•ㅅ•)
      /   づ

Tip

You can disable poems in the walkthrough.

Disable the reviews.poem setting in your project's settings in CodeRabbit to remove poems from the walkthrough.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
src/zenml/integrations/modal/step_operators/modal_step_operator.py (1)

112-208: Consider adding more comments for clarity.

The launch method is detailed and includes error handling, but additional comments could improve readability and maintainability.

Consider adding comments to explain the purpose of each major block of code within the method.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 647ac95 and c3173a3.

Files selected for processing (8)
  • docs/mocked_libs.json (1 hunks)
  • src/zenml/integrations/init.py (1 hunks)
  • src/zenml/integrations/constants.py (1 hunks)
  • src/zenml/integrations/modal/init.py (1 hunks)
  • src/zenml/integrations/modal/flavors/init.py (1 hunks)
  • src/zenml/integrations/modal/flavors/modal_step_operator_flavor.py (1 hunks)
  • src/zenml/integrations/modal/step_operators/init.py (1 hunks)
  • src/zenml/integrations/modal/step_operators/modal_step_operator.py (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/zenml/integrations/constants.py
  • src/zenml/integrations/modal/step_operators/init.py
Additional context used
Path-based instructions (5)
src/zenml/integrations/modal/flavors/__init__.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

src/zenml/integrations/modal/__init__.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

src/zenml/integrations/__init__.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

src/zenml/integrations/modal/flavors/modal_step_operator_flavor.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

src/zenml/integrations/modal/step_operators/modal_step_operator.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

Additional comments not posted (12)
src/zenml/integrations/modal/flavors/__init__.py (2)

1-14: LGTM!

The license header and docstring are correctly formatted.

The code changes are approved.


16-26: LGTM!

The import statements and __all__ declaration are correctly implemented.

The code changes are approved.

src/zenml/integrations/modal/__init__.py (4)

1-18: LGTM!

The license header and docstring are correctly formatted.

The code changes are approved.


19-25: LGTM!

The import statements and constant declaration are correctly implemented.

The code changes are approved.


28-43: LGTM!

The class definition and methods are correctly implemented.

The code changes are approved.


46-46: LGTM!

The installation check is correctly implemented.

The code changes are approved.

src/zenml/integrations/__init__.py (1)

49-49: LGTM!

The import statement for ModalIntegration is correctly implemented.

The code changes are approved.

src/zenml/integrations/modal/flavors/modal_step_operator_flavor.py (3)

26-51: LGTM!

The ModalStepOperatorSettings class is well-defined with comprehensive docstrings. The attributes cover essential configurations for the Modal step operator.

The code changes are approved.


54-70: LGTM!

The ModalStepOperatorConfig class is well-structured and the is_remote property is correctly implemented. The docstring provides clear explanations.

The code changes are approved.


73-130: LGTM!

The ModalStepOperatorFlavor class is well-implemented with correctly defined properties and informative docstrings. The class follows Python best practices.

The code changes are approved.

docs/mocked_libs.json (1)

254-257: LGTM!

The additions of modal, modal.cli, and modal.cli.run expand the library's capabilities. The overall structure of the JSON remains unchanged.

The code changes are approved.

src/zenml/integrations/modal/step_operators/modal_step_operator.py (1)

44-49: LGTM!

The ModalStepOperator class is well-implemented with a clear purpose and structure. The docstring provides a good overview.

The code changes are approved.

@schustmi
Copy link
Contributor

Some answers for your general questions/comments:

  • The settings should be visible on the DAG visualizer in the Stack card. Can you point me to a run with some settings so I can verify that it's not showing up.
  • How is the orchestrator url related to this PR? It's just a step operator right, and there is no code in your step operator that would even set this metadata right?

I would suggest the following:

  • We introduce another metadata constant:
    METADATA_STEP_OPERATOR_URL = "step_operator_url"
  • We implement the get_step_run_metadata(...) method in the modal step operator and include the modal URL for the constant above. We can then later expose this on the dashboard and also implement it for other step operators
@strickvl
Copy link
Contributor Author

Some answers for your general questions/comments:

  • The settings should be visible on the DAG visualizer in the Stack card. Can you point me to a run with some settings so I can verify that it's not showing up.
  • How is the orchestrator url related to this PR? It's just a step operator right, and there is no code in your step operator that would even set this metadata right?

I would suggest the following:

  • We introduce another metadata constant:
    METADATA_STEP_OPERATOR_URL = "step_operator_url"
  • We implement the get_step_run_metadata(...) method in the modal step operator and include the modal URL for the constant above. We can then later expose this on the dashboard and also implement it for other step operators

Ah yes you're right. Actually because of the way their CLI works (and the fact that we're now using subprocess), it's even a bit harder to get the URL for the specific run. Since we don't yet have it for other step operators, I think we can just leave it for now maybe.

@strickvl strickvl marked this pull request as ready for review August 28, 2024 14:44
@strickvl strickvl requested review from schustmi, kramstrom and avishniakov and removed request for kramstrom August 28, 2024 14:44
@strickvl strickvl requested a review from schustmi August 29, 2024 06:59
Copy link
Contributor

@avishniakov avishniakov left a comment

Choose a reason for hiding this comment

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

LGTM, just a tiny nit which can be ignored

src/zenml/integrations/modal/__init__.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request internal To filter out internal PRs and issues run-slow-ci
4 participants