flyte 0.2.0b1__py3-none-any.whl → 2.0.0b46__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.
Files changed (266) hide show
  1. flyte/__init__.py +83 -30
  2. flyte/_bin/connect.py +61 -0
  3. flyte/_bin/debug.py +38 -0
  4. flyte/_bin/runtime.py +87 -19
  5. flyte/_bin/serve.py +351 -0
  6. flyte/_build.py +3 -2
  7. flyte/_cache/cache.py +6 -5
  8. flyte/_cache/local_cache.py +216 -0
  9. flyte/_code_bundle/_ignore.py +31 -5
  10. flyte/_code_bundle/_packaging.py +42 -11
  11. flyte/_code_bundle/_utils.py +57 -34
  12. flyte/_code_bundle/bundle.py +130 -27
  13. flyte/_constants.py +1 -0
  14. flyte/_context.py +21 -5
  15. flyte/_custom_context.py +73 -0
  16. flyte/_debug/constants.py +37 -0
  17. flyte/_debug/utils.py +17 -0
  18. flyte/_debug/vscode.py +315 -0
  19. flyte/_deploy.py +396 -75
  20. flyte/_deployer.py +109 -0
  21. flyte/_environment.py +94 -11
  22. flyte/_excepthook.py +37 -0
  23. flyte/_group.py +2 -1
  24. flyte/_hash.py +1 -16
  25. flyte/_image.py +544 -231
  26. flyte/_initialize.py +456 -316
  27. flyte/_interface.py +40 -5
  28. flyte/_internal/controllers/__init__.py +22 -8
  29. flyte/_internal/controllers/_local_controller.py +159 -35
  30. flyte/_internal/controllers/_trace.py +18 -10
  31. flyte/_internal/controllers/remote/__init__.py +38 -9
  32. flyte/_internal/controllers/remote/_action.py +82 -12
  33. flyte/_internal/controllers/remote/_client.py +6 -2
  34. flyte/_internal/controllers/remote/_controller.py +290 -64
  35. flyte/_internal/controllers/remote/_core.py +155 -95
  36. flyte/_internal/controllers/remote/_informer.py +40 -20
  37. flyte/_internal/controllers/remote/_service_protocol.py +2 -2
  38. flyte/_internal/imagebuild/__init__.py +2 -10
  39. flyte/_internal/imagebuild/docker_builder.py +391 -84
  40. flyte/_internal/imagebuild/image_builder.py +111 -55
  41. flyte/_internal/imagebuild/remote_builder.py +409 -0
  42. flyte/_internal/imagebuild/utils.py +79 -0
  43. flyte/_internal/resolvers/_app_env_module.py +92 -0
  44. flyte/_internal/resolvers/_task_module.py +5 -38
  45. flyte/_internal/resolvers/app_env.py +26 -0
  46. flyte/_internal/resolvers/common.py +8 -1
  47. flyte/_internal/resolvers/default.py +2 -2
  48. flyte/_internal/runtime/convert.py +319 -36
  49. flyte/_internal/runtime/entrypoints.py +106 -18
  50. flyte/_internal/runtime/io.py +71 -23
  51. flyte/_internal/runtime/resources_serde.py +21 -7
  52. flyte/_internal/runtime/reuse.py +125 -0
  53. flyte/_internal/runtime/rusty.py +196 -0
  54. flyte/_internal/runtime/task_serde.py +239 -66
  55. flyte/_internal/runtime/taskrunner.py +48 -8
  56. flyte/_internal/runtime/trigger_serde.py +162 -0
  57. flyte/_internal/runtime/types_serde.py +7 -16
  58. flyte/_keyring/file.py +115 -0
  59. flyte/_link.py +30 -0
  60. flyte/_logging.py +241 -42
  61. flyte/_map.py +312 -0
  62. flyte/_metrics.py +59 -0
  63. flyte/_module.py +74 -0
  64. flyte/_pod.py +30 -0
  65. flyte/_resources.py +296 -33
  66. flyte/_retry.py +1 -7
  67. flyte/_reusable_environment.py +72 -7
  68. flyte/_run.py +462 -132
  69. flyte/_secret.py +47 -11
  70. flyte/_serve.py +333 -0
  71. flyte/_task.py +245 -56
  72. flyte/_task_environment.py +219 -97
  73. flyte/_task_plugins.py +47 -0
  74. flyte/_tools.py +8 -8
  75. flyte/_trace.py +15 -24
  76. flyte/_trigger.py +1027 -0
  77. flyte/_utils/__init__.py +12 -1
  78. flyte/_utils/asyn.py +3 -1
  79. flyte/_utils/async_cache.py +139 -0
  80. flyte/_utils/coro_management.py +5 -4
  81. flyte/_utils/description_parser.py +19 -0
  82. flyte/_utils/docker_credentials.py +173 -0
  83. flyte/_utils/helpers.py +45 -19
  84. flyte/_utils/module_loader.py +123 -0
  85. flyte/_utils/org_discovery.py +57 -0
  86. flyte/_utils/uv_script_parser.py +8 -1
  87. flyte/_version.py +16 -3
  88. flyte/app/__init__.py +27 -0
  89. flyte/app/_app_environment.py +362 -0
  90. flyte/app/_connector_environment.py +40 -0
  91. flyte/app/_deploy.py +130 -0
  92. flyte/app/_parameter.py +343 -0
  93. flyte/app/_runtime/__init__.py +3 -0
  94. flyte/app/_runtime/app_serde.py +383 -0
  95. flyte/app/_types.py +113 -0
  96. flyte/app/extras/__init__.py +9 -0
  97. flyte/app/extras/_auth_middleware.py +217 -0
  98. flyte/app/extras/_fastapi.py +93 -0
  99. flyte/app/extras/_model_loader/__init__.py +3 -0
  100. flyte/app/extras/_model_loader/config.py +7 -0
  101. flyte/app/extras/_model_loader/loader.py +288 -0
  102. flyte/cli/__init__.py +12 -0
  103. flyte/cli/_abort.py +28 -0
  104. flyte/cli/_build.py +114 -0
  105. flyte/cli/_common.py +493 -0
  106. flyte/cli/_create.py +371 -0
  107. flyte/cli/_delete.py +45 -0
  108. flyte/cli/_deploy.py +401 -0
  109. flyte/cli/_gen.py +316 -0
  110. flyte/cli/_get.py +446 -0
  111. flyte/cli/_option.py +33 -0
  112. flyte/{_cli → cli}/_params.py +57 -17
  113. flyte/cli/_plugins.py +209 -0
  114. flyte/cli/_prefetch.py +292 -0
  115. flyte/cli/_run.py +690 -0
  116. flyte/cli/_serve.py +338 -0
  117. flyte/cli/_update.py +86 -0
  118. flyte/cli/_user.py +20 -0
  119. flyte/cli/main.py +246 -0
  120. flyte/config/__init__.py +2 -167
  121. flyte/config/_config.py +215 -163
  122. flyte/config/_internal.py +10 -1
  123. flyte/config/_reader.py +225 -0
  124. flyte/connectors/__init__.py +11 -0
  125. flyte/connectors/_connector.py +330 -0
  126. flyte/connectors/_server.py +194 -0
  127. flyte/connectors/utils.py +159 -0
  128. flyte/errors.py +134 -2
  129. flyte/extend.py +24 -0
  130. flyte/extras/_container.py +69 -56
  131. flyte/git/__init__.py +3 -0
  132. flyte/git/_config.py +279 -0
  133. flyte/io/__init__.py +8 -1
  134. flyte/io/{structured_dataset → _dataframe}/__init__.py +32 -30
  135. flyte/io/{structured_dataset → _dataframe}/basic_dfs.py +75 -68
  136. flyte/io/{structured_dataset/structured_dataset.py → _dataframe/dataframe.py} +207 -242
  137. flyte/io/_dir.py +575 -113
  138. flyte/io/_file.py +587 -141
  139. flyte/io/_hashing_io.py +342 -0
  140. flyte/io/extend.py +7 -0
  141. flyte/models.py +635 -0
  142. flyte/prefetch/__init__.py +22 -0
  143. flyte/prefetch/_hf_model.py +563 -0
  144. flyte/remote/__init__.py +14 -3
  145. flyte/remote/_action.py +879 -0
  146. flyte/remote/_app.py +346 -0
  147. flyte/remote/_auth_metadata.py +42 -0
  148. flyte/remote/_client/_protocols.py +62 -4
  149. flyte/remote/_client/auth/_auth_utils.py +19 -0
  150. flyte/remote/_client/auth/_authenticators/base.py +8 -2
  151. flyte/remote/_client/auth/_authenticators/device_code.py +4 -5
  152. flyte/remote/_client/auth/_authenticators/factory.py +4 -0
  153. flyte/remote/_client/auth/_authenticators/passthrough.py +79 -0
  154. flyte/remote/_client/auth/_authenticators/pkce.py +17 -18
  155. flyte/remote/_client/auth/_channel.py +47 -18
  156. flyte/remote/_client/auth/_client_config.py +5 -3
  157. flyte/remote/_client/auth/_keyring.py +15 -2
  158. flyte/remote/_client/auth/_token_client.py +3 -3
  159. flyte/remote/_client/controlplane.py +206 -18
  160. flyte/remote/_common.py +66 -0
  161. flyte/remote/_data.py +107 -22
  162. flyte/remote/_logs.py +116 -33
  163. flyte/remote/_project.py +21 -19
  164. flyte/remote/_run.py +164 -631
  165. flyte/remote/_secret.py +72 -29
  166. flyte/remote/_task.py +387 -46
  167. flyte/remote/_trigger.py +368 -0
  168. flyte/remote/_user.py +43 -0
  169. flyte/report/_report.py +10 -6
  170. flyte/storage/__init__.py +13 -1
  171. flyte/storage/_config.py +237 -0
  172. flyte/storage/_parallel_reader.py +289 -0
  173. flyte/storage/_storage.py +268 -59
  174. flyte/syncify/__init__.py +56 -0
  175. flyte/syncify/_api.py +414 -0
  176. flyte/types/__init__.py +39 -0
  177. flyte/types/_interface.py +22 -7
  178. flyte/{io/pickle/transformer.py → types/_pickle.py} +37 -9
  179. flyte/types/_string_literals.py +8 -9
  180. flyte/types/_type_engine.py +226 -126
  181. flyte/types/_utils.py +1 -1
  182. flyte-2.0.0b46.data/scripts/debug.py +38 -0
  183. flyte-2.0.0b46.data/scripts/runtime.py +194 -0
  184. flyte-2.0.0b46.dist-info/METADATA +352 -0
  185. flyte-2.0.0b46.dist-info/RECORD +221 -0
  186. flyte-2.0.0b46.dist-info/entry_points.txt +8 -0
  187. flyte-2.0.0b46.dist-info/licenses/LICENSE +201 -0
  188. flyte/_api_commons.py +0 -3
  189. flyte/_cli/_common.py +0 -299
  190. flyte/_cli/_create.py +0 -42
  191. flyte/_cli/_delete.py +0 -23
  192. flyte/_cli/_deploy.py +0 -140
  193. flyte/_cli/_get.py +0 -235
  194. flyte/_cli/_run.py +0 -174
  195. flyte/_cli/main.py +0 -98
  196. flyte/_datastructures.py +0 -342
  197. flyte/_internal/controllers/pbhash.py +0 -39
  198. flyte/_protos/common/authorization_pb2.py +0 -66
  199. flyte/_protos/common/authorization_pb2.pyi +0 -108
  200. flyte/_protos/common/authorization_pb2_grpc.py +0 -4
  201. flyte/_protos/common/identifier_pb2.py +0 -71
  202. flyte/_protos/common/identifier_pb2.pyi +0 -82
  203. flyte/_protos/common/identifier_pb2_grpc.py +0 -4
  204. flyte/_protos/common/identity_pb2.py +0 -48
  205. flyte/_protos/common/identity_pb2.pyi +0 -72
  206. flyte/_protos/common/identity_pb2_grpc.py +0 -4
  207. flyte/_protos/common/list_pb2.py +0 -36
  208. flyte/_protos/common/list_pb2.pyi +0 -69
  209. flyte/_protos/common/list_pb2_grpc.py +0 -4
  210. flyte/_protos/common/policy_pb2.py +0 -37
  211. flyte/_protos/common/policy_pb2.pyi +0 -27
  212. flyte/_protos/common/policy_pb2_grpc.py +0 -4
  213. flyte/_protos/common/role_pb2.py +0 -37
  214. flyte/_protos/common/role_pb2.pyi +0 -53
  215. flyte/_protos/common/role_pb2_grpc.py +0 -4
  216. flyte/_protos/common/runtime_version_pb2.py +0 -28
  217. flyte/_protos/common/runtime_version_pb2.pyi +0 -24
  218. flyte/_protos/common/runtime_version_pb2_grpc.py +0 -4
  219. flyte/_protos/logs/dataplane/payload_pb2.py +0 -96
  220. flyte/_protos/logs/dataplane/payload_pb2.pyi +0 -168
  221. flyte/_protos/logs/dataplane/payload_pb2_grpc.py +0 -4
  222. flyte/_protos/secret/definition_pb2.py +0 -49
  223. flyte/_protos/secret/definition_pb2.pyi +0 -93
  224. flyte/_protos/secret/definition_pb2_grpc.py +0 -4
  225. flyte/_protos/secret/payload_pb2.py +0 -62
  226. flyte/_protos/secret/payload_pb2.pyi +0 -94
  227. flyte/_protos/secret/payload_pb2_grpc.py +0 -4
  228. flyte/_protos/secret/secret_pb2.py +0 -38
  229. flyte/_protos/secret/secret_pb2.pyi +0 -6
  230. flyte/_protos/secret/secret_pb2_grpc.py +0 -198
  231. flyte/_protos/secret/secret_pb2_grpc_grpc.py +0 -198
  232. flyte/_protos/validate/validate/validate_pb2.py +0 -76
  233. flyte/_protos/workflow/node_execution_service_pb2.py +0 -26
  234. flyte/_protos/workflow/node_execution_service_pb2.pyi +0 -4
  235. flyte/_protos/workflow/node_execution_service_pb2_grpc.py +0 -32
  236. flyte/_protos/workflow/queue_service_pb2.py +0 -106
  237. flyte/_protos/workflow/queue_service_pb2.pyi +0 -141
  238. flyte/_protos/workflow/queue_service_pb2_grpc.py +0 -172
  239. flyte/_protos/workflow/run_definition_pb2.py +0 -128
  240. flyte/_protos/workflow/run_definition_pb2.pyi +0 -310
  241. flyte/_protos/workflow/run_definition_pb2_grpc.py +0 -4
  242. flyte/_protos/workflow/run_logs_service_pb2.py +0 -41
  243. flyte/_protos/workflow/run_logs_service_pb2.pyi +0 -28
  244. flyte/_protos/workflow/run_logs_service_pb2_grpc.py +0 -69
  245. flyte/_protos/workflow/run_service_pb2.py +0 -133
  246. flyte/_protos/workflow/run_service_pb2.pyi +0 -175
  247. flyte/_protos/workflow/run_service_pb2_grpc.py +0 -412
  248. flyte/_protos/workflow/state_service_pb2.py +0 -58
  249. flyte/_protos/workflow/state_service_pb2.pyi +0 -71
  250. flyte/_protos/workflow/state_service_pb2_grpc.py +0 -138
  251. flyte/_protos/workflow/task_definition_pb2.py +0 -72
  252. flyte/_protos/workflow/task_definition_pb2.pyi +0 -65
  253. flyte/_protos/workflow/task_definition_pb2_grpc.py +0 -4
  254. flyte/_protos/workflow/task_service_pb2.py +0 -44
  255. flyte/_protos/workflow/task_service_pb2.pyi +0 -31
  256. flyte/_protos/workflow/task_service_pb2_grpc.py +0 -104
  257. flyte/io/_dataframe.py +0 -0
  258. flyte/io/pickle/__init__.py +0 -0
  259. flyte/remote/_console.py +0 -18
  260. flyte-0.2.0b1.dist-info/METADATA +0 -179
  261. flyte-0.2.0b1.dist-info/RECORD +0 -204
  262. flyte-0.2.0b1.dist-info/entry_points.txt +0 -3
  263. /flyte/{_cli → _debug}/__init__.py +0 -0
  264. /flyte/{_protos → _keyring}/__init__.py +0 -0
  265. {flyte-0.2.0b1.dist-info → flyte-2.0.0b46.dist-info}/WHEEL +0 -0
  266. {flyte-0.2.0b1.dist-info → flyte-2.0.0b46.dist-info}/top_level.txt +0 -0
