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

Sagemaker inference agent #2027

Merged
merged 125 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
f025b8c
[wip] Sagemaker serving agent
kumare3 Dec 7, 2023
5db022a
added sync agent example
kumare3 Dec 11, 2023
deed189
initial version
samhita-alla Dec 28, 2023
56277a6
add deployment workflow
samhita-alla Dec 29, 2023
53b9fce
add a workflow to delete sagemaker deployment
samhita-alla Jan 2, 2024
c64da88
clean up
samhita-alla Jan 2, 2024
e2bbe08
modify dict update logic, create sagemaker deployment tasks
samhita-alla Jan 3, 2024
6e24e75
nit
samhita-alla Jan 3, 2024
1fbdf51
dockerfile and setup changes
samhita-alla Jan 23, 2024
e5392d4
update
samhita-alla Jan 26, 2024
2cfba8a
update
samhita-alla Jan 26, 2024
93eb222
pin aioboto3 version
samhita-alla Jan 26, 2024
34afdaf
remove boto3 directory
samhita-alla Jan 26, 2024
979379a
update imports
samhita-alla Jan 26, 2024
1760ffe
boto3 update code and add tests
samhita-alla Jan 30, 2024
78a2069
remove output type
samhita-alla Jan 30, 2024
dab6780
add await
samhita-alla Jan 30, 2024
36850c3
remove sync
samhita-alla Jan 30, 2024
47f250e
modify imports
samhita-alla Jan 30, 2024
e601af8
modify container logic
samhita-alla Jan 30, 2024
cfccdd0
modify output key
samhita-alla Jan 30, 2024
31500ce
add default container image
samhita-alla Jan 30, 2024
b150887
remove struct
samhita-alla Jan 30, 2024
28c31fa
add region
samhita-alla Jan 30, 2024
568d3fc
add output to gettaskresponse
samhita-alla Jan 30, 2024
06b5002
convert to dict to str
samhita-alla Jan 30, 2024
f5931b7
revert
samhita-alla Jan 30, 2024
9fec7f4
remove timeout and add creds to boto3 calls
samhita-alla Jan 30, 2024
a548fe3
add to_flyte_idl
samhita-alla Jan 30, 2024
d84e467
subclass fix
samhita-alla Jan 30, 2024
97006c4
invoke endpoint async
samhita-alla Jan 31, 2024
ceab2dc
remove output type
samhita-alla Jan 31, 2024
afed76a
modify create sagemaker deployment code
samhita-alla Jan 31, 2024
29f875d
dict loop
samhita-alla Jan 31, 2024
3452ca9
add wf output
samhita-alla Feb 1, 2024
b78b69c
set lhs to an empty string for pythoninstancetask & modify param name…
samhita-alla Feb 3, 2024
6a66480
update tracker and delete deployment workflow
samhita-alla Feb 3, 2024
6f6839f
instance to instancetask
samhita-alla Feb 3, 2024
8625e32
add tests
samhita-alla Feb 20, 2024
4332c8c
resolve merge conflicts
samhita-alla Feb 20, 2024
9f65a99
ruff isort
samhita-alla Feb 20, 2024
0840f51
ruff isort
samhita-alla Feb 20, 2024
e8622ec
isort
samhita-alla Feb 20, 2024
131b488
add test
samhita-alla Feb 20, 2024
7bf91cc
pin greatexpectations version
samhita-alla Feb 20, 2024
0c4390a
update secret name
samhita-alla Feb 20, 2024
eb30a63
add typing dict and update tracker
samhita-alla Feb 20, 2024
236a072
modify tracker test
samhita-alla Feb 20, 2024
8dc4086
add sync agent
samhita-alla Feb 21, 2024
976aa1b
add name
samhita-alla Feb 21, 2024
4127d95
add syncagentexecutormixin
samhita-alla Feb 21, 2024
6c4109b
modify sync output
samhita-alla Feb 21, 2024
692c2b4
metadata to resource_meta
samhita-alla Feb 21, 2024
ba2c16a
remote conversion to flyte idl
samhita-alla Feb 21, 2024
01b41c9
add output type
samhita-alla Feb 21, 2024
2a843ac
floats to ints
samhita-alla Feb 21, 2024
590f59d
in place modification
samhita-alla Feb 21, 2024
8366cf9
chain tasks
samhita-alla Feb 21, 2024
e298f40
great expectations revert
samhita-alla Feb 21, 2024
1d41026
optimize float to int code
samhita-alla Feb 23, 2024
5de9684
snake case
samhita-alla Feb 24, 2024
6990dc4
modify plugin name
samhita-alla Feb 29, 2024
0b15104
modify plugin name
samhita-alla Feb 29, 2024
64ad2e2
modify tracker tests
samhita-alla Feb 29, 2024
327cbdd
fix tests, revert tracker changes and remove pythoninstancetask
samhita-alla Mar 4, 2024
beb758b
tracker changes revert
samhita-alla Mar 4, 2024
783a57d
dict to Dict
samhita-alla Mar 4, 2024
fd2a022
make images optional
samhita-alla Mar 4, 2024
bb0fcaf
add image_name
samhita-alla Mar 4, 2024
2a50c4c
Merge remote-tracking branch 'origin/master' into sagemaker-agent
samhita-alla Mar 5, 2024
3e0a1b0
debug
samhita-alla Mar 5, 2024
0741e5a
debug
samhita-alla Mar 5, 2024
1bf71e8
debug
samhita-alla Mar 5, 2024
492948e
debug
samhita-alla Mar 5, 2024
2bcb9ae
debug
samhita-alla Mar 5, 2024
34e6d42
debug
samhita-alla Mar 5, 2024
6472fd4
debug
samhita-alla Mar 5, 2024
d31a0f6
debug
samhita-alla Mar 5, 2024
0292552
debug
samhita-alla Mar 5, 2024
176eadf
debug
samhita-alla Mar 5, 2024
39a2e87
debug
samhita-alla Mar 5, 2024
4a37026
debug
samhita-alla Mar 5, 2024
dd5af68
debug
samhita-alla Mar 5, 2024
feb3f89
dict to Dict
samhita-alla Mar 5, 2024
bead8a9
state to phase
samhita-alla Mar 5, 2024
1b6a329
add encode mode to secrets.get
samhita-alla Mar 5, 2024
49e68e2
revert: add encode mode to secrets.get
samhita-alla Mar 5, 2024
8c81fe0
add decode
samhita-alla Mar 5, 2024
2844363
revert decode
samhita-alla Mar 6, 2024
2218ed1
ergonomic improvements; change plugin name
samhita-alla Mar 15, 2024
c8b8e38
change plugin name
samhita-alla Mar 15, 2024
1d7821f
nit
samhita-alla Mar 15, 2024
da5b16c
resolve merge conflicts
samhita-alla Mar 15, 2024
fb8f04a
image check
samhita-alla Mar 15, 2024
71c1a4b
add api docs
samhita-alla Mar 15, 2024
aea16de
add api docs
samhita-alla Mar 15, 2024
41f117a
incorporate Kevin's suggestions
samhita-alla Mar 18, 2024
bf593b0
resolve merge conflict
samhita-alla Mar 19, 2024
67fe7f6
handle scenario when the same input is present in the wf already
samhita-alla Mar 20, 2024
e2dd672
add support for region to be a user-provided input at run-time
samhita-alla Mar 20, 2024
eeeab71
modify workflow code to accommodate providing regions at runtime
samhita-alla Mar 20, 2024
6b95417
code optimization and add region support to workflows
samhita-alla Mar 20, 2024
9ef7513
nit
samhita-alla Mar 20, 2024
8f1a2e3
fixed an input_types bug
samhita-alla Mar 20, 2024
346c894
fix images bug
samhita-alla Mar 21, 2024
ef053ca
replace endpoint_name with config
samhita-alla Mar 21, 2024
04fca76
input_region default
samhita-alla Mar 21, 2024
03f4507
add inputs
samhita-alla Mar 21, 2024
9df6cf5
replace bug
samhita-alla Mar 21, 2024
79a1d68
add return type
samhita-alla Mar 21, 2024
5864d96
kwtypes fix bug
samhita-alla Mar 21, 2024
6ed332c
add cache_ignore_input_vars to task template in tests
samhita-alla Mar 21, 2024
b22e8ff
fix test
samhita-alla Mar 21, 2024
85a9c08
fix test
samhita-alla Mar 21, 2024
210516e
Merge remote-tracking branch 'origin/master' into sagemaker-agent
samhita-alla Mar 21, 2024
fda1dd9
add test case for boto3 call method
samhita-alla Mar 21, 2024
191fca3
lint
samhita-alla Mar 21, 2024
0975917
lint
samhita-alla Mar 21, 2024
36f4315
lint
samhita-alla Mar 21, 2024
bef6a4c
lint
samhita-alla Mar 21, 2024
2fecd37
lint
samhita-alla Mar 21, 2024
a833ff1
ruff version
samhita-alla Mar 21, 2024
c7bb5ac
ruff version
samhita-alla Mar 21, 2024
b86b4c2
nit
samhita-alla Mar 22, 2024
5a906a3
docstring update
samhita-alla Mar 22, 2024
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
10 changes: 4 additions & 6 deletions .github/workflows/pythonbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: Build

# Schedule runs to run twice a day


on:
push:
branches:
- master
pull_request:
schedule:
- cron: '0 13 * * *' # This schedule runs at 1pm UTC every day
- cron: "0 13 * * *" # This schedule runs at 1pm UTC every day

env:
FLYTE_SDK_LOGGING_LEVEL: 10 # debug
Expand Down Expand Up @@ -116,9 +115,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
os: [ubuntu-latest]
python-version: ${{fromJson(needs.detect-python-versions.outputs.python-versions)}}
pandas: [ "pandas<2.0.0", "pandas>=2.0.0" ]
pandas: ["pandas<2.0.0", "pandas>=2.0.0"]
steps:
- uses: insightsengineering/disk-space-reclaimer@v1
- uses: actions/checkout@v4
Expand Down Expand Up @@ -257,8 +256,7 @@ jobs:
- flytekit-async-fsspec
- flytekit-aws-athena
- flytekit-aws-batch
# TODO: uncomment this when the sagemaker agent is implemented: https://github.com/flyteorg/flyte/issues/4079
# - flytekit-aws-sagemaker
- flytekit-aws-sagemaker
- flytekit-bigquery
- flytekit-dask
- flytekit-data-fsspec
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.6
rev: v0.2.2
hooks:
# Run the linter.
- id: ruff
args: [--fix, --show-fixes, --show-source]
args: [--fix, --show-fixes, --output-format=full]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.agent
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN pip install --no-cache-dir -U flytekit==$VERSION \
flytekitplugins-bigquery==$VERSION \
flytekitplugins-chatgpt==$VERSION \
flytekitplugins-snowflake==$VERSION \
flytekitplugins-awssagemaker==$VERSION \
&& apt-get clean autoclean \
&& apt-get autoremove --yes \
&& rm -rf /var/lib/{apt,dpkg,cache,log}/ \
Expand Down
17 changes: 0 additions & 17 deletions docs/source/plugins/awssagemaker.rst

This file was deleted.

12 changes: 12 additions & 0 deletions docs/source/plugins/awssagemaker_inference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. _awssagemaker_inference:

#####################################
AWS Sagemaker Inference API reference
#####################################

.. tags:: Integration, MachineLearning, AWS

.. automodule:: flytekitplugins.awssagemaker_inference
:no-members:
:no-inherited-members:
:no-special-members:
2 changes: 2 additions & 0 deletions docs/source/plugins/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Plugin API reference
* :ref:`Vaex <vaex>` - Vaex API reference
* :ref:`MLflow <mlflow>` - MLflow API reference
* :ref:`DuckDB <duckdb>` - DuckDB API reference
* :ref:`SageMaker Inference <awssagemaker_inference>` - SageMaker Inference API reference

.. toctree::
:maxdepth: 2
Expand Down Expand Up @@ -61,3 +62,4 @@ Plugin API reference
Vaex <vaex>
MLflow <mlflow>
DuckDB <duckdb>
SageMaker Inference <awssagemaker_inference>
36 changes: 29 additions & 7 deletions flytekit/core/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@
from abc import abstractmethod
from base64 import b64encode
from dataclasses import dataclass
from typing import Any, Coroutine, Dict, Generic, List, Optional, OrderedDict, Tuple, Type, TypeVar, Union, cast
from typing import (
Any,
Coroutine,
Dict,
Generic,
List,
Optional,
OrderedDict,
Tuple,
Type,
TypeVar,
Union,
cast,
)

from flyteidl.core import artifact_id_pb2 as art_id
from flyteidl.core import tasks_pb2
Expand Down Expand Up @@ -165,9 +178,6 @@ class IgnoreOutputs(Exception):
"""
This exception should be used to indicate that the outputs generated by this can be safely ignored.
This is useful in case of distributed training or peer-to-peer parallel algorithms.

For example look at Sagemaker training, e.g.
:py:class:`plugins.awssagemaker.flytekitplugins.awssagemaker.training.SagemakerBuiltinAlgorithmsTask`.
"""

pass
Expand Down Expand Up @@ -479,7 +489,10 @@ def __init__(
self._task_config = task_config

if disable_deck is not None:
warnings.warn("disable_deck was deprecated in 1.10.0, please use enable_deck instead", FutureWarning)
warnings.warn(
"disable_deck was deprecated in 1.10.0, please use enable_deck instead",
FutureWarning,
)

# Confirm that disable_deck and enable_deck do not contradict each other
if disable_deck is not None and enable_deck is not None:
Expand Down Expand Up @@ -703,7 +716,13 @@ def dispatch_execute(
# If executed inside of a workflow being executed locally, then run the coroutine to get the
# actual results.
return asyncio.run(
self._async_execute(native_inputs, native_outputs, ctx, exec_ctx, new_user_params)
self._async_execute(
native_inputs,
native_outputs,
ctx,
exec_ctx,
new_user_params,
)
)

return self._async_execute(native_inputs, native_outputs, ctx, exec_ctx, new_user_params)
Expand All @@ -716,7 +735,10 @@ def dispatch_execute(
# Short circuit the translation to literal map because what's returned may be a dj spec (or an
# already-constructed LiteralMap if the dynamic task was a no-op), not python native values
# dynamic_execute returns a literal map in local execute so this also gets triggered.
if isinstance(native_outputs, (_literal_models.LiteralMap, _dynamic_job.DynamicJobSpec)):
if isinstance(
native_outputs,
(_literal_models.LiteralMap, _dynamic_job.DynamicJobSpec),
):
return native_outputs

literals_map, native_outputs_as_map = self._output_to_literal_map(native_outputs, exec_ctx)
Expand Down
2 changes: 1 addition & 1 deletion flytekit/core/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def transform_to_comp_expr(expr: ComparisonExpression) -> Tuple[_core_cond.Compa


def transform_to_boolexpr(
expr: Union[ComparisonExpression, ConjunctionExpression]
expr: Union[ComparisonExpression, ConjunctionExpression],
) -> Tuple[_core_cond.BooleanExpression, typing.List[Promise]]:
if isinstance(expr, ConjunctionExpression):
cexpr, promises = transform_to_conj_expr(expr)
Expand Down
41 changes: 34 additions & 7 deletions flytekit/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class TaskPlugins(object):
# Plugin_object_type is a derivative of ``PythonFunctionTask``

Examples of available task plugins include different query-based plugins such as
:py:class:`flytekitplugins.athena.task.AthenaTask` and :py:class:`flytekitplugins.hive.task.HiveTask`, ML tools like
:py:class:`plugins.awssagemaker.flytekitplugins.awssagemaker.training.SagemakerBuiltinAlgorithmsTask`, kubeflow
:py:class:`flytekitplugins.athena.task.AthenaTask` and :py:class:`flytekitplugins.hive.task.HiveTask`, kubeflow
operators like :py:class:`plugins.kfpytorch.flytekitplugins.kfpytorch.task.PyTorchFunctionTask` and
:py:class:`plugins.kftensorflow.flytekitplugins.kftensorflow.task.TensorflowFunctionTask`, and generic plugins like
:py:class:`flytekitplugins.pod.task.PodFunctionTask` which doesn't integrate with third party tools or services.
Expand Down Expand Up @@ -103,7 +102,13 @@ def task(
secret_requests: Optional[List[Secret]] = ...,
execution_mode: PythonFunctionTask.ExecutionBehavior = ...,
node_dependency_hints: Optional[
Iterable[Union[PythonFunctionTask, _annotated_launchplan.LaunchPlan, _annotated_workflow.WorkflowBase]]
Iterable[
Union[
PythonFunctionTask,
_annotated_launchplan.LaunchPlan,
_annotated_workflow.WorkflowBase,
]
]
] = ...,
task_resolver: Optional[TaskResolverMixin] = ...,
docs: Optional[Documentation] = ...,
Expand Down Expand Up @@ -135,7 +140,13 @@ def task(
secret_requests: Optional[List[Secret]] = ...,
execution_mode: PythonFunctionTask.ExecutionBehavior = ...,
node_dependency_hints: Optional[
Iterable[Union[PythonFunctionTask, _annotated_launchplan.LaunchPlan, _annotated_workflow.WorkflowBase]]
Iterable[
Union[
PythonFunctionTask,
_annotated_launchplan.LaunchPlan,
_annotated_workflow.WorkflowBase,
]
]
] = ...,
task_resolver: Optional[TaskResolverMixin] = ...,
docs: Optional[Documentation] = ...,
Expand Down Expand Up @@ -166,7 +177,13 @@ def task(
secret_requests: Optional[List[Secret]] = None,
execution_mode: PythonFunctionTask.ExecutionBehavior = PythonFunctionTask.ExecutionBehavior.DEFAULT,
node_dependency_hints: Optional[
Iterable[Union[PythonFunctionTask, _annotated_launchplan.LaunchPlan, _annotated_workflow.WorkflowBase]]
Iterable[
Union[
PythonFunctionTask,
_annotated_launchplan.LaunchPlan,
_annotated_workflow.WorkflowBase,
]
]
] = None,
task_resolver: Optional[TaskResolverMixin] = None,
docs: Optional[Documentation] = None,
Expand All @@ -175,7 +192,11 @@ def task(
pod_template: Optional["PodTemplate"] = None,
pod_template_name: Optional[str] = None,
accelerator: Optional[BaseAccelerator] = None,
) -> Union[Callable[[Callable[..., FuncOut]], PythonFunctionTask[T]], PythonFunctionTask[T], Callable[..., FuncOut]]:
) -> Union[
Callable[[Callable[..., FuncOut]], PythonFunctionTask[T]],
PythonFunctionTask[T],
Callable[..., FuncOut],
]:
"""
This is the core decorator to use for any task type in flytekit.

Expand Down Expand Up @@ -342,7 +363,13 @@ class ReferenceTask(ReferenceEntity, PythonFunctionTask): # type: ignore
"""

def __init__(
self, project: str, domain: str, name: str, version: str, inputs: Dict[str, type], outputs: Dict[str, Type]
self,
project: str,
domain: str,
name: str,
version: str,
inputs: Dict[str, type],
outputs: Dict[str, Type],
):
super().__init__(TaskReference(project, domain, name, version), inputs, outputs)

Expand Down
Loading
Loading