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

Move SageMakerEndpointMetadata to agent.py #2310

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion flytekit/core/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def __init__(
self,
task_type: str,
name: str,
task_config: Optional[T],
task_config: Optional[T] = None,
interface: Optional[Interface] = None,
environment: Optional[Dict[str, str]] = None,
disable_deck: Optional[bool] = None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import json
from dataclasses import dataclass
from datetime import datetime
from typing import Optional
from typing import Any, Dict, Optional

import cloudpickle

from flytekit.extend.backend.base_agent import (
AgentRegistry,
AsyncAgentBase,
Resource,
ResourceMeta,
)
from flytekit.extend.backend.utils import convert_to_flyte_phase
from flytekit.models.literals import LiteralMap
from flytekit.models.task import TaskTemplate

from .boto3_mixin import Boto3AgentMixin
from .task import SageMakerEndpointMetadata


@dataclass
class SageMakerEndpointMetadata(ResourceMeta):
config: Dict[str, Any]
region: Optional[str] = None
inputs: Optional[LiteralMap] = None

def encode(self) -> bytes:
return cloudpickle.dumps(self)

Check warning on line 28 in plugins/flytekit-aws-sagemaker/flytekitplugins/awssagemaker_inference/agent.py

View check run for this annotation

Codecov / codecov/patch

plugins/flytekit-aws-sagemaker/flytekitplugins/awssagemaker_inference/agent.py#L28

Added line #L28 was not covered by tests

@classmethod
def decode(cls, data: bytes) -> "SageMakerEndpointMetadata":
return cloudpickle.loads(data)

Check warning on line 32 in plugins/flytekit-aws-sagemaker/flytekitplugins/awssagemaker_inference/agent.py

View check run for this annotation

Codecov / codecov/patch

plugins/flytekit-aws-sagemaker/flytekitplugins/awssagemaker_inference/agent.py#L32

Added line #L32 was not covered by tests


states = {
"Creating": "Running",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from dataclasses import dataclass
from typing import Any, Dict, Optional, Type, Union

from flytekit import ImageSpec, kwtypes
from flytekit.configuration import SerializationSettings
from flytekit.core.base_task import PythonTask
from flytekit.core.interface import Interface
from flytekit.extend.backend.base_agent import AsyncAgentExecutorMixin
from flytekit.models.literals import LiteralMap

from .boto3_task import BotoConfig, BotoTask

Expand Down Expand Up @@ -75,14 +73,7 @@ def __init__(
)


@dataclass
class SageMakerEndpointMetadata(object):
config: Dict[str, Any]
region: Optional[str] = None
inputs: Optional[LiteralMap] = None


class SageMakerEndpointTask(AsyncAgentExecutorMixin, PythonTask[SageMakerEndpointMetadata]):
class SageMakerEndpointTask(AsyncAgentExecutorMixin, PythonTask):
_TASK_TYPE = "sagemaker-endpoint"

def __init__(
Expand All @@ -103,17 +94,15 @@ def __init__(
"""
super().__init__(
name=name,
task_config=SageMakerEndpointMetadata(
config=config,
region=region,
),
task_type=self._TASK_TYPE,
interface=Interface(inputs=inputs, outputs=kwtypes(result=str)),
**kwargs,
)
self._config = config
self._region = region

def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]:
return {"config": self.task_config.config, "region": self.task_config.region}
return {"config": self._config, "region": self._region}


class SageMakerDeleteEndpointTask(BotoTask):
Expand Down
Loading