@@ -5,14 +5,13 @@ It uses the storage module to handle the actual uploading and downloading of fil
5
5
  TODO: Convert to use streaming apis
6
6
  """
7
7
 
8
- import logging
9
-
10
- from flyteidl.core import errors_pb2, execution_pb2
8
+ from flyteidl2.core import errors_pb2, execution_pb2
9
+ from flyteidl2.task import common_pb2
11
10
 
12
11
  import flyte.storage as storage
13
- from flyte._protos.workflow import run_definition_pb2
12
+ from flyte._logging import logger
13
+ from flyte.models import PathRewrite
14
14
 
15
- from ..._logging import log
16
15
  from .convert import Inputs, Outputs, _clean_error_code
17
16
 
18
17
  # ------------------------------- CONSTANTS ------------------------------- #
@@ -21,11 +20,11 @@ _OUTPUTS_FILE_NAME = "outputs.pb"
21
20
  _CHECKPOINT_FILE_NAME = "_flytecheckpoints"
22
21
  _ERROR_FILE_NAME = "error.pb"
23
22
  _REPORT_FILE_NAME = "report.html"
24
- _PKL_FILE_NAME = "code_bundle.pkl.gz"
23
+ _PKL_EXT = ".pkl.gz"
25
24
 
26
25
 
27
- def pkl_path(base_path: str) -> str:
28
- return storage.join(base_path, _PKL_FILE_NAME)
26
+ def pkl_path(base_path: str, pkl_name: str) -> str:
27
+ return storage.join(base_path, f"{pkl_name}{_PKL_EXT}")
29
28
 
30
29
 
31
30
  def inputs_path(base_path: str) -> str:
@@ -55,16 +54,25 @@ async def upload_inputs(inputs: Inputs, input_path: str):
55
54
  await storage.put_stream(data_iterable=inputs.proto_inputs.SerializeToString(), to_path=input_path)
56
55
 
57
56
 
58
- async def upload_outputs(outputs: Outputs, output_path: str):
57
+ async def upload_outputs(outputs: Outputs, output_path: str, max_bytes: int = -1):
59
58
  """
60
59
  :param outputs: Outputs
61
60
  :param output_path: The path to upload the output file.
61
+ :param max_bytes: Maximum number of bytes to write to the output file. Default is -1, which means no limit.
62
62
  """
63
+ if max_bytes != -1 and outputs.proto_outputs.ByteSize() > max_bytes:
64
+ import flyte.errors
65
+
66
+ raise flyte.errors.InlineIOMaxBytesBreached(
67
+ f"Output file at {output_path} exceeds max_bytes limit of {max_bytes},"
68
+ f" size: {outputs.proto_outputs.ByteSize()}"
69
+ )
63
70
  output_uri = outputs_path(output_path)
64
71
  await storage.put_stream(data_iterable=outputs.proto_outputs.SerializeToString(), to_path=output_uri)
72
+ logger.debug(f"Uploaded {output_uri} to {output_path}")
65
73
 
66
74
 
67
- async def upload_error(err: execution_pb2.ExecutionError, output_prefix: str):
75
+ async def upload_error(err: execution_pb2.ExecutionError, output_prefix: str) -> str:
68
76
  """
69
77
  :param err: execution_pb2.ExecutionError
70
78
  :param output_prefix: The output prefix of the remote uri.
@@ -76,34 +84,76 @@ async def upload_error(err: execution_pb2.ExecutionError, output_prefix: str):
76
84
  message=err.message,
