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

[flyte-core] Flyte Connection #2297

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

[flyte-core] Flyte Connection #2297

wants to merge 27 commits into from

Conversation

pingsutw
Copy link
Member

@pingsutw pingsutw commented Mar 26, 2024

Tracking issue

flyteorg/flyte#3936

Why are the changes needed?

it will allow users to pass different API_KEY to the chatGPT agent from flytepropeller

What changes were proposed in this pull request?

  • Add List[Secret] to the create/get/delete/executeSync request
  • Read the secret in the base agent

How was this patch tested?

local/remote

Setup process

from flytekit import workflow, Secret
from flytekitplugins.chatgpt import ChatGPTTask

chatgpt_small_job = ChatGPTTask(
    name="3.5-turbo",
    openai_organization="org-P2rdnZQry4Fw7Ak3vSpXEIrx",
    openai_key=Secret("openai", "kevin"),
    chatgpt_config={
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
    },
)


@workflow
def my_chatgpt_job(message: str) -> str:
    message = chatgpt_small_job(message=message)
    return message
import datetime
import random
from operator import add

from click.testing import CliRunner

import flytekit
from flytekit import Resources, Secret, task, workflow, ImageSpec
from flytekit.clis.sdk_in_container import pyflyte
from flytekitplugins.spark import Databricks

image = ImageSpec(base_image="flyteorg/flytekit:spark-latest", registry="pingsutw")


@task(
    task_config=Databricks(
        # this configuration is applied to the spark cluster
        spark_conf={
            "spark.driver.memory": "600M",
            "spark.executor.memory": "600M",
            "spark.executor.cores": "1",
            "spark.executor.instances": "1",
            "spark.driver.cores": "1",
        },
        executor_path="/databricks/python3/bin/python",
        applications_path="dbfs:///FileStore/tables/entrypoint.py",
        databricks_conf={
            "run_name": "flytekit databricks plugin example",
            "job_id": "{{inputs.cluster_id}}",
            "new_cluster": {
                "spark_version": "13.3.x-scala2.12",
                "node_type_id": "m6i.large",  # TODO: test m6i.large, i3.xlarge
                "num_workers": 3,
                "aws_attributes": {
                    "availability": "SPOT_WITH_FALLBACK",
                    "instance_profile_arn": "arn:aws:iam::546011168256:instance-profile/databricks-demo",
                    "ebs_volume_type": "GENERAL_PURPOSE_SSD",
                    "ebs_volume_count": 1,
                    "ebs_volume_size": 100,
                    "first_on_demand": 1,
                },
                "policy_id": "0000FF579DC57A49"
            },
            # "existing_cluster_id": "1122-085119-brus1mft",
            "timeout_seconds": 3600,
            "max_retries": 1,
        },
        databricks_instance="dbc-429786b4-2d97.cloud.databricks.com",
    ),
    limits=Resources(mem="2000M"),
    container_image="pingsutw/databricks:v12",
    secret_requests=[Secret("databricks", "kevin")],
)
def hello_spark(partitions: int) -> float:
    print("Starting Spark with Partitions: {}".format(partitions))

    n = 100000 * partitions
    sess = flytekit.current_context().spark_session
    count = (
        sess.sparkContext.parallelize(range(1, n + 1), partitions).map(f).reduce(add)
    )
    pi_val = 4.0 * count / n
    print("Pi val is :{}".format(pi_val))
    return pi_val


def f(_):
    x = random.random() * 2 - 1
    y = random.random() * 2 - 1
    return 1 if x ** 2 + y ** 2 <= 1 else 0


@task(cache_version="1")
def print_every_time(value_to_print: float, date_triggered: datetime.datetime) -> int:
    print("My printed value: {} @ {}".format(value_to_print, date_triggered))
    return 1


@workflow
def wf(
        triggered_date: datetime.datetime = datetime.datetime.now(),
) -> float:
    """
    Using the workflow is still as any other workflow. As image is a pr1operty of the task, the workflow does not care
    about how the image is configured.1
    """
    pi = hello_spark(partitions=50).with_overrides(name="bad cluster")
    print_every_time(value_to_print=pi, date_triggered=triggered_date)
    return pi

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

NA

Docs link

NA

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 26, 2024
@pingsutw pingsutw marked this pull request as draft March 26, 2024 21:35
Signed-off-by: Kevin Su <[email protected]>
@Future-Outlier
Copy link
Member

Love it, will take a look

Signed-off-by: Kevin Su <[email protected]>
Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

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

Works well to me in local.
image

Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

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

I've failed in remote execution, but I think the reason is that I need more settings to let propeller can get my secret, right?
(which means kubectl create secret generic openai-remote\ --from-literal=hanru=xxx will not work in this case.

image

@pingsutw pingsutw changed the title [WIP] Add secrets to the agent interface Add secrets to the agent interface Apr 4, 2024
@pingsutw pingsutw marked this pull request as ready for review April 4, 2024 21:52
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 4, 2024
@Future-Outlier
Copy link
Member

Coming, will do it today

@kumare3
Copy link
Contributor

kumare3 commented Apr 16, 2024

Looks nice, cc @EngHabu one comment.

Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
@samhita-alla samhita-alla mentioned this pull request Apr 23, 2024
5 tasks
@pingsutw pingsutw changed the title Add secrets to the agent interface [flyte-core] Flyte Connection May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants