flyte 0.0.1b0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flyte might be problematic. Click here for more details.
- flyte/__init__.py +62 -0
- flyte/_api_commons.py +3 -0
- flyte/_bin/__init__.py +0 -0
- flyte/_bin/runtime.py +126 -0
- flyte/_build.py +25 -0
- flyte/_cache/__init__.py +12 -0
- flyte/_cache/cache.py +146 -0
- flyte/_cache/defaults.py +9 -0
- flyte/_cache/policy_function_body.py +42 -0
- flyte/_cli/__init__.py +0 -0
- flyte/_cli/_common.py +287 -0
- flyte/_cli/_create.py +42 -0
- flyte/_cli/_delete.py +23 -0
- flyte/_cli/_deploy.py +140 -0
- flyte/_cli/_get.py +235 -0
- flyte/_cli/_run.py +152 -0
- flyte/_cli/main.py +72 -0
- flyte/_code_bundle/__init__.py +8 -0
- flyte/_code_bundle/_ignore.py +113 -0
- flyte/_code_bundle/_packaging.py +187 -0
- flyte/_code_bundle/_utils.py +339 -0
- flyte/_code_bundle/bundle.py +178 -0
- flyte/_context.py +146 -0
- flyte/_datastructures.py +342 -0
- flyte/_deploy.py +202 -0
- flyte/_doc.py +29 -0
- flyte/_docstring.py +32 -0
- flyte/_environment.py +43 -0
- flyte/_group.py +31 -0
- flyte/_hash.py +23 -0
- flyte/_image.py +760 -0
- flyte/_initialize.py +634 -0
- flyte/_interface.py +84 -0
- flyte/_internal/__init__.py +3 -0
- flyte/_internal/controllers/__init__.py +115 -0
- flyte/_internal/controllers/_local_controller.py +118 -0
- flyte/_internal/controllers/_trace.py +40 -0
- flyte/_internal/controllers/pbhash.py +39 -0
- flyte/_internal/controllers/remote/__init__.py +40 -0
- flyte/_internal/controllers/remote/_action.py +141 -0
- flyte/_internal/controllers/remote/_client.py +43 -0
- flyte/_internal/controllers/remote/_controller.py +361 -0
- flyte/_internal/controllers/remote/_core.py +402 -0
- flyte/_internal/controllers/remote/_informer.py +361 -0
- flyte/_internal/controllers/remote/_service_protocol.py +50 -0
- flyte/_internal/imagebuild/__init__.py +11 -0
- flyte/_internal/imagebuild/docker_builder.py +416 -0
- flyte/_internal/imagebuild/image_builder.py +241 -0
- flyte/_internal/imagebuild/remote_builder.py +0 -0
- flyte/_internal/resolvers/__init__.py +0 -0
- flyte/_internal/resolvers/_task_module.py +54 -0
- flyte/_internal/resolvers/common.py +31 -0
- flyte/_internal/resolvers/default.py +28 -0
- flyte/_internal/runtime/__init__.py +0 -0
- flyte/_internal/runtime/convert.py +199 -0
- flyte/_internal/runtime/entrypoints.py +135 -0
- flyte/_internal/runtime/io.py +136 -0
- flyte/_internal/runtime/resources_serde.py +138 -0
- flyte/_internal/runtime/task_serde.py +210 -0
- flyte/_internal/runtime/taskrunner.py +190 -0
- flyte/_internal/runtime/types_serde.py +54 -0
- flyte/_logging.py +124 -0
- flyte/_protos/__init__.py +0 -0
- flyte/_protos/common/authorization_pb2.py +66 -0
- flyte/_protos/common/authorization_pb2.pyi +108 -0
- flyte/_protos/common/authorization_pb2_grpc.py +4 -0
- flyte/_protos/common/identifier_pb2.py +71 -0
- flyte/_protos/common/identifier_pb2.pyi +82 -0
- flyte/_protos/common/identifier_pb2_grpc.py +4 -0
- flyte/_protos/common/identity_pb2.py +48 -0
- flyte/_protos/common/identity_pb2.pyi +72 -0
- flyte/_protos/common/identity_pb2_grpc.py +4 -0
- flyte/_protos/common/list_pb2.py +36 -0
- flyte/_protos/common/list_pb2.pyi +69 -0
- flyte/_protos/common/list_pb2_grpc.py +4 -0
- flyte/_protos/common/policy_pb2.py +37 -0
- flyte/_protos/common/policy_pb2.pyi +27 -0
- flyte/_protos/common/policy_pb2_grpc.py +4 -0
- flyte/_protos/common/role_pb2.py +37 -0
- flyte/_protos/common/role_pb2.pyi +53 -0
- flyte/_protos/common/role_pb2_grpc.py +4 -0
- flyte/_protos/common/runtime_version_pb2.py +28 -0
- flyte/_protos/common/runtime_version_pb2.pyi +24 -0
- flyte/_protos/common/runtime_version_pb2_grpc.py +4 -0
- flyte/_protos/logs/dataplane/payload_pb2.py +96 -0
- flyte/_protos/logs/dataplane/payload_pb2.pyi +168 -0
- flyte/_protos/logs/dataplane/payload_pb2_grpc.py +4 -0
- flyte/_protos/secret/definition_pb2.py +49 -0
- flyte/_protos/secret/definition_pb2.pyi +93 -0
- flyte/_protos/secret/definition_pb2_grpc.py +4 -0
- flyte/_protos/secret/payload_pb2.py +62 -0
- flyte/_protos/secret/payload_pb2.pyi +94 -0
- flyte/_protos/secret/payload_pb2_grpc.py +4 -0
- flyte/_protos/secret/secret_pb2.py +38 -0
- flyte/_protos/secret/secret_pb2.pyi +6 -0
- flyte/_protos/secret/secret_pb2_grpc.py +198 -0
- flyte/_protos/secret/secret_pb2_grpc_grpc.py +198 -0
- flyte/_protos/validate/validate/validate_pb2.py +76 -0
- flyte/_protos/workflow/node_execution_service_pb2.py +26 -0
- flyte/_protos/workflow/node_execution_service_pb2.pyi +4 -0
- flyte/_protos/workflow/node_execution_service_pb2_grpc.py +32 -0
- flyte/_protos/workflow/queue_service_pb2.py +106 -0
- flyte/_protos/workflow/queue_service_pb2.pyi +141 -0
- flyte/_protos/workflow/queue_service_pb2_grpc.py +172 -0
- flyte/_protos/workflow/run_definition_pb2.py +128 -0
- flyte/_protos/workflow/run_definition_pb2.pyi +310 -0
- flyte/_protos/workflow/run_definition_pb2_grpc.py +4 -0
- flyte/_protos/workflow/run_logs_service_pb2.py +41 -0
- flyte/_protos/workflow/run_logs_service_pb2.pyi +28 -0
- flyte/_protos/workflow/run_logs_service_pb2_grpc.py +69 -0
- flyte/_protos/workflow/run_service_pb2.py +133 -0
- flyte/_protos/workflow/run_service_pb2.pyi +175 -0
- flyte/_protos/workflow/run_service_pb2_grpc.py +412 -0
- flyte/_protos/workflow/state_service_pb2.py +58 -0
- flyte/_protos/workflow/state_service_pb2.pyi +71 -0
- flyte/_protos/workflow/state_service_pb2_grpc.py +138 -0
- flyte/_protos/workflow/task_definition_pb2.py +72 -0
- flyte/_protos/workflow/task_definition_pb2.pyi +65 -0
- flyte/_protos/workflow/task_definition_pb2_grpc.py +4 -0
- flyte/_protos/workflow/task_service_pb2.py +44 -0
- flyte/_protos/workflow/task_service_pb2.pyi +31 -0
- flyte/_protos/workflow/task_service_pb2_grpc.py +104 -0
- flyte/_resources.py +226 -0
- flyte/_retry.py +32 -0
- flyte/_reusable_environment.py +25 -0
- flyte/_run.py +411 -0
- flyte/_secret.py +61 -0
- flyte/_task.py +367 -0
- flyte/_task_environment.py +200 -0
- flyte/_timeout.py +47 -0
- flyte/_tools.py +27 -0
- flyte/_trace.py +128 -0
- flyte/_utils/__init__.py +20 -0
- flyte/_utils/asyn.py +119 -0
- flyte/_utils/coro_management.py +25 -0
- flyte/_utils/file_handling.py +72 -0
- flyte/_utils/helpers.py +108 -0
- flyte/_utils/lazy_module.py +54 -0
- flyte/_utils/uv_script_parser.py +49 -0
- flyte/_version.py +21 -0
- flyte/connectors/__init__.py +0 -0
- flyte/errors.py +143 -0
- flyte/extras/__init__.py +5 -0
- flyte/extras/_container.py +273 -0
- flyte/io/__init__.py +11 -0
- flyte/io/_dataframe.py +0 -0
- flyte/io/_dir.py +448 -0
- flyte/io/_file.py +468 -0
- flyte/io/pickle/__init__.py +0 -0
- flyte/io/pickle/transformer.py +117 -0
- flyte/io/structured_dataset/__init__.py +129 -0
- flyte/io/structured_dataset/basic_dfs.py +219 -0
- flyte/io/structured_dataset/structured_dataset.py +1061 -0
- flyte/py.typed +0 -0
- flyte/remote/__init__.py +25 -0
- flyte/remote/_client/__init__.py +0 -0
- flyte/remote/_client/_protocols.py +131 -0
- flyte/remote/_client/auth/__init__.py +12 -0
- flyte/remote/_client/auth/_authenticators/__init__.py +0 -0
- flyte/remote/_client/auth/_authenticators/base.py +397 -0
- flyte/remote/_client/auth/_authenticators/client_credentials.py +73 -0
- flyte/remote/_client/auth/_authenticators/device_code.py +118 -0
- flyte/remote/_client/auth/_authenticators/external_command.py +79 -0
- flyte/remote/_client/auth/_authenticators/factory.py +200 -0
- flyte/remote/_client/auth/_authenticators/pkce.py +516 -0
- flyte/remote/_client/auth/_channel.py +184 -0
- flyte/remote/_client/auth/_client_config.py +83 -0
- flyte/remote/_client/auth/_default_html.py +32 -0
- flyte/remote/_client/auth/_grpc_utils/__init__.py +0 -0
- flyte/remote/_client/auth/_grpc_utils/auth_interceptor.py +288 -0
- flyte/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +151 -0
- flyte/remote/_client/auth/_keyring.py +143 -0
- flyte/remote/_client/auth/_token_client.py +260 -0
- flyte/remote/_client/auth/errors.py +16 -0
- flyte/remote/_client/controlplane.py +95 -0
- flyte/remote/_console.py +18 -0
- flyte/remote/_data.py +155 -0
- flyte/remote/_logs.py +116 -0
- flyte/remote/_project.py +86 -0
- flyte/remote/_run.py +873 -0
- flyte/remote/_secret.py +132 -0
- flyte/remote/_task.py +227 -0
- flyte/report/__init__.py +3 -0
- flyte/report/_report.py +178 -0
- flyte/report/_template.html +124 -0
- flyte/storage/__init__.py +24 -0
- flyte/storage/_remote_fs.py +34 -0
- flyte/storage/_storage.py +251 -0
- flyte/storage/_utils.py +5 -0
- flyte/types/__init__.py +13 -0
- flyte/types/_interface.py +25 -0
- flyte/types/_renderer.py +162 -0
- flyte/types/_string_literals.py +120 -0
- flyte/types/_type_engine.py +2210 -0
- flyte/types/_utils.py +80 -0
- flyte-0.0.1b0.dist-info/METADATA +179 -0
- flyte-0.0.1b0.dist-info/RECORD +390 -0
- flyte-0.0.1b0.dist-info/WHEEL +5 -0
- flyte-0.0.1b0.dist-info/entry_points.txt +3 -0
- flyte-0.0.1b0.dist-info/top_level.txt +1 -0
- union/__init__.py +54 -0
- union/_api_commons.py +3 -0
- union/_bin/__init__.py +0 -0
- union/_bin/runtime.py +113 -0
- union/_build.py +25 -0
- union/_cache/__init__.py +12 -0
- union/_cache/cache.py +141 -0
- union/_cache/defaults.py +9 -0
- union/_cache/policy_function_body.py +42 -0
- union/_cli/__init__.py +0 -0
- union/_cli/_common.py +263 -0
- union/_cli/_create.py +40 -0
- union/_cli/_delete.py +23 -0
- union/_cli/_deploy.py +120 -0
- union/_cli/_get.py +162 -0
- union/_cli/_params.py +579 -0
- union/_cli/_run.py +150 -0
- union/_cli/main.py +72 -0
- union/_code_bundle/__init__.py +8 -0
- union/_code_bundle/_ignore.py +113 -0
- union/_code_bundle/_packaging.py +187 -0
- union/_code_bundle/_utils.py +342 -0
- union/_code_bundle/bundle.py +176 -0
- union/_context.py +146 -0
- union/_datastructures.py +295 -0
- union/_deploy.py +185 -0
- union/_doc.py +29 -0
- union/_docstring.py +26 -0
- union/_environment.py +43 -0
- union/_group.py +31 -0
- union/_hash.py +23 -0
- union/_image.py +760 -0
- union/_initialize.py +585 -0
- union/_interface.py +84 -0
- union/_internal/__init__.py +3 -0
- union/_internal/controllers/__init__.py +77 -0
- union/_internal/controllers/_local_controller.py +77 -0
- union/_internal/controllers/pbhash.py +39 -0
- union/_internal/controllers/remote/__init__.py +40 -0
- union/_internal/controllers/remote/_action.py +131 -0
- union/_internal/controllers/remote/_client.py +43 -0
- union/_internal/controllers/remote/_controller.py +169 -0
- union/_internal/controllers/remote/_core.py +341 -0
- union/_internal/controllers/remote/_informer.py +260 -0
- union/_internal/controllers/remote/_service_protocol.py +44 -0
- union/_internal/imagebuild/__init__.py +11 -0
- union/_internal/imagebuild/docker_builder.py +416 -0
- union/_internal/imagebuild/image_builder.py +243 -0
- union/_internal/imagebuild/remote_builder.py +0 -0
- union/_internal/resolvers/__init__.py +0 -0
- union/_internal/resolvers/_task_module.py +31 -0
- union/_internal/resolvers/common.py +24 -0
- union/_internal/resolvers/default.py +27 -0
- union/_internal/runtime/__init__.py +0 -0
- union/_internal/runtime/convert.py +163 -0
- union/_internal/runtime/entrypoints.py +121 -0
- union/_internal/runtime/io.py +136 -0
- union/_internal/runtime/resources_serde.py +134 -0
- union/_internal/runtime/task_serde.py +202 -0
- union/_internal/runtime/taskrunner.py +179 -0
- union/_internal/runtime/types_serde.py +53 -0
- union/_logging.py +124 -0
- union/_protos/__init__.py +0 -0
- union/_protos/common/authorization_pb2.py +66 -0
- union/_protos/common/authorization_pb2.pyi +106 -0
- union/_protos/common/authorization_pb2_grpc.py +4 -0
- union/_protos/common/identifier_pb2.py +71 -0
- union/_protos/common/identifier_pb2.pyi +82 -0
- union/_protos/common/identifier_pb2_grpc.py +4 -0
- union/_protos/common/identity_pb2.py +48 -0
- union/_protos/common/identity_pb2.pyi +72 -0
- union/_protos/common/identity_pb2_grpc.py +4 -0
- union/_protos/common/list_pb2.py +36 -0
- union/_protos/common/list_pb2.pyi +69 -0
- union/_protos/common/list_pb2_grpc.py +4 -0
- union/_protos/common/policy_pb2.py +37 -0
- union/_protos/common/policy_pb2.pyi +27 -0
- union/_protos/common/policy_pb2_grpc.py +4 -0
- union/_protos/common/role_pb2.py +37 -0
- union/_protos/common/role_pb2.pyi +51 -0
- union/_protos/common/role_pb2_grpc.py +4 -0
- union/_protos/common/runtime_version_pb2.py +28 -0
- union/_protos/common/runtime_version_pb2.pyi +24 -0
- union/_protos/common/runtime_version_pb2_grpc.py +4 -0
- union/_protos/logs/dataplane/payload_pb2.py +96 -0
- union/_protos/logs/dataplane/payload_pb2.pyi +168 -0
- union/_protos/logs/dataplane/payload_pb2_grpc.py +4 -0
- union/_protos/secret/definition_pb2.py +49 -0
- union/_protos/secret/definition_pb2.pyi +93 -0
- union/_protos/secret/definition_pb2_grpc.py +4 -0
- union/_protos/secret/payload_pb2.py +62 -0
- union/_protos/secret/payload_pb2.pyi +94 -0
- union/_protos/secret/payload_pb2_grpc.py +4 -0
- union/_protos/secret/secret_pb2.py +38 -0
- union/_protos/secret/secret_pb2.pyi +6 -0
- union/_protos/secret/secret_pb2_grpc.py +198 -0
- union/_protos/validate/validate/validate_pb2.py +76 -0
- union/_protos/workflow/node_execution_service_pb2.py +26 -0
- union/_protos/workflow/node_execution_service_pb2.pyi +4 -0
- union/_protos/workflow/node_execution_service_pb2_grpc.py +32 -0
- union/_protos/workflow/queue_service_pb2.py +75 -0
- union/_protos/workflow/queue_service_pb2.pyi +103 -0
- union/_protos/workflow/queue_service_pb2_grpc.py +172 -0
- union/_protos/workflow/run_definition_pb2.py +100 -0
- union/_protos/workflow/run_definition_pb2.pyi +256 -0
- union/_protos/workflow/run_definition_pb2_grpc.py +4 -0
- union/_protos/workflow/run_logs_service_pb2.py +41 -0
- union/_protos/workflow/run_logs_service_pb2.pyi +28 -0
- union/_protos/workflow/run_logs_service_pb2_grpc.py +69 -0
- union/_protos/workflow/run_service_pb2.py +133 -0
- union/_protos/workflow/run_service_pb2.pyi +173 -0
- union/_protos/workflow/run_service_pb2_grpc.py +412 -0
- union/_protos/workflow/state_service_pb2.py +58 -0
- union/_protos/workflow/state_service_pb2.pyi +69 -0
- union/_protos/workflow/state_service_pb2_grpc.py +138 -0
- union/_protos/workflow/task_definition_pb2.py +72 -0
- union/_protos/workflow/task_definition_pb2.pyi +65 -0
- union/_protos/workflow/task_definition_pb2_grpc.py +4 -0
- union/_protos/workflow/task_service_pb2.py +44 -0
- union/_protos/workflow/task_service_pb2.pyi +31 -0
- union/_protos/workflow/task_service_pb2_grpc.py +104 -0
- union/_resources.py +226 -0
- union/_retry.py +32 -0
- union/_reusable_environment.py +25 -0
- union/_run.py +374 -0
- union/_secret.py +61 -0
- union/_task.py +354 -0
- union/_task_environment.py +186 -0
- union/_timeout.py +47 -0
- union/_tools.py +27 -0
- union/_utils/__init__.py +11 -0
- union/_utils/asyn.py +119 -0
- union/_utils/file_handling.py +71 -0
- union/_utils/helpers.py +46 -0
- union/_utils/lazy_module.py +54 -0
- union/_utils/uv_script_parser.py +49 -0
- union/_version.py +21 -0
- union/connectors/__init__.py +0 -0
- union/errors.py +128 -0
- union/extras/__init__.py +5 -0
- union/extras/_container.py +263 -0
- union/io/__init__.py +11 -0
- union/io/_dataframe.py +0 -0
- union/io/_dir.py +425 -0
- union/io/_file.py +418 -0
- union/io/pickle/__init__.py +0 -0
- union/io/pickle/transformer.py +117 -0
- union/io/structured_dataset/__init__.py +122 -0
- union/io/structured_dataset/basic_dfs.py +219 -0
- union/io/structured_dataset/structured_dataset.py +1057 -0
- union/py.typed +0 -0
- union/remote/__init__.py +23 -0
- union/remote/_client/__init__.py +0 -0
- union/remote/_client/_protocols.py +129 -0
- union/remote/_client/auth/__init__.py +12 -0
- union/remote/_client/auth/_authenticators/__init__.py +0 -0
- union/remote/_client/auth/_authenticators/base.py +391 -0
- union/remote/_client/auth/_authenticators/client_credentials.py +73 -0
- union/remote/_client/auth/_authenticators/device_code.py +120 -0
- union/remote/_client/auth/_authenticators/external_command.py +77 -0
- union/remote/_client/auth/_authenticators/factory.py +200 -0
- union/remote/_client/auth/_authenticators/pkce.py +515 -0
- union/remote/_client/auth/_channel.py +184 -0
- union/remote/_client/auth/_client_config.py +83 -0
- union/remote/_client/auth/_default_html.py +32 -0
- union/remote/_client/auth/_grpc_utils/__init__.py +0 -0
- union/remote/_client/auth/_grpc_utils/auth_interceptor.py +204 -0
- union/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +144 -0
- union/remote/_client/auth/_keyring.py +154 -0
- union/remote/_client/auth/_token_client.py +258 -0
- union/remote/_client/auth/errors.py +16 -0
- union/remote/_client/controlplane.py +86 -0
- union/remote/_data.py +149 -0
- union/remote/_logs.py +74 -0
- union/remote/_project.py +86 -0
- union/remote/_run.py +820 -0
- union/remote/_secret.py +132 -0
- union/remote/_task.py +193 -0
- union/report/__init__.py +3 -0
- union/report/_report.py +178 -0
- union/report/_template.html +124 -0
- union/storage/__init__.py +24 -0
- union/storage/_remote_fs.py +34 -0
- union/storage/_storage.py +247 -0
- union/storage/_utils.py +5 -0
- union/types/__init__.py +11 -0
- union/types/_renderer.py +162 -0
- union/types/_string_literals.py +120 -0
- union/types/_type_engine.py +2131 -0
- union/types/_utils.py +80 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from asyncio import Protocol
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from union._task import TaskTemplate
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Resolver(Protocol):
|
|
8
|
+
"""
|
|
9
|
+
Resolver interface for loading tasks. This interface should be implemented by Resolvers.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def import_path(self) -> str: ...
|
|
14
|
+
|
|
15
|
+
def load_task(self, loader_args: List[str]) -> TaskTemplate:
|
|
16
|
+
"""
|
|
17
|
+
Given the set of identifier keys, should return one TaskTemplate or raise an error if not found
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def loader_args(self, t: TaskTemplate) -> List[str]:
|
|
21
|
+
"""
|
|
22
|
+
Return a list of strings that can help identify the parameter TaskTemplate. Each string should not have
|
|
23
|
+
spaces or special characters. This is used to identify the task in the resolver.
|
|
24
|
+
"""
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from union._internal.resolvers._task_module import extract_task_module
|
|
5
|
+
from union._internal.resolvers.common import Resolver
|
|
6
|
+
from union._task import TaskTemplate
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class DefaultTaskResolver(Resolver):
|
|
10
|
+
"""
|
|
11
|
+
Please see the notes in the TaskResolverMixin as it describes this default behavior.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def import_path(self) -> str:
|
|
16
|
+
return "union._internal.resolvers.default.DefaultTaskResolver"
|
|
17
|
+
|
|
18
|
+
def load_task(self, loader_args: List[str]) -> TaskTemplate:
|
|
19
|
+
_, task_module, _, task_name, *_ = loader_args
|
|
20
|
+
|
|
21
|
+
task_module = importlib.import_module(name=task_module) # type: ignore
|
|
22
|
+
task_def = getattr(task_module, task_name)
|
|
23
|
+
return task_def
|
|
24
|
+
|
|
25
|
+
def loader_args(self, task: TaskTemplate) -> List[str]: # type:ignore
|
|
26
|
+
t, m = extract_task_module(task)
|
|
27
|
+
return ["mod", m, "instance", t]
|
|
File without changes
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Any, Dict, Tuple, Union
|
|
3
|
+
|
|
4
|
+
from flyteidl.core import execution_pb2, literals_pb2
|
|
5
|
+
|
|
6
|
+
import union.errors
|
|
7
|
+
from union._datastructures import NativeInterface
|
|
8
|
+
from union._protos.workflow import run_definition_pb2
|
|
9
|
+
from union.types import TypeEngine
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class Inputs:
|
|
14
|
+
proto_inputs: run_definition_pb2.Inputs
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True)
|
|
18
|
+
class Outputs:
|
|
19
|
+
proto_outputs: run_definition_pb2.Outputs
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class Error:
|
|
24
|
+
err: execution_pb2.ExecutionError
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# ------------------------------- CONVERT Methods ------------------------------- #
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _clean_error_code(code: str) -> Tuple[str, str | None]:
|
|
31
|
+
"""
|
|
32
|
+
The error code may have a server injected code and is of the form `RetriesExhausedError|<code>` or `<code>`.
|
|
33
|
+
|
|
34
|
+
:param code:
|
|
35
|
+
:return: "user code", optional server code
|
|
36
|
+
"""
|
|
37
|
+
if "|" in code:
|
|
38
|
+
server_code, user_code = code.split("|", 1)
|
|
39
|
+
return user_code.strip(), server_code.strip()
|
|
40
|
+
return code.strip(), None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
async def convert_inputs_to_native(inputs: Inputs, python_interface: NativeInterface) -> Dict[str, Any]:
|
|
44
|
+
literals = {named_literal.name: named_literal.value for named_literal in inputs.proto_inputs.literals}
|
|
45
|
+
inputs = await TypeEngine.literal_map_to_kwargs(
|
|
46
|
+
literals_pb2.LiteralMap(literals=literals), python_interface.get_input_types()
|
|
47
|
+
)
|
|
48
|
+
return inputs
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
async def convert_from_native_to_inputs(interface: NativeInterface, *args, **kwargs) -> Inputs:
|
|
52
|
+
kwargs = interface.convert_to_kwargs(*args, **kwargs)
|
|
53
|
+
literal_map = await TypeEngine.dict_to_literal_map(kwargs, interface.get_input_types())
|
|
54
|
+
return Inputs(
|
|
55
|
+
proto_inputs=run_definition_pb2.Inputs(
|
|
56
|
+
literals=[run_definition_pb2.NamedLiteral(name=k, value=v) for k, v in literal_map.literals.items()]
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def convert_from_native_to_outputs(o: Any, interface: NativeInterface) -> Outputs:
|
|
62
|
+
# Always make it a tuple even if it's just one item to simplify logic below
|
|
63
|
+
if not isinstance(o, tuple):
|
|
64
|
+
o = (o,)
|
|
65
|
+
|
|
66
|
+
assert len(interface.outputs) == len(interface.outputs), (
|
|
67
|
+
f"Received {len(o)} outputs but interface has {len(interface.outputs)}"
|
|
68
|
+
)
|
|
69
|
+
named = []
|
|
70
|
+
for (output_name, python_type), v in zip(interface.outputs.items(), o):
|
|
71
|
+
lit = await TypeEngine.to_literal(v, python_type, TypeEngine.to_literal_type(python_type))
|
|
72
|
+
named.append(run_definition_pb2.NamedLiteral(name=output_name, value=lit))
|
|
73
|
+
|
|
74
|
+
return Outputs(proto_outputs=run_definition_pb2.Outputs(literals=named))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
async def convert_outputs_to_native(interface: NativeInterface, outputs: Outputs) -> Union[Any, Tuple[Any, ...]]:
|
|
78
|
+
lm = literals_pb2.LiteralMap(
|
|
79
|
+
literals={named_literal.name: named_literal.value for named_literal in outputs.proto_outputs.literals}
|
|
80
|
+
)
|
|
81
|
+
kwargs = await TypeEngine.literal_map_to_kwargs(lm, interface.outputs)
|
|
82
|
+
if len(kwargs) == 0:
|
|
83
|
+
return None
|
|
84
|
+
elif len(kwargs) == 1:
|
|
85
|
+
return next(iter(kwargs.values()))
|
|
86
|
+
else:
|
|
87
|
+
# Return as tuple if multiple outputs, make sure to order correctly as it seems proto maps can change ordering
|
|
88
|
+
return tuple(kwargs[k] for k in interface.outputs.keys())
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def convert_error_to_native(err: execution_pb2.ExecutionError | Exception | Error) -> BaseException | None:
|
|
92
|
+
if not err:
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
if isinstance(err, Exception):
|
|
96
|
+
return err
|
|
97
|
+
|
|
98
|
+
if isinstance(err, Error):
|
|
99
|
+
err = err.err
|
|
100
|
+
|
|
101
|
+
user_code, server_code = _clean_error_code(err.code)
|
|
102
|
+
match err.kind:
|
|
103
|
+
case execution_pb2.ExecutionError.UNKNOWN:
|
|
104
|
+
return union.errors.RuntimeUnknownError(code=user_code, message=err.message, worker=err.worker)
|
|
105
|
+
case execution_pb2.ExecutionError.USER:
|
|
106
|
+
if "OOM" in err.code.upper():
|
|
107
|
+
return union.errors.OOMError(code=user_code, message=err.message, worker=err.worker)
|
|
108
|
+
elif "Interrupted" in err.code:
|
|
109
|
+
return union.errors.TaskInterruptedError(code=user_code, message=err.message, worker=err.worker)
|
|
110
|
+
elif "PrimaryContainerNotFound" in err.code:
|
|
111
|
+
return union.errors.PrimaryContainerNotFoundError(
|
|
112
|
+
code=user_code, message=err.message, worker=err.worker
|
|
113
|
+
)
|
|
114
|
+
elif "RetriesExhausted" in err.code:
|
|
115
|
+
return union.errors.RetriesExhaustedError(code=user_code, message=err.message, worker=err.worker)
|
|
116
|
+
elif "Unknown" in err.code:
|
|
117
|
+
return union.errors.RuntimeUnknownError(code=user_code, message=err.message, worker=err.worker)
|
|
118
|
+
elif "InvalidImageName" in err.code:
|
|
119
|
+
return union.errors.InvalidImageNameError(code=user_code, message=err.message, worker=err.worker)
|
|
120
|
+
elif "ImagePullBackOff" in err.code:
|
|
121
|
+
return union.errors.ImagePullBackOffError(code=user_code, message=err.message, worker=err.worker)
|
|
122
|
+
return union.errors.RuntimeUserError(code=user_code, message=err.message, worker=err.worker)
|
|
123
|
+
case execution_pb2.ExecutionError.SYSTEM:
|
|
124
|
+
return union.errors.RuntimeSystemError(code=user_code, message=err.message, worker=err.worker)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def convert_from_native_to_error(err: BaseException) -> Error:
|
|
128
|
+
if isinstance(err, union.errors.RuntimeUnknownError):
|
|
129
|
+
return Error(
|
|
130
|
+
err=execution_pb2.ExecutionError(
|
|
131
|
+
kind=execution_pb2.ExecutionError.UNKNOWN,
|
|
132
|
+
code=err.code,
|
|
133
|
+
message=str(err),
|
|
134
|
+
worker=err.worker,
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
elif isinstance(err, union.errors.RuntimeUserError):
|
|
138
|
+
return Error(
|
|
139
|
+
err=execution_pb2.ExecutionError(
|
|
140
|
+
kind=execution_pb2.ExecutionError.USER,
|
|
141
|
+
code=err.code,
|
|
142
|
+
message=str(err),
|
|
143
|
+
worker=err.worker,
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
elif isinstance(err, union.errors.RuntimeSystemError):
|
|
147
|
+
return Error(
|
|
148
|
+
err=execution_pb2.ExecutionError(
|
|
149
|
+
kind=execution_pb2.ExecutionError.SYSTEM,
|
|
150
|
+
code=err.code,
|
|
151
|
+
message=str(err),
|
|
152
|
+
worker=err.worker,
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
else:
|
|
156
|
+
return Error(
|
|
157
|
+
err=execution_pb2.ExecutionError(
|
|
158
|
+
kind=execution_pb2.ExecutionError.UNKNOWN,
|
|
159
|
+
code=type(err).__name__,
|
|
160
|
+
message=str(err),
|
|
161
|
+
worker="UNKNOWN",
|
|
162
|
+
)
|
|
163
|
+
)
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from typing import List, Optional, Tuple
|
|
2
|
+
|
|
3
|
+
from union._code_bundle import download_bundle
|
|
4
|
+
from union._context import contextual_run
|
|
5
|
+
from union._datastructures import ActionID, Checkpoints, CodeBundle, RawDataPath
|
|
6
|
+
from union._internal import Controller
|
|
7
|
+
from union._internal.imagebuild.image_builder import ImageCache
|
|
8
|
+
from union._logging import logger
|
|
9
|
+
from union._task import TaskTemplate
|
|
10
|
+
|
|
11
|
+
from .convert import Error, Inputs, Outputs
|
|
12
|
+
from .task_serde import load_task
|
|
13
|
+
from .taskrunner import (
|
|
14
|
+
convert_and_run,
|
|
15
|
+
extract_download_run_upload,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def direct_dispatch(
|
|
20
|
+
task: TaskTemplate,
|
|
21
|
+
*,
|
|
22
|
+
action: ActionID,
|
|
23
|
+
raw_data_path: RawDataPath,
|
|
24
|
+
controller: Controller,
|
|
25
|
+
version: str,
|
|
26
|
+
checkpoints: Checkpoints | None = None,
|
|
27
|
+
code_bundle: CodeBundle | None = None,
|
|
28
|
+
inputs: Inputs | None = None,
|
|
29
|
+
output_path: str | None = None,
|
|
30
|
+
) -> Tuple[Outputs, Optional[Error]]:
|
|
31
|
+
"""
|
|
32
|
+
This method is used today by the local_controller and is positioned to be used by a rust core in the future.
|
|
33
|
+
The caller, loads the task and invokes this method. This method is used to convert the inputs to native types,
|
|
34
|
+
The reason for this is that the rust entrypoint will not have access to the python context, and
|
|
35
|
+
will not be able to run the tasks in the context tree.
|
|
36
|
+
"""
|
|
37
|
+
return await contextual_run(
|
|
38
|
+
convert_and_run,
|
|
39
|
+
task=task,
|
|
40
|
+
inputs=inputs,
|
|
41
|
+
action=action,
|
|
42
|
+
raw_data_path=raw_data_path,
|
|
43
|
+
checkpoints=checkpoints,
|
|
44
|
+
code_bundle=code_bundle,
|
|
45
|
+
controller=controller,
|
|
46
|
+
version=version,
|
|
47
|
+
output_path=output_path,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
async def _download_and_load_task(
|
|
52
|
+
code_bundle: CodeBundle | None, resolver: str, resolver_args: List[str]
|
|
53
|
+
) -> TaskTemplate:
|
|
54
|
+
if code_bundle and (code_bundle.tgz or code_bundle.pkl):
|
|
55
|
+
logger.debug(f"Downloading {code_bundle}")
|
|
56
|
+
downloaded_path = await download_bundle(code_bundle)
|
|
57
|
+
code_bundle = code_bundle.with_downloaded_path(downloaded_path)
|
|
58
|
+
if code_bundle.pkl:
|
|
59
|
+
try:
|
|
60
|
+
logger.debug(f"Loading task from pkl: {code_bundle.downloaded_path}")
|
|
61
|
+
import gzip
|
|
62
|
+
|
|
63
|
+
import cloudpickle
|
|
64
|
+
|
|
65
|
+
with gzip.open(code_bundle.downloaded_path, "rb") as f:
|
|
66
|
+
return cloudpickle.load(f)
|
|
67
|
+
except Exception as e:
|
|
68
|
+
logger.exception(f"Failed to load pickled task from {code_bundle.downloaded_path}. Reason: {e!s}")
|
|
69
|
+
raise
|
|
70
|
+
logger.debug(
|
|
71
|
+
f"Loading task from tgz: {code_bundle.downloaded_path}, resolver: {resolver}, args: {resolver_args}"
|
|
72
|
+
)
|
|
73
|
+
return load_task(resolver, *resolver_args)
|
|
74
|
+
logger.debug(f"No code bundle provided, loading task from resolver: {resolver}, args: {resolver_args}")
|
|
75
|
+
return load_task(resolver, *resolver_args)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def load_and_run_task(
|
|
79
|
+
action: ActionID,
|
|
80
|
+
raw_data_path: RawDataPath,
|
|
81
|
+
output_path: str,
|
|
82
|
+
version: str,
|
|
83
|
+
controller: Controller,
|
|
84
|
+
resolver: str | None = None,
|
|
85
|
+
resolver_args: List[str] | None = None,
|
|
86
|
+
checkpoints: Checkpoints | None = None,
|
|
87
|
+
code_bundle: CodeBundle | None = None,
|
|
88
|
+
input_path: str | None = None,
|
|
89
|
+
image_cache: ImageCache | None = None,
|
|
90
|
+
):
|
|
91
|
+
"""
|
|
92
|
+
This method is invoked from the runtime/CLI and is used to run a task. This creates the context tree,
|
|
93
|
+
for the tasks to run in. It also handles the loading of the task.
|
|
94
|
+
|
|
95
|
+
:param controller: Controller to use for the task.
|
|
96
|
+
:param resolver: The resolver to use to load the task.
|
|
97
|
+
:param resolver_args: The arguments to pass to the resolver.
|
|
98
|
+
:param action: The ActionID to use for the task.
|
|
99
|
+
:param raw_data_path: The raw data path to use for the task.
|
|
100
|
+
:param output_path: The output path to use for the task.
|
|
101
|
+
:param version: The version of the task to run.
|
|
102
|
+
:param checkpoints: The checkpoints to use for the task.
|
|
103
|
+
:param code_bundle: The code bundle to use for the task.
|
|
104
|
+
:param input_path: The input path to use for the task.
|
|
105
|
+
:param image_cache: Mappings of Image identifiers to image URIs.
|
|
106
|
+
"""
|
|
107
|
+
task = await _download_and_load_task(code_bundle, resolver, resolver_args)
|
|
108
|
+
|
|
109
|
+
await contextual_run(
|
|
110
|
+
extract_download_run_upload,
|
|
111
|
+
task,
|
|
112
|
+
action=action,
|
|
113
|
+
version=version,
|
|
114
|
+
controller=controller,
|
|
115
|
+
raw_data_path=raw_data_path,
|
|
116
|
+
output_path=output_path,
|
|
117
|
+
checkpoints=checkpoints,
|
|
118
|
+
code_bundle=code_bundle,
|
|
119
|
+
input_path=input_path,
|
|
120
|
+
image_cache=image_cache,
|
|
121
|
+
)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module contains the methods for uploading and downloading inputs and outputs.
|
|
3
|
+
It uses the storage module to handle the actual uploading and downloading of files.
|
|
4
|
+
|
|
5
|
+
TODO: Convert to use streaming apis
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
|
|
10
|
+
from flyteidl.core import errors_pb2, execution_pb2
|
|
11
|
+
|
|
12
|
+
import union.storage as storage
|
|
13
|
+
from union._protos.workflow import run_definition_pb2
|
|
14
|
+
|
|
15
|
+
from ..._logging import log
|
|
16
|
+
from .convert import Inputs, Outputs, _clean_error_code
|
|
17
|
+
|
|
18
|
+
# ------------------------------- CONSTANTS ------------------------------- #
|
|
19
|
+
_INPUTS_FILE_NAME = "inputs.pb"
|
|
20
|
+
_OUTPUTS_FILE_NAME = "outputs.pb"
|
|
21
|
+
_CHECKPOINT_FILE_NAME = "_flytecheckpoints"
|
|
22
|
+
_ERROR_FILE_NAME = "error.pb"
|
|
23
|
+
_REPORT_FILE_NAME = "report.html"
|
|
24
|
+
_PKL_FILE_NAME = "code_bundle.pkl.gz"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def pkl_path(base_path: str) -> str:
|
|
28
|
+
return storage.join(base_path, _PKL_FILE_NAME)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def inputs_path(base_path: str) -> str:
|
|
32
|
+
return storage.join(base_path, _INPUTS_FILE_NAME)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def outputs_path(base_path: str) -> str:
|
|
36
|
+
return storage.join(base_path, _OUTPUTS_FILE_NAME)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def error_path(base_path: str) -> str:
|
|
40
|
+
return storage.join(base_path, _ERROR_FILE_NAME)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def report_path(base_path: str) -> str:
|
|
44
|
+
return storage.join(base_path, _REPORT_FILE_NAME)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# ------------------------------- UPLOAD Methods ------------------------------- #
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async def upload_inputs(inputs: Inputs, input_path: str):
|
|
51
|
+
"""
|
|
52
|
+
:param Inputs inputs: Inputs
|
|
53
|
+
:param str input_path: The path to upload the input file.
|
|
54
|
+
"""
|
|
55
|
+
await storage.put_stream(data_iterable=inputs.proto_inputs.SerializeToString(), to_path=input_path)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def upload_outputs(outputs: Outputs, output_path: str):
|
|
59
|
+
"""
|
|
60
|
+
:param outputs: Outputs
|
|
61
|
+
:param output_path: The path to upload the output file.
|
|
62
|
+
"""
|
|
63
|
+
output_uri = outputs_path(output_path)
|
|
64
|
+
await storage.put_stream(data_iterable=outputs.proto_outputs.SerializeToString(), to_path=output_uri)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async def upload_error(err: execution_pb2.ExecutionError, output_prefix: str):
|
|
68
|
+
"""
|
|
69
|
+
:param err: execution_pb2.ExecutionError
|
|
70
|
+
:param output_prefix: The output prefix of the remote uri.
|
|
71
|
+
"""
|
|
72
|
+
# TODO - clean this up + conditionally set kind
|
|
73
|
+
error_document = errors_pb2.ErrorDocument(
|
|
74
|
+
error=errors_pb2.ContainerError(
|
|
75
|
+
code=err.code,
|
|
76
|
+
message=err.message,
|
|
77
|
+
kind=errors_pb2.ContainerError.RECOVERABLE,
|
|
78
|
+
origin=err.kind,
|
|
79
|
+
timestamp=err.timestamp,
|
|
80
|
+
worker=err.worker,
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
error_uri = error_path(output_prefix)
|
|
84
|
+
await storage.put_stream(data_iterable=error_document.SerializeToString(), to_path=error_uri)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# ------------------------------- DOWNLOAD Methods ------------------------------- #
|
|
88
|
+
@log(level=logging.INFO)
|
|
89
|
+
async def load_inputs(path: str) -> Inputs:
|
|
90
|
+
"""
|
|
91
|
+
:param path: Input file to be downloaded
|
|
92
|
+
:return: Inputs object
|
|
93
|
+
"""
|
|
94
|
+
lm = run_definition_pb2.Inputs()
|
|
95
|
+
proto_str = b"".join([c async for c in storage.get_stream(path=path)])
|
|
96
|
+
lm.ParseFromString(proto_str)
|
|
97
|
+
return Inputs(proto_inputs=lm)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
async def load_outputs(path: str) -> Outputs:
|
|
101
|
+
"""
|
|
102
|
+
:param path: output file to be loaded
|
|
103
|
+
:return: Outputs object
|
|
104
|
+
"""
|
|
105
|
+
lm = run_definition_pb2.Outputs()
|
|
106
|
+
proto_str = b"".join([c async for c in storage.get_stream(path=path)])
|
|
107
|
+
lm.ParseFromString(proto_str)
|
|
108
|
+
return Outputs(proto_outputs=lm)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
async def load_error(path: str) -> execution_pb2.ExecutionError:
|
|
112
|
+
"""
|
|
113
|
+
:param path: error file to be downloaded
|
|
114
|
+
:return: execution_pb2.ExecutionError
|
|
115
|
+
"""
|
|
116
|
+
err = errors_pb2.ErrorDocument()
|
|
117
|
+
proto_str = b"".join([c async for c in storage.get_stream(path=path)])
|
|
118
|
+
err.ParseFromString(proto_str)
|
|
119
|
+
|
|
120
|
+
if err.error is not None:
|
|
121
|
+
user_code, server_code = _clean_error_code(err.error.code)
|
|
122
|
+
return execution_pb2.ExecutionError(
|
|
123
|
+
code=user_code,
|
|
124
|
+
message=err.error.message,
|
|
125
|
+
kind=err.error.origin,
|
|
126
|
+
error_uri=path,
|
|
127
|
+
timestamp=err.error.timestamp,
|
|
128
|
+
worker=err.error.worker,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
return execution_pb2.ExecutionError(
|
|
132
|
+
code="Unknown",
|
|
133
|
+
message=f"Received unloadable error from path {path}",
|
|
134
|
+
kind=execution_pb2.ExecutionError.SYSTEM,
|
|
135
|
+
error_uri=path,
|
|
136
|
+
)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
from typing import List, Optional, Tuple
|
|
2
|
+
|
|
3
|
+
from flyteidl.core import tasks_pb2
|
|
4
|
+
|
|
5
|
+
from union._resources import CPUBaseType, Resources
|
|
6
|
+
|
|
7
|
+
ACCELERATOR_DEVICE_MAP = {
|
|
8
|
+
"A100": "nvidia-tesla-a100",
|
|
9
|
+
"A100 80G": "nvidia-a100-80gb",
|
|
10
|
+
"A10": "nvidia-a10",
|
|
11
|
+
"A10G": "nvidia-a10g",
|
|
12
|
+
"A100G": "nvidia-a100g",
|
|
13
|
+
"L4": "nvidia-l4",
|
|
14
|
+
"L40s": "nvidia-l40",
|
|
15
|
+
"L4_VWS": "nvidia-l4-vws",
|
|
16
|
+
"K80": "nvidia-tesla-k80",
|
|
17
|
+
"M60": "nvidia-tesla-m60",
|
|
18
|
+
"P4": "nvidia-tesla-p4",
|
|
19
|
+
"P100": "nvidia-tesla-p100",
|
|
20
|
+
"T4": "nvidia-tesla-t4",
|
|
21
|
+
"V100": "nvidia-tesla-v100",
|
|
22
|
+
"V5E": "tpu-v5-lite-podslice",
|
|
23
|
+
"V5P": "tpu-v5p-slice",
|
|
24
|
+
"V6E": "tpu-v6e-slice",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _get_cpu_resource_entry(cpu: CPUBaseType) -> tasks_pb2.Resources.ResourceEntry:
|
|
29
|
+
return tasks_pb2.Resources.ResourceEntry(
|
|
30
|
+
name=tasks_pb2.Resources.ResourceName.CPU,
|
|
31
|
+
value=str(cpu),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _get_memory_resource_entry(memory: str) -> tasks_pb2.Resources.ResourceEntry:
|
|
36
|
+
return tasks_pb2.Resources.ResourceEntry(
|
|
37
|
+
name=tasks_pb2.Resources.ResourceName.MEMORY,
|
|
38
|
+
value=memory,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _get_gpu_resource_entry(gpu: int) -> tasks_pb2.Resources.ResourceEntry:
|
|
43
|
+
return tasks_pb2.Resources.ResourceEntry(
|
|
44
|
+
name=tasks_pb2.Resources.ResourceName.GPU,
|
|
45
|
+
value=str(gpu),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _get_gpu_extended_resource_entry(resources: Resources) -> Optional[tasks_pb2.GPUAccelerator]:
|
|
50
|
+
if resources is None:
|
|
51
|
+
return None
|
|
52
|
+
if resources.gpu is None or isinstance(resources.gpu, int):
|
|
53
|
+
return None
|
|
54
|
+
device = resources.get_device()
|
|
55
|
+
if device.device not in ACCELERATOR_DEVICE_MAP:
|
|
56
|
+
raise ValueError(f"GPU of type {device.device} unknown, cannot map to device name")
|
|
57
|
+
return tasks_pb2.GPUAccelerator(
|
|
58
|
+
device=ACCELERATOR_DEVICE_MAP[device.device],
|
|
59
|
+
partition_size=device.partition if device.partition else None,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _get_disk_resource_entry(disk: str) -> tasks_pb2.Resources.ResourceEntry:
|
|
64
|
+
return tasks_pb2.Resources.ResourceEntry(
|
|
65
|
+
name=tasks_pb2.Resources.ResourceName.EPHEMERAL_STORAGE,
|
|
66
|
+
value=disk,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_proto_extended_resources(resources: Resources) -> Optional[tasks_pb2.ExtendedResources]:
|
|
71
|
+
"""
|
|
72
|
+
TODO Implement partitioning logic string handling for GPU
|
|
73
|
+
:param resources:
|
|
74
|
+
"""
|
|
75
|
+
if resources is None:
|
|
76
|
+
return None
|
|
77
|
+
acc = _get_gpu_extended_resource_entry(resources)
|
|
78
|
+
shm = resources.get_shared_memory()
|
|
79
|
+
if acc is None and shm is None:
|
|
80
|
+
return None
|
|
81
|
+
proto_shm = None
|
|
82
|
+
if shm is not None:
|
|
83
|
+
proto_shm = tasks_pb2.SharedMemory(
|
|
84
|
+
mount_path="/dev/shm",
|
|
85
|
+
mount_name="union-shm",
|
|
86
|
+
size_limit=shm,
|
|
87
|
+
)
|
|
88
|
+
return tasks_pb2.ExtendedResources(gpu_accelerator=acc, shared_memory=proto_shm)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _convert_resources_to_resource_entries(
|
|
92
|
+
resources: Resources | None,
|
|
93
|
+
) -> Tuple[List[tasks_pb2.Resources.ResourceEntry], List[tasks_pb2.Resources.ResourceEntry]]:
|
|
94
|
+
request_entries, limit_entries = [], []
|
|
95
|
+
if resources is None:
|
|
96
|
+
return request_entries, limit_entries
|
|
97
|
+
if resources.cpu is not None:
|
|
98
|
+
if isinstance(resources.cpu, tuple):
|
|
99
|
+
request_entries.append(_get_cpu_resource_entry(resources.cpu[0]))
|
|
100
|
+
limit_entries.append(_get_cpu_resource_entry(resources.cpu[1]))
|
|
101
|
+
else:
|
|
102
|
+
request_entries.append(_get_cpu_resource_entry(resources.cpu))
|
|
103
|
+
|
|
104
|
+
if resources.memory is not None:
|
|
105
|
+
if isinstance(resources.memory, tuple):
|
|
106
|
+
request_entries.append(_get_memory_resource_entry(resources.memory[0]))
|
|
107
|
+
limit_entries.append(_get_memory_resource_entry(resources.memory[1]))
|
|
108
|
+
else:
|
|
109
|
+
request_entries.append(_get_memory_resource_entry(resources.memory))
|
|
110
|
+
|
|
111
|
+
if resources.gpu is not None:
|
|
112
|
+
device = resources.get_device()
|
|
113
|
+
request_entries.append(_get_gpu_resource_entry(device.quantity))
|
|
114
|
+
|
|
115
|
+
if resources.disk is not None:
|
|
116
|
+
request_entries.append(_get_disk_resource_entry(resources.disk))
|
|
117
|
+
|
|
118
|
+
return request_entries, limit_entries
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def get_proto_resources(resources: Resources) -> Optional[tasks_pb2.Resources]:
|
|
122
|
+
"""
|
|
123
|
+
Get main resources IDL representation from the resources object
|
|
124
|
+
|
|
125
|
+
:param resources: User facing Resources object containing potentially both requests and limits
|
|
126
|
+
:return: The given resources as requests and limits
|
|
127
|
+
"""
|
|
128
|
+
request_entries, limit_entries = _convert_resources_to_resource_entries(resources)
|
|
129
|
+
request_entries = request_entries if request_entries else None
|
|
130
|
+
limit_entries = limit_entries if limit_entries else None
|
|
131
|
+
if not request_entries and not limit_entries:
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
return tasks_pb2.Resources(requests=request_entries, limits=limit_entries)
|