77
85
  kind=errors_pb2.ContainerError.RECOVERABLE,
78
86
  origin=err.kind,
79
- timestamp=err.timestamp,
80
- worker=err.worker,
81
87
  )
82
88
  )
83
89
  error_uri = error_path(output_prefix)
84
- await storage.put_stream(data_iterable=error_document.SerializeToString(), to_path=error_uri)
90
+ return await storage.put_stream(data_iterable=error_document.SerializeToString(), to_path=error_uri)
85
91
 
86
92
 
87
93
  # ------------------------------- DOWNLOAD Methods ------------------------------- #
88
- @log(level=logging.INFO)
89
- async def load_inputs(path: str) -> Inputs:
94
+ async def load_inputs(path: str, max_bytes: int = -1, path_rewrite_config: PathRewrite | None = None) -> Inputs:
90
95
  """
91
96
  :param path: Input file to be downloaded
97
+ :param max_bytes: Maximum number of bytes to read from the input file. Default is -1, which means no limit.
98
+ :param path_rewrite_config: If provided, rewrites paths in the input blobs according to the configuration.
92
99
  :return: Inputs object
93
100
  """
94
- lm = run_definition_pb2.Inputs()
95
- proto_str = b"".join([c async for c in storage.get_stream(path=path)])
101
+ lm = common_pb2.Inputs()
102
+ if max_bytes == -1:
103
+ proto_str = b"".join([c async for c in storage.get_stream(path=path)])
104
+ else:
105
+ proto_bytes = []
106
+ total_bytes = 0
107
+ async for chunk in storage.get_stream(path=path):
108
+ if total_bytes + len(chunk) > max_bytes:
109
+ import flyte.errors
110
+
111
+ raise flyte.errors.InlineIOMaxBytesBreached(
112
+ f"Input file at {path} exceeds max_bytes limit of {max_bytes}"
113
+ )
114
+ proto_bytes.append(chunk)
115
+ total_bytes += len(chunk)
116
+ proto_str = b"".join(proto_bytes)
117
+
96
118
  lm.ParseFromString(proto_str)
