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,138 @@
|
|
|
1
|
+
from typing import List, Optional, Tuple
|
|
2
|
+
|
|
3
|
+
from flyteidl.core import tasks_pb2
|
|
4
|
+
|
|
5
|
+
from flyte._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 is None:
|
|
56
|
+
return None
|
|
57
|
+
if device.device not in ACCELERATOR_DEVICE_MAP:
|
|
58
|
+
raise ValueError(f"GPU of type {device.device} unknown, cannot map to device name")
|
|
59
|
+
return tasks_pb2.GPUAccelerator(
|
|
60
|
+
device=ACCELERATOR_DEVICE_MAP[device.device],
|
|
61
|
+
partition_size=device.partition if device.partition else None,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _get_disk_resource_entry(disk: str) -> tasks_pb2.Resources.ResourceEntry:
|
|
66
|
+
return tasks_pb2.Resources.ResourceEntry(
|
|
67
|
+
name=tasks_pb2.Resources.ResourceName.EPHEMERAL_STORAGE,
|
|
68
|
+
value=disk,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def get_proto_extended_resources(resources: Resources | None) -> Optional[tasks_pb2.ExtendedResources]:
|
|
73
|
+
"""
|
|
74
|
+
TODO Implement partitioning logic string handling for GPU
|
|
75
|
+
:param resources:
|
|
76
|
+
"""
|
|
77
|
+
if resources is None:
|
|
78
|
+
return None
|
|
79
|
+
acc = _get_gpu_extended_resource_entry(resources)
|
|
80
|
+
shm = resources.get_shared_memory()
|
|
81
|
+
if acc is None and shm is None:
|
|
82
|
+
return None
|
|
83
|
+
proto_shm = None
|
|
84
|
+
if shm is not None:
|
|
85
|
+
proto_shm = tasks_pb2.SharedMemory(
|
|
86
|
+
mount_path="/dev/shm",
|
|
87
|
+
mount_name="flyte-shm",
|
|
88
|
+
size_limit=shm,
|
|
89
|
+
)
|
|
90
|
+
return tasks_pb2.ExtendedResources(gpu_accelerator=acc, shared_memory=proto_shm)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _convert_resources_to_resource_entries(
|
|
94
|
+
resources: Resources | None,
|
|
95
|
+
) -> Tuple[List[tasks_pb2.Resources.ResourceEntry], List[tasks_pb2.Resources.ResourceEntry]]:
|
|
96
|
+
request_entries: List[tasks_pb2.Resources.ResourceEntry] = []
|
|
97
|
+
limit_entries: List[tasks_pb2.Resources.ResourceEntry] = []
|
|
98
|
+
if resources is None:
|
|
99
|
+
return request_entries, limit_entries
|
|
100
|
+
if resources.cpu is not None:
|
|
101
|
+
if isinstance(resources.cpu, tuple):
|
|
102
|
+
request_entries.append(_get_cpu_resource_entry(resources.cpu[0]))
|
|
103
|
+
limit_entries.append(_get_cpu_resource_entry(resources.cpu[1]))
|
|
104
|
+
else:
|
|
105
|
+
request_entries.append(_get_cpu_resource_entry(resources.cpu))
|
|
106
|
+
|
|
107
|
+
if resources.memory is not None:
|
|
108
|
+
if isinstance(resources.memory, tuple):
|
|
109
|
+
request_entries.append(_get_memory_resource_entry(resources.memory[0]))
|
|
110
|
+
limit_entries.append(_get_memory_resource_entry(resources.memory[1]))
|
|
111
|
+
else:
|
|
112
|
+
request_entries.append(_get_memory_resource_entry(resources.memory))
|
|
113
|
+
|
|
114
|
+
if resources.gpu is not None:
|
|
115
|
+
device = resources.get_device()
|
|
116
|
+
if device is not None:
|
|
117
|
+
request_entries.append(_get_gpu_resource_entry(device.quantity))
|
|
118
|
+
|
|
119
|
+
if resources.disk is not None:
|
|
120
|
+
request_entries.append(_get_disk_resource_entry(resources.disk))
|
|
121
|
+
|
|
122
|
+
return request_entries, limit_entries
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_proto_resources(resources: Resources | None) -> Optional[tasks_pb2.Resources]:
|
|
126
|
+
"""
|
|
127
|
+
Get main resources IDL representation from the resources object
|
|
128
|
+
|
|
129
|
+
:param resources: User facing Resources object containing potentially both requests and limits
|
|
130
|
+
:return: The given resources as requests and limits
|
|
131
|
+
"""
|
|
132
|
+
if resources is None:
|
|
133
|
+
return None
|
|
134
|
+
request_entries, limit_entries = _convert_resources_to_resource_entries(resources)
|
|
135
|
+
if not request_entries and not limit_entries:
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
return tasks_pb2.Resources(requests=request_entries, limits=limit_entries)
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides functionality to serialize and deserialize tasks to and from the wire format.
|
|
3
|
+
It includes a Resolver interface for loading tasks, and functions to load classes and tasks.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import importlib
|
|
7
|
+
from datetime import timedelta
|
|
8
|
+
from typing import Optional, Type
|
|
9
|
+
|
|
10
|
+
from flyteidl.core import identifier_pb2, literals_pb2, security_pb2, tasks_pb2
|
|
11
|
+
from google.protobuf import duration_pb2, wrappers_pb2
|
|
12
|
+
|
|
13
|
+
import flyte.errors
|
|
14
|
+
from flyte._cache.cache import VersionParameters, cache_from_request
|
|
15
|
+
from flyte._datastructures import SerializationContext
|
|
16
|
+
from flyte._logging import logger
|
|
17
|
+
from flyte._protos.workflow import task_definition_pb2
|
|
18
|
+
from flyte._secret import SecretRequest, secrets_from_request
|
|
19
|
+
from flyte._task import AsyncFunctionTaskTemplate, TaskTemplate
|
|
20
|
+
|
|
21
|
+
from ..._retry import RetryStrategy
|
|
22
|
+
from ..._timeout import TimeoutType, timeout_from_request
|
|
23
|
+
from .resources_serde import get_proto_extended_resources, get_proto_resources
|
|
24
|
+
from .types_serde import transform_native_to_typed_interface
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load_class(qualified_name) -> Type:
|
|
28
|
+
"""
|
|
29
|
+
Load a class from a qualified name. The qualified name should be in the format 'module.ClassName'.
|
|
30
|
+
:param qualified_name: The qualified name of the class to load.
|
|
31
|
+
:return: The class object.
|
|
32
|
+
"""
|
|
33
|
+
module_name, class_name = qualified_name.rsplit(".", 1) # Split module and class
|
|
34
|
+
module = importlib.import_module(module_name) # Import the module
|
|
35
|
+
return getattr(module, class_name) # Retrieve the class
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def load_task(resolver: str, *resolver_args: str) -> TaskTemplate:
|
|
39
|
+
"""
|
|
40
|
+
Load a task from a resolver. This is a placeholder function.
|
|
41
|
+
|
|
42
|
+
:param resolver: The resolver to use to load the task.
|
|
43
|
+
:param resolver_args: Arguments to pass to the resolver.
|
|
44
|
+
:return: The loaded task.
|
|
45
|
+
"""
|
|
46
|
+
resolver_class = load_class(resolver)
|
|
47
|
+
resolver_instance = resolver_class()
|
|
48
|
+
return resolver_instance.load_task(resolver_args)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def translate_task_to_wire(
|
|
52
|
+
task: TaskTemplate, serialization_context: SerializationContext
|
|
53
|
+
) -> task_definition_pb2.TaskSpec:
|
|
54
|
+
"""
|
|
55
|
+
Translate a task to a wire format. This is a placeholder function.
|
|
56
|
+
|
|
57
|
+
:param task: The task to translate.
|
|
58
|
+
:param serialization_context: The serialization context to use for the translation.
|
|
59
|
+
|
|
60
|
+
:return: The translated task.
|
|
61
|
+
"""
|
|
62
|
+
return get_proto_task(task, serialization_context)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_security_context(secrets: Optional[SecretRequest]) -> Optional[security_pb2.SecurityContext]:
|
|
66
|
+
"""
|
|
67
|
+
Get the security context from a list of secrets. This is a placeholder function.
|
|
68
|
+
|
|
69
|
+
:param secrets: The list of secrets to use for the security context.
|
|
70
|
+
|
|
71
|
+
:return: The security context.
|
|
72
|
+
"""
|
|
73
|
+
if secrets is None:
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
secret_list = secrets_from_request(secrets)
|
|
77
|
+
return security_pb2.SecurityContext(
|
|
78
|
+
secrets=[
|
|
79
|
+
security_pb2.Secret(
|
|
80
|
+
group=secret.group,
|
|
81
|
+
key=secret.key,
|
|
82
|
+
mount_requirement=(
|
|
83
|
+
security_pb2.Secret.MountType.ENV_VAR if secret.as_env_var else security_pb2.Secret.MountType.FILE
|
|
84
|
+
),
|
|
85
|
+
env_var=secret.as_env_var,
|
|
86
|
+
)
|
|
87
|
+
for secret in secret_list
|
|
88
|
+
]
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def get_proto_retry_strategy(retries: RetryStrategy | int | None) -> Optional[literals_pb2.RetryStrategy]:
|
|
93
|
+
if retries is None:
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
if isinstance(retries, int):
|
|
97
|
+
raise AssertionError("Retries should be an instance of RetryStrategy, not int")
|
|
98
|
+
|
|
99
|
+
return literals_pb2.RetryStrategy(retries=retries.count)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def get_proto_timeout(timeout: TimeoutType | None) -> Optional[duration_pb2.Duration]:
|
|
103
|
+
if timeout is None:
|
|
104
|
+
return None
|
|
105
|
+
max_runtime_timeout = timeout_from_request(timeout).max_runtime
|
|
106
|
+
if isinstance(max_runtime_timeout, int):
|
|
107
|
+
max_runtime_timeout = timedelta(seconds=max_runtime_timeout)
|
|
108
|
+
return duration_pb2.Duration(seconds=max_runtime_timeout.seconds)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def get_proto_task(task: TaskTemplate, serialize_context: SerializationContext) -> task_definition_pb2.TaskSpec:
|
|
112
|
+
task_id = identifier_pb2.Identifier(
|
|
113
|
+
resource_type=identifier_pb2.ResourceType.TASK,
|
|
114
|
+
project=serialize_context.project,
|
|
115
|
+
domain=serialize_context.domain,
|
|
116
|
+
org=serialize_context.org,
|
|
117
|
+
name=task.name,
|
|
118
|
+
version=serialize_context.version,
|
|
119
|
+
)
|
|
120
|
+
# TODO, there will be tasks that do not have images, handle that case
|
|
121
|
+
# if task.parent_env is None:
|
|
122
|
+
# raise ValueError(f"Task {task.name} must have a parent environment")
|
|
123
|
+
|
|
124
|
+
#
|
|
125
|
+
# This pod will be incorrect when doing fast serialize
|
|
126
|
+
#
|
|
127
|
+
container = _get_urun_container(serialize_context, task)
|
|
128
|
+
|
|
129
|
+
# TODO Add support for SQL, Pod, extra_config, custom
|
|
130
|
+
pod = None
|
|
131
|
+
sql = None
|
|
132
|
+
# pod = task.get_k8s_pod(serialize_context)
|
|
133
|
+
extra_config = {} # type: ignore
|
|
134
|
+
custom = {} # type: ignore
|
|
135
|
+
|
|
136
|
+
# -------------- CACHE HANDLING ----------------------
|
|
137
|
+
task_cache = cache_from_request(task.cache)
|
|
138
|
+
cache_enabled = task_cache.is_enabled()
|
|
139
|
+
cache_version = None
|
|
140
|
+
|
|
141
|
+
if task_cache.is_enabled():
|
|
142
|
+
logger.debug(f"Cache enabled for task {task.name}")
|
|
143
|
+
if serialize_context.code_bundle and serialize_context.code_bundle.pkl:
|
|
144
|
+
logger.debug(f"Detected pkl bundle for task {task.name}, using computed version as cache version")
|
|
145
|
+
cache_version = serialize_context.code_bundle.computed_version
|
|
146
|
+
else:
|
|
147
|
+
version_parameters = None
|
|
148
|
+
if isinstance(task, AsyncFunctionTaskTemplate):
|
|
149
|
+
version_parameters = VersionParameters(func=task.func, image=task.image)
|
|
150
|
+
else:
|
|
151
|
+
version_parameters = VersionParameters(func=None, image=task.image)
|
|
152
|
+
cache_version = task_cache.get_version(version_parameters)
|
|
153
|
+
logger.debug(f"Cache version for task {task.name} is {cache_version}")
|
|
154
|
+
else:
|
|
155
|
+
logger.debug(f"Cache disabled for task {task.name}")
|
|
156
|
+
|
|
157
|
+
tt = tasks_pb2.TaskTemplate(
|
|
158
|
+
id=task_id,
|
|
159
|
+
type=task.task_type,
|
|
160
|
+
metadata=tasks_pb2.TaskMetadata(
|
|
161
|
+
discoverable=cache_enabled,
|
|
162
|
+
discovery_version=cache_version,
|
|
163
|
+
cache_serializable=task_cache.serialize,
|
|
164
|
+
cache_ignore_input_vars=task_cache.ignored_inputs,
|
|
165
|
+
runtime=tasks_pb2.RuntimeMetadata(),
|
|
166
|
+
retries=get_proto_retry_strategy(task.retries),
|
|
167
|
+
timeout=get_proto_timeout(task.timeout),
|
|
168
|
+
pod_template_name=task.pod_template if task.pod_template and isinstance(task.pod_template, str) else None,
|
|
169
|
+
interruptible=task.interruptable,
|
|
170
|
+
generates_deck=wrappers_pb2.BoolValue(value=False), # TODO add support for reports
|
|
171
|
+
),
|
|
172
|
+
interface=transform_native_to_typed_interface(task.native_interface),
|
|
173
|
+
custom=custom,
|
|
174
|
+
container=container,
|
|
175
|
+
task_type_version=task.task_type_version,
|
|
176
|
+
security_context=get_security_context(task.secrets),
|
|
177
|
+
config=extra_config,
|
|
178
|
+
k8s_pod=pod,
|
|
179
|
+
sql=sql,
|
|
180
|
+
extended_resources=get_proto_extended_resources(task.resources),
|
|
181
|
+
)
|
|
182
|
+
return task_definition_pb2.TaskSpec(task_template=tt)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _get_urun_container(
|
|
186
|
+
serialize_context: SerializationContext, task_template: TaskTemplate
|
|
187
|
+
) -> Optional[tasks_pb2.Container]:
|
|
188
|
+
env = (
|
|
189
|
+
[literals_pb2.KeyValuePair(key=k, value=v) for k, v in task_template.env.items()] if task_template.env else None
|
|
190
|
+
)
|
|
191
|
+
resources = get_proto_resources(task_template.resources)
|
|
192
|
+
# pr: under what conditions should this return None?
|
|
193
|
+
if isinstance(task_template.image, str):
|
|
194
|
+
raise flyte.errors.RuntimeSystemError("BadConfig", "Image is not a valid image")
|
|
195
|
+
image_id = task_template.image.identifier
|
|
196
|
+
if not serialize_context.image_cache or image_id not in serialize_context.image_cache.image_lookup:
|
|
197
|
+
# This computes the image uri, computing hashes as necessary so can fail if done remotely.
|
|
198
|
+
img_uri = task_template.image.uri
|
|
199
|
+
else:
|
|
200
|
+
img_uri = serialize_context.image_cache.image_lookup[image_id]
|
|
201
|
+
|
|
202
|
+
return tasks_pb2.Container(
|
|
203
|
+
image=img_uri,
|
|
204
|
+
command=[],
|
|
205
|
+
args=task_template.container_args(serialize_context),
|
|
206
|
+
resources=resources,
|
|
207
|
+
env=env,
|
|
208
|
+
data_config=task_template.data_loading_config(serialize_context),
|
|
209
|
+
config=task_template.config(serialize_context),
|
|
210
|
+
)
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module is responsible for running tasks in the V2 runtime. All methods in this file should be
|
|
3
|
+
invoked within a context tree.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import pathlib
|
|
7
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
8
|
+
|
|
9
|
+
import flyte.report
|
|
10
|
+
from flyte._context import internal_ctx
|
|
11
|
+
from flyte._datastructures import ActionID, Checkpoints, CodeBundle, RawDataPath, TaskContext
|
|
12
|
+
from flyte._internal.imagebuild.image_builder import ImageCache
|
|
13
|
+
from flyte._logging import log, logger
|
|
14
|
+
from flyte._task import TaskTemplate
|
|
15
|
+
from flyte.errors import CustomError, RuntimeSystemError, RuntimeUnknownError, RuntimeUserError
|
|
16
|
+
|
|
17
|
+
from .. import Controller
|
|
18
|
+
from .convert import (
|
|
19
|
+
Error,
|
|
20
|
+
Inputs,
|
|
21
|
+
Outputs,
|
|
22
|
+
convert_from_native_to_error,
|
|
23
|
+
convert_from_native_to_outputs,
|
|
24
|
+
convert_inputs_to_native,
|
|
25
|
+
)
|
|
26
|
+
from .io import load_inputs, upload_error, upload_outputs
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def replace_task_cli(args: List[str], inputs: Inputs, tmp_path: pathlib.Path, action: ActionID) -> List[str]:
|
|
30
|
+
"""
|
|
31
|
+
This method can be used to run an task from the cli, if you have cli for the task. It will replace,
|
|
32
|
+
all the args with the task args.
|
|
33
|
+
|
|
34
|
+
The urun cli is of the format
|
|
35
|
+
```python
|
|
36
|
+
['urun', '--inputs', '{{.Inputs}}', '--outputs-path', '{{.Outputs}}', '--version', '',
|
|
37
|
+
'--raw-data-path', '{{.rawOutputDataPrefix}}',
|
|
38
|
+
'--checkpoint-path', '{{.checkpointOutputPrefix}}', '--prev-checkpoint', '{{.prevCheckpointPrefix}}',
|
|
39
|
+
'--run-name', '{{.runName}}', '--name', '{{.actionName}}',
|
|
40
|
+
'--tgz', 'some-path', '--dest', '.',
|
|
41
|
+
'--resolver', 'flyte._internal.resolvers.default.DefaultTaskResolver', '--resolver-args',
|
|
42
|
+
'mod', 'test_round_trip', 'instance', 'task1']
|
|
43
|
+
```
|
|
44
|
+
We will replace, inputs, outputs, raw_data_path, checkpoint_path, prev_checkpoint, run_name, name
|
|
45
|
+
with supplied values.
|
|
46
|
+
|
|
47
|
+
:param args: urun command
|
|
48
|
+
:param inputs: converted inputs to the task
|
|
49
|
+
:param tmp_path: temporary path to use for the task
|
|
50
|
+
:param action: run id to use for the task
|
|
51
|
+
:return: modified args
|
|
52
|
+
"""
|
|
53
|
+
# Iterate over all the args and replace the inputs, outputs, raw_data_path, checkpoint_path, prev_checkpoint,
|
|
54
|
+
# root_name, run_name with the supplied values
|
|
55
|
+
# first we will write the inputs to a file called inputs.pb
|
|
56
|
+
inputs_path = tmp_path / "inputs.pb"
|
|
57
|
+
with open(inputs_path, "wb") as f:
|
|
58
|
+
f.write(inputs.proto_inputs.SerializeToString())
|
|
59
|
+
# now modify the args
|
|
60
|
+
args = list(args) # copy first because it's a proto container
|
|
61
|
+
for i, arg in enumerate(args):
|
|
62
|
+
match arg:
|
|
63
|
+
case "--inputs":
|
|
64
|
+
args[i + 1] = str(inputs_path)
|
|
65
|
+
case "--outputs-path":
|
|
66
|
+
args[i + 1] = str(tmp_path)
|
|
67
|
+
case "--raw-data-path":
|
|
68
|
+
args[i + 1] = str(tmp_path / "raw_data_path")
|
|
69
|
+
case "--checkpoint-path":
|
|
70
|
+
args[i + 1] = str(tmp_path / "checkpoint_path")
|
|
71
|
+
case "--prev-checkpoint":
|
|
72
|
+
args[i + 1] = str(tmp_path / "prev_checkpoint")
|
|
73
|
+
case "--run-name":
|
|
74
|
+
args[i + 1] = action.run_name or ""
|
|
75
|
+
case "--name":
|
|
76
|
+
args[i + 1] = action.name
|
|
77
|
+
insert_point = args.index("--raw-data-path")
|
|
78
|
+
args.insert(insert_point, str(tmp_path))
|
|
79
|
+
args.insert(insert_point, "--run-base-dir")
|
|
80
|
+
return args
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@log
|
|
84
|
+
async def run_task(
|
|
85
|
+
tctx: TaskContext, controller: Controller, task: TaskTemplate, inputs: Dict[str, Any]
|
|
86
|
+
) -> Tuple[Any, Optional[Exception]]:
|
|
87
|
+
try:
|
|
88
|
+
logger.info(f"Parent task executing {tctx.action}")
|
|
89
|
+
outputs = await task.execute(**inputs)
|
|
90
|
+
logger.info(f"Parent task completed successfully, {tctx.action}")
|
|
91
|
+
return outputs, None
|
|
92
|
+
except RuntimeSystemError as e:
|
|
93
|
+
logger.exception(f"Task failed with error: {e}")
|
|
94
|
+
return {}, e
|
|
95
|
+
except RuntimeUnknownError as e:
|
|
96
|
+
logger.exception(f"Task failed with error: {e}")
|
|
97
|
+
return {}, e
|
|
98
|
+
except RuntimeUserError as e:
|
|
99
|
+
logger.exception(f"Task failed with error: {e}")
|
|
100
|
+
return {}, e
|
|
101
|
+
except Exception as e:
|
|
102
|
+
logger.exception(f"Task failed with error: {e}")
|
|
103
|
+
return {}, CustomError.from_exception(e)
|
|
104
|
+
finally:
|
|
105
|
+
logger.info(f"Parent task finalized {tctx.action}")
|
|
106
|
+
# reconstruct run id here
|
|
107
|
+
await controller.finalize_parent_action(tctx.action)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
async def convert_and_run(
|
|
111
|
+
*,
|
|
112
|
+
task: TaskTemplate,
|
|
113
|
+
inputs: Inputs,
|
|
114
|
+
action: ActionID,
|
|
115
|
+
controller: Controller,
|
|
116
|
+
raw_data_path: RawDataPath,
|
|
117
|
+
version: str,
|
|
118
|
+
output_path: str,
|
|
119
|
+
run_base_dir: str,
|
|
120
|
+
checkpoints: Checkpoints | None = None,
|
|
121
|
+
code_bundle: CodeBundle | None = None,
|
|
122
|
+
image_cache: ImageCache | None = None,
|
|
123
|
+
) -> Tuple[Optional[Outputs], Optional[Error]]:
|
|
124
|
+
"""
|
|
125
|
+
This method is used to convert the inputs to native types, and run the task. It assumes you are running
|
|
126
|
+
in a context tree.
|
|
127
|
+
"""
|
|
128
|
+
ctx = internal_ctx()
|
|
129
|
+
tctx = TaskContext(
|
|
130
|
+
action=action,
|
|
131
|
+
checkpoints=checkpoints,
|
|
132
|
+
code_bundle=code_bundle,
|
|
133
|
+
output_path=output_path,
|
|
134
|
+
run_base_dir=run_base_dir,
|
|
135
|
+
version=version,
|
|
136
|
+
raw_data_path=raw_data_path,
|
|
137
|
+
compiled_image_cache=image_cache,
|
|
138
|
+
report=flyte.report.Report(name=action.name),
|
|
139
|
+
)
|
|
140
|
+
async with ctx.replace_task_context(tctx):
|
|
141
|
+
inputs_kwargs = await convert_inputs_to_native(inputs, task.native_interface)
|
|
142
|
+
out, err = await run_task(tctx=tctx, controller=controller, task=task, inputs=inputs_kwargs)
|
|
143
|
+
if err is not None:
|
|
144
|
+
return None, convert_from_native_to_error(err)
|
|
145
|
+
if task.report:
|
|
146
|
+
await flyte.report.flush.aio()
|
|
147
|
+
return await convert_from_native_to_outputs(out, task.native_interface), None
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
async def extract_download_run_upload(
|
|
151
|
+
task: TaskTemplate,
|
|
152
|
+
*,
|
|
153
|
+
action: ActionID,
|
|
154
|
+
controller: Controller,
|
|
155
|
+
raw_data_path: RawDataPath,
|
|
156
|
+
output_path: str,
|
|
157
|
+
run_base_dir: str,
|
|
158
|
+
version: str,
|
|
159
|
+
checkpoints: Checkpoints | None = None,
|
|
160
|
+
code_bundle: CodeBundle | None = None,
|
|
161
|
+
input_path: str | None = None,
|
|
162
|
+
image_cache: ImageCache | None = None,
|
|
163
|
+
):
|
|
164
|
+
"""
|
|
165
|
+
This method is invoked from the CLI (urun) and is used to run a task. This assumes that the context tree
|
|
166
|
+
has already been created, and the task has been loaded. It also handles the loading of the task.
|
|
167
|
+
"""
|
|
168
|
+
inputs = await load_inputs(input_path) if input_path else None
|
|
169
|
+
outputs, err = await convert_and_run(
|
|
170
|
+
task=task,
|
|
171
|
+
inputs=inputs or Inputs.empty(),
|
|
172
|
+
action=action,
|
|
173
|
+
controller=controller,
|
|
174
|
+
raw_data_path=raw_data_path,
|
|
175
|
+
output_path=output_path,
|
|
176
|
+
run_base_dir=run_base_dir,
|
|
177
|
+
version=version,
|
|
178
|
+
checkpoints=checkpoints,
|
|
179
|
+
code_bundle=code_bundle,
|
|
180
|
+
image_cache=image_cache,
|
|
181
|
+
)
|
|
182
|
+
if err is not None:
|
|
183
|
+
path = await upload_error(err.err, output_path)
|
|
184
|
+
logger.error(f"Task {task.name} failed with error: {err}. Uploaded error to {path}")
|
|
185
|
+
return
|
|
186
|
+
if outputs is None:
|
|
187
|
+
logger.info(f"Task {task.name} completed successfully, no outputs")
|
|
188
|
+
return
|
|
189
|
+
await upload_outputs(outputs, output_path) if output_path else None
|
|
190
|
+
logger.info(f"Task {task.name} completed successfully, uploaded outputs to {output_path}")
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from typing import Dict, Optional, TypeVar
|
|
2
|
+
|
|
3
|
+
from flyteidl.core import interface_pb2
|
|
4
|
+
|
|
5
|
+
from flyte._datastructures import NativeInterface
|
|
6
|
+
from flyte.types._type_engine import TypeEngine
|
|
7
|
+
|
|
8
|
+
T = TypeVar("T")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def transform_variable_map(
|
|
12
|
+
variable_map: Dict[str, type],
|
|
13
|
+
descriptions: Optional[Dict[str, str]] = None,
|
|
14
|
+
) -> Dict[str, interface_pb2.Variable]:
|
|
15
|
+
"""
|
|
16
|
+
Given a map of str (names of inputs for instance) to their Python native types, return a map of the name to a
|
|
17
|
+
Flyte Variable object with that type.
|
|
18
|
+
"""
|
|
19
|
+
res = {}
|
|
20
|
+
descriptions = descriptions or {}
|
|
21
|
+
if variable_map:
|
|
22
|
+
for k, v in variable_map.items():
|
|
23
|
+
res[k] = transform_type(v, descriptions.get(k, k))
|
|
24
|
+
return res
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def transform_native_to_typed_interface(
|
|
28
|
+
interface: Optional[NativeInterface],
|
|
29
|
+
) -> Optional[interface_pb2.TypedInterface]:
|
|
30
|
+
"""
|
|
31
|
+
Transform the given simple python native interface to FlyteIDL's interface
|
|
32
|
+
"""
|
|
33
|
+
if interface is None:
|
|
34
|
+
return None
|
|
35
|
+
input_descriptions: Dict[str, str] = {}
|
|
36
|
+
output_descriptions: Dict[str, str] = {}
|
|
37
|
+
if interface.docstring:
|
|
38
|
+
# Fill in descriptions from docstring in the future
|
|
39
|
+
input_descriptions = {}
|
|
40
|
+
output_descriptions = {}
|
|
41
|
+
|
|
42
|
+
inputs_map = transform_variable_map(interface.get_input_types(), input_descriptions)
|
|
43
|
+
outputs_map = transform_variable_map(interface.outputs, output_descriptions)
|
|
44
|
+
return interface_pb2.TypedInterface(
|
|
45
|
+
inputs=interface_pb2.VariableMap(variables=inputs_map), outputs=interface_pb2.VariableMap(variables=outputs_map)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def transform_type(x: type, description: Optional[str] = None) -> interface_pb2.Variable:
|
|
50
|
+
# add artifact handling eventually
|
|
51
|
+
return interface_pb2.Variable(
|
|
52
|
+
type=TypeEngine.to_literal_type(x),
|
|
53
|
+
description=description,
|
|
54
|
+
)
|