119
+
120
+ if path_rewrite_config is not None:
121
+ for inp in lm.literals:
122
+ if inp.value.HasField("scalar") and inp.value.scalar.HasField("blob"):
123
+ scalar_blob = inp.value.scalar.blob
124
+ if scalar_blob.uri.startswith(path_rewrite_config.old_prefix):
125
+ scalar_blob.uri = scalar_blob.uri.replace(
126
+ path_rewrite_config.old_prefix, path_rewrite_config.new_prefix, 1
127
+ )
128
+
97
129
  return Inputs(proto_inputs=lm)
98
130
 
99
131
 
100
- async def load_outputs(path: str) -> Outputs:
132
+ async def load_outputs(path: str, max_bytes: int = -1) -> Outputs:
101
133
  """
102
134
  :param path: output file to be loaded
135
+ :param max_bytes: Maximum number of bytes to read from the output file.
136
+ If -1, reads the entire file.
103
137
  :return: Outputs object
104
138
  """
105
- lm = run_definition_pb2.Outputs()
106
- proto_str = b"".join([c async for c in storage.get_stream(path=path)])
139
+ lm = common_pb2.Outputs()
140
+
141
+ if max_bytes == -1:
142
+ proto_str = b"".join([c async for c in storage.get_stream(path=path)])
143
+ else:
144
+ proto_bytes = []
145
+ total_bytes = 0
146
+ async for chunk in storage.get_stream(path=path):
147
+ if total_bytes + len(chunk) > max_bytes:
148
+ import flyte.errors
149
+
150
+ raise flyte.errors.InlineIOMaxBytesBreached(
151
+ f"Output file at {path} exceeds max_bytes limit of {max_bytes}"
152
+ )
153
+ proto_bytes.append(chunk)
154
+ total_bytes += len(chunk)
155
+ proto_str = b"".join(proto_bytes)
156
+
107
157
  lm.ParseFromString(proto_str)
108
158
  return Outputs(proto_outputs=lm)
109
159
 
@@ -118,14 +168,12 @@ async def load_error(path: str) -> execution_pb2.ExecutionError:
118
168
  err.ParseFromString(proto_str)
119
169
 
120
170
  if err.error is not None:
121
- user_code, server_code = _clean_error_code(err.error.code)
171
+ user_code, _server_code = _clean_error_code(err.error.code)
122
172
  return execution_pb2.ExecutionError(
123
173
  code=user_code,
124
174
  message=err.error.message,
125
175
  kind=err.error.origin,
126
176
  error_uri=path,
127
- timestamp=err.error.timestamp,
128
- worker=err.error.worker,
129
177
  )
130
178
 
131
179
  return execution_pb2.ExecutionError(
@@ -1,8 +1,8 @@
1
- from typing import List, Optional, Tuple
1
+ from typing import Dict, List, Optional, Tuple
2
2
 
3
- from flyteidl.core import tasks_pb2
3
+ from flyteidl2.core import tasks_pb2
4
4
 
5
- from flyte._resources import CPUBaseType, Resources
5
+ from flyte._resources import CPUBaseType, DeviceClass, Resources
6
6
 
7
7
  ACCELERATOR_DEVICE_MAP = {
8
8
  "A100": "nvidia-tesla-a100",
@@ -11,7 +11,7 @@ ACCELERATOR_DEVICE_MAP = {
11
11
  "A10G": "nvidia-a10g",
12
12
  "A100G": "nvidia-a100g",
13
13
  "L4": "nvidia-l4",
14
- "L40s": "nvidia-l40",
14
+ "L40s": "nvidia-l40s",
15
15
  "L4_VWS": "nvidia-l4-vws",
16
16
  "K80": "nvidia-tesla-k80",
17
17
  "M60": "nvidia-tesla-m60",
@@ -24,6 +24,14 @@ ACCELERATOR_DEVICE_MAP = {
24
24
  "V6E": "tpu-v6e-slice",
25
25
  }
26
26
 
27
+ _DeviceClassToProto: Dict[DeviceClass, "tasks_pb2.GPUAccelerator.DeviceClass"] = {
28
+ "GPU": tasks_pb2.GPUAccelerator.NVIDIA_GPU,
29
+ "TPU": tasks_pb2.GPUAccelerator.GOOGLE_TPU,
30
+ "NEURON": tasks_pb2.GPUAccelerator.AMAZON_NEURON,
31
+ "AMD_GPU": tasks_pb2.GPUAccelerator.AMD_GPU,
32
+ "HABANA_GAUDI": tasks_pb2.GPUAccelerator.HABANA_GAUDI,
33
+ }
34
+
27
35
 
28
36
  def _get_cpu_resource_entry(cpu: CPUBaseType) -> tasks_pb2.Resources.ResourceEntry:
29
37
  return tasks_pb2.Resources.ResourceEntry(
@@ -54,11 +62,17 @@ def _get_gpu_extended_resource_entry(resources: Resources) -> Optional[tasks_pb2
54
62
  device = resources.get_device()
55
63
  if device is None:
56
64
  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")
65
+
66
+ device_class = _DeviceClassToProto.get(device.device_class, tasks_pb2.GPUAccelerator.NVIDIA_GPU)
67
+ if device.device is None:
68
+ raise RuntimeError("Device type must be specified for GPU string.")
69
+ else:
70
+ device_type = device.device
71
+ device_type = ACCELERATOR_DEVICE_MAP.get(device_type, device_type)
59
72
  return tasks_pb2.GPUAccelerator(
60
- device=ACCELERATOR_DEVICE_MAP[device.device],
73
+ device=device_type,
61
74
  partition_size=device.partition if device.partition else None,
75
+ device_class=device_class,
62
76
  )
63
77
 
64
78
 
@@ -0,0 +1,125 @@
1
+ import hashlib
2
+ import typing
3
+ from venv import logger
4
+
5
+ from flyteidl2.core import tasks_pb2
6
+
7
+ import flyte.errors
8
+ from flyte import ReusePolicy
9
+ from flyte._pod import _PRIMARY_CONTAINER_DEFAULT_NAME, _PRIMARY_CONTAINER_NAME_FIELD
10
+ from flyte.models import CodeBundle
11
+
12
+
13
+ def extract_unique_id_and_image(
14
+ env_name: str,
15
+ code_bundle: CodeBundle | None,
16
+ task: tasks_pb2.TaskTemplate,
17
+ reuse_policy: ReusePolicy,
18
+ ) -> typing.Tuple[str, str]:
19
+ """
20
+ Compute a unique ID for the task based on its name, version, image URI, and code bundle.
21
+ :param env_name: Name of the reusable environment.
22
+ :param reuse_policy: The reuse policy for the task.
23
+ :param task: The task template.
24
+ :param code_bundle: The code bundle associated with the task.
25
+ :return: A unique ID string and the image URI.
26
+ """
27
+ image = ""
28
+ container_ser = ""
29
+ if task.HasField("container"):
30
+ copied_container = tasks_pb2.Container()
31
+ copied_container.CopyFrom(task.container)
32
+ copied_container.args.clear() # Clear args to ensure deterministic serialization
33
+ container_ser = copied_container.SerializeToString(deterministic=True)
34
+ image = copied_container.image
35
+
36
+ if task.HasField("k8s_pod"):
37
+ # Clear args to ensure deterministic serialization
38
+ copied_k8s_pod = tasks_pb2.K8sPod()
39
+ copied_k8s_pod.CopyFrom(task.k8s_pod)
40
+ if task.config is not None:
41
+ primary_container_name = task.config[_PRIMARY_CONTAINER_NAME_FIELD]
42
+ else:
43
+ primary_container_name = _PRIMARY_CONTAINER_DEFAULT_NAME
44
+ for container in copied_k8s_pod.pod_spec["containers"]:
45
+ if "name" in container and container["name"] == primary_container_name:
46
+ image = container["image"]
47
+ del container["args"]
48
+ container_ser = copied_k8s_pod.SerializeToString(deterministic=True)
49
+
50
+ components = f"{env_name}:{container_ser}"
51
+ if isinstance(reuse_policy.replicas, tuple):
52
+ components += f":{reuse_policy.replicas[0]}:{reuse_policy.replicas[1]}"
53
+ else:
54
+ components += f":{reuse_policy.replicas}"
55
+ if reuse_policy.idle_ttl:
56
+ components += f":{reuse_policy.idle_ttl.total_seconds()}" # type: ignore [union-attr]
57
+ if reuse_policy.get_scaledown_ttl() is not None:
58
+ components += f":{reuse_policy.get_scaledown_ttl()}"
59
+ if code_bundle is not None:
60
+ components += f":{code_bundle.computed_version}"
61
+ if task.security_context is not None:
62
+ security_ctx_str = task.security_context.SerializeToString(deterministic=True)
63
+ components += f":{security_ctx_str}"
64
+ if task.metadata.interruptible is not None:
65
+ components += f":{task.metadata.interruptible}"
66
+ if task.metadata.pod_template_name is not None:
67
+ components += f":{task.metadata.pod_template_name}"
68
+ sha256 = hashlib.sha256()
69
+ sha256.update(components.encode("utf-8"))
70
+ return sha256.hexdigest(), image
71
+
72
+
73
+ def add_reusable(
74
+ task: tasks_pb2.TaskTemplate,
75
+ reuse_policy: ReusePolicy,
76
+ code_bundle: CodeBundle | None,
77
+ parent_env_name: str | None = None,
78
+ ) -> tasks_pb2.TaskTemplate:
79
+ """
80
+ Convert a ReusePolicy to a custom configuration dictionary.
81
+
82
+ :param task: The task to which the reusable policy will be added.
83
+ :param reuse_policy: The reuse policy to apply.
84
+ :param code_bundle: The code bundle associated with the task.
85
+ :param parent_env_name: The name of the parent environment, if any.
86
+ :return: The modified task with the reusable policy added.
87
+ """
88
+ if reuse_policy is None:
89
+ return task
90
+
91
+ if task.HasField("custom"):
92
+ raise flyte.errors.RuntimeUserError(
93
+ "BadConfiguration", "Plugins do not support reusable policy. Only container tasks and pods."
94
+ )
95
+
96
+ logger.debug(f"Adding reusable policy for task: {task.id.name}")
97
+ name = parent_env_name if parent_env_name else ""
98
+ if parent_env_name is None:
99
+ name = task.id.name.split(".")[0]
100
+
101
+ version, image_uri = extract_unique_id_and_image(
102
+ env_name=name, code_bundle=code_bundle, task=task, reuse_policy=reuse_policy
103
+ )
104
+
105
+ scaledown_ttl = reuse_policy.get_scaledown_ttl()
106
+
107
+ task.custom = {
108
+ "name": name,
109
+ "version": version[:15], # Use only the first 15 characters for the version
110
+ "type": "actor",
111
+ "spec": {
112
+ "container_image": image_uri,
113
+ "backlog_length": None,
114
+ "parallelism": reuse_policy.concurrency,
115
+ "min_replica_count": reuse_policy.min_replicas,
116
+ "replica_count": reuse_policy.max_replicas,
117
+ "ttl_seconds": reuse_policy.idle_ttl.total_seconds() if reuse_policy.idle_ttl else None, # type: ignore [union-attr]
118
+ "scaledown_ttl_seconds": scaledown_ttl.total_seconds() if scaledown_ttl else None,
119
+ },
120
+ }
121
+
122
+ task.type = "actor"
123
+ logger.info(f"Reusable task {task.id.name} with config {task.custom}")
124
+
125
+ return task
@@ -0,0 +1,196 @@
1
+ import asyncio
2
+ import time
3
+ from typing import List, Tuple
4
+
5
+ from flyte._context import contextual_run
6
+ from flyte._internal.controllers import Controller
7
+ from flyte._internal.controllers import create_controller as _create_controller
8
+ from flyte._internal.imagebuild.image_builder import ImageCache
9
+ from flyte._internal.runtime.entrypoints import download_code_bundle, load_pkl_task, load_task
10
+ from flyte._internal.runtime.taskrunner import extract_download_run_upload
11
+ from flyte._logging import logger
12
+ from flyte._task import TaskTemplate
13
+ from flyte._utils import adjust_sys_path
14
+ from flyte.models import ActionID, Checkpoints, CodeBundle, PathRewrite, RawDataPath
15
+
16
+
17
+ async def download_tgz(destination: str, version: str, tgz: str) -> CodeBundle:
18
+ """
19
+ Downloads and loads the task from the code bundle or resolver.
20
+ :param tgz: The path to the task template in a tar.gz format.
21
+ :param destination: The path to save the downloaded task template.
22
+ :param version: The version of the task to load.
23
+ :return: The CodeBundle object.
24
+ """
25
+ logger.info(f"[rusty] Downloading tgz code bundle from {tgz} to {destination} with version {version}")
26
+ adjust_sys_path()
27
+
28
+ code_bundle = CodeBundle(
29
+ tgz=tgz,
30
+ destination=destination,
31
+ computed_version=version,
32
+ )
33
+ return await download_code_bundle(code_bundle)
34
+
35
+
36
+ async def download_load_pkl(destination: str, version: str, pkl: str) -> Tuple[CodeBundle, TaskTemplate]:
37
+ """
38
+ Downloads and loads the task from the code bundle or resolver.
39
+ :param pkl: The path to the task template in a pickle format.
40
+ :param destination: The path to save the downloaded task template.
41
+ :param version: The version of the task to load.
42
+ :return: The CodeBundle object.
43
+ """
44
+ logger.info(f"[rusty] Downloading pkl code bundle from {pkl} to {destination} with version {version}")
45
+ adjust_sys_path()
46
+
47
+ code_bundle = CodeBundle(
48
+ pkl=pkl,
49
+ destination=destination,
50
+ computed_version=version,
51
+ )
52
+ code_bundle = await download_code_bundle(code_bundle)
53
+ return code_bundle, load_pkl_task(code_bundle)
54
+
55
+
56
+ def load_task_from_code_bundle(resolver: str, resolver_args: List[str]) -> TaskTemplate:
57
+ """
58
+ Loads the task from the code bundle or resolver.
59
+ :param resolver: The resolver to use to load the task.
60
+ :param resolver_args: The arguments to pass to the resolver.
61
+ :return: The loaded task template.
62
+ """
63
+ logger.debug(f"[rusty] Loading task from code bundle {resolver} with args: {resolver_args}")
64
+ return load_task(resolver, *resolver_args)
65
+
66
+
67
+ async def create_controller(
68
+ endpoint: str = "host.docker.internal:8090",
69
+ insecure: bool = False,
70
+ api_key: str | None = None,
71
+ ) -> Controller:
72
+ """
73
+ Creates a controller instance for remote operations.
74
+ :param endpoint:
75
+ :param insecure:
76
+ :param api_key:
77
+ :return:
78
+ """
79
+ logger.info(f"[rusty] Creating controller with endpoint {endpoint}")
80
+ import flyte.errors
81
+ from flyte._initialize import init_in_cluster
82
+
83
+ loop = asyncio.get_event_loop()
84
+ loop.set_exception_handler(flyte.errors.silence_grpc_polling_error)
85
+
86
+ # TODO Currently remote tasks are not supported in Rusty.
87
+ controller_kwargs = await init_in_cluster.aio(api_key=api_key, endpoint=endpoint, insecure=insecure)
88
+ return _create_controller(ct="remote", **controller_kwargs)
89
+
90
+
91
+ async def run_task(
92
+ task: TaskTemplate,
93
+ controller: Controller,
94
+ org: str,
95
+ project: str,
96
+ domain: str,
97
+ run_name: str,
98
+ name: str,
99
+ raw_data_path: str,
100
+ output_path: str,
101
+ run_base_dir: str,
102
+ version: str,
103
+ image_cache: str | None = None,
104
+ checkpoint_path: str | None = None,
105
+ prev_checkpoint: str | None = None,
106
+ code_bundle: CodeBundle | None = None,
107
+ input_path: str | None = None,
108
+ path_rewrite_cfg: str | None = None,
109
+ ):
110
+ """
111
+ Runs the task with the provided parameters.
112
+ :param prev_checkpoint: Previous checkpoint path to resume from.
113
+ :param checkpoint_path: Checkpoint path to save the current state.
114
+ :param image_cache: Image cache to use for the task.
115
+ :param name: Action name to run.
116
+ :param run_name: Parent run name to use for the task.
117
+ :param domain: domain to run the task in.
118
+ :param project: project to run the task in.
119
+ :param org: organization to run the task in.
120
+ :param task: The task template to run.
121
+ :param raw_data_path: The path to the raw data.
122
+ :param output_path: The path to save the output.
123
+ :param run_base_dir: The base directory for the run.
124
+ :param version: The version of the task to run.
125
+ :param controller: The controller to use for the task.
126
+ :param code_bundle: Optional code bundle for the task.
127
+ :param input_path: Optional input path for the task.
128
+ :param path_rewrite_cfg: Optional path rewrite configuration.
129
+ :return: The loaded task template.
130
+ """
131
+ start_time = time.time()
132
+ action_id = f"{org}/{project}/{domain}/{run_name}/{name}"
133
+
134
+ logger.info(
135
+ f"[rusty] Running task '{task.name}' (action: {action_id})"
136
+ f" at {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))}"
137
+ )
138
+
139
+ path_rewrite = PathRewrite.from_str(path_rewrite_cfg) if path_rewrite_cfg else None
140
+ if path_rewrite:
141
+ import flyte.storage as storage
142
+
143
+ if not await storage.exists(path_rewrite.new_prefix):
144
+ logger.error(
145
+ f"[rusty] Path rewrite failed for path {path_rewrite.new_prefix}, "
146
+ f"not found, reverting to original path {path_rewrite.old_prefix}"
147
+ )
148
+ path_rewrite = None
149
+ else:
150
+ logger.info(f"[rusty] Using path rewrite: {path_rewrite}")
151
+
152
+ try:
153
+ await contextual_run(
154
+ extract_download_run_upload,
155
+ task,
156
+ action=ActionID(name=name, org=org, project=project, domain=domain, run_name=run_name),
157
+ version=version,
158
+ controller=controller,
159
+ raw_data_path=RawDataPath(path=raw_data_path, path_rewrite=path_rewrite),
160
+ output_path=output_path,
161
+ run_base_dir=run_base_dir,
162
+ checkpoints=Checkpoints(prev_checkpoint_path=prev_checkpoint, checkpoint_path=checkpoint_path),
163
+ code_bundle=code_bundle,
164
+ input_path=input_path,
165
+ image_cache=ImageCache.from_transport(image_cache) if image_cache else None,
166
+ )
167
+ except asyncio.CancelledError as e:
168
+ logger.error(f"[rusty] Task cancellation received: {e!s}")
169
+ raise
170
+ except Exception as e:
171
+ logger.error(f"[rusty] Task failed: {e!s}")
172
+ raise
173
+ finally:
174
+ end_time = time.time()
175
+ duration = end_time - start_time
176
+ logger.info(
177
+ f"[rusty] TASK_EXECUTION_END: Task '{task.name}' (action: {action_id})"
178
+ f" done after {duration:.2f}s at {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))}"
179
+ )
180
+
181
+
182
+ async def ping(name: str) -> str:
183
+ """
184
+ A simple hello world function to test the Rusty entrypoint.
185
+ """
186
+ print(f"Received ping request from {name} in Rusty!")
187
+ return f"pong from Rusty to {name}!"
188
+
189
+
190
+ async def hello(name: str):
191
+ """
192
+ A simple hello world function to test the Rusty entrypoint.
193
+ :param name: The name to greet.
194
+ :return: A greeting message.
195
+ """
196
+ print(f"Received hello request in Rusty with name: {name}!")