torchx-nightly 2024.1.6__py3-none-any.whl → 2025.12.24__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 torchx-nightly might be problematic. Click here for more details.

Files changed (110) hide show
  1. torchx/__init__.py +2 -0
  2. torchx/{schedulers/ray/__init__.py → _version.py} +3 -1
  3. torchx/apps/serve/serve.py +2 -0
  4. torchx/apps/utils/booth_main.py +2 -0
  5. torchx/apps/utils/copy_main.py +2 -0
  6. torchx/apps/utils/process_monitor.py +2 -0
  7. torchx/cli/__init__.py +2 -0
  8. torchx/cli/argparse_util.py +38 -3
  9. torchx/cli/cmd_base.py +2 -0
  10. torchx/cli/cmd_cancel.py +2 -0
  11. torchx/cli/cmd_configure.py +2 -0
  12. torchx/cli/cmd_delete.py +30 -0
  13. torchx/cli/cmd_describe.py +2 -0
  14. torchx/cli/cmd_list.py +8 -4
  15. torchx/cli/cmd_log.py +6 -24
  16. torchx/cli/cmd_run.py +269 -45
  17. torchx/cli/cmd_runopts.py +2 -0
  18. torchx/cli/cmd_status.py +12 -1
  19. torchx/cli/cmd_tracker.py +3 -1
  20. torchx/cli/colors.py +2 -0
  21. torchx/cli/main.py +4 -0
  22. torchx/components/__init__.py +3 -8
  23. torchx/components/component_test_base.py +2 -0
  24. torchx/components/dist.py +18 -7
  25. torchx/components/integration_tests/component_provider.py +4 -2
  26. torchx/components/integration_tests/integ_tests.py +2 -0
  27. torchx/components/serve.py +2 -0
  28. torchx/components/structured_arg.py +4 -3
  29. torchx/components/utils.py +15 -4
  30. torchx/distributed/__init__.py +2 -4
  31. torchx/examples/apps/datapreproc/datapreproc.py +2 -0
  32. torchx/examples/apps/lightning/data.py +5 -3
  33. torchx/examples/apps/lightning/model.py +7 -6
  34. torchx/examples/apps/lightning/profiler.py +7 -4
  35. torchx/examples/apps/lightning/train.py +11 -2
  36. torchx/examples/torchx_out_of_sync_training.py +11 -0
  37. torchx/notebook.py +2 -0
  38. torchx/runner/__init__.py +2 -0
  39. torchx/runner/api.py +167 -60
  40. torchx/runner/config.py +43 -10
  41. torchx/runner/events/__init__.py +57 -13
  42. torchx/runner/events/api.py +14 -3
  43. torchx/runner/events/handlers.py +2 -0
  44. torchx/runtime/tracking/__init__.py +2 -0
  45. torchx/runtime/tracking/api.py +2 -0
  46. torchx/schedulers/__init__.py +16 -15
  47. torchx/schedulers/api.py +70 -14
  48. torchx/schedulers/aws_batch_scheduler.py +75 -6
  49. torchx/schedulers/aws_sagemaker_scheduler.py +598 -0
  50. torchx/schedulers/devices.py +17 -4
  51. torchx/schedulers/docker_scheduler.py +43 -11
  52. torchx/schedulers/ids.py +29 -23
  53. torchx/schedulers/kubernetes_mcad_scheduler.py +9 -7
  54. torchx/schedulers/kubernetes_scheduler.py +383 -38
  55. torchx/schedulers/local_scheduler.py +100 -27
  56. torchx/schedulers/lsf_scheduler.py +5 -4
  57. torchx/schedulers/slurm_scheduler.py +336 -20
  58. torchx/schedulers/streams.py +2 -0
  59. torchx/specs/__init__.py +89 -12
  60. torchx/specs/api.py +418 -30
  61. torchx/specs/builders.py +176 -38
  62. torchx/specs/file_linter.py +143 -57
  63. torchx/specs/finder.py +68 -28
  64. torchx/specs/named_resources_aws.py +181 -4
  65. torchx/specs/named_resources_generic.py +2 -0
  66. torchx/specs/overlays.py +106 -0
  67. torchx/specs/test/components/__init__.py +2 -0
  68. torchx/specs/test/components/a/__init__.py +2 -0
  69. torchx/specs/test/components/a/b/__init__.py +2 -0
  70. torchx/specs/test/components/a/b/c.py +2 -0
  71. torchx/specs/test/components/c/__init__.py +2 -0
  72. torchx/specs/test/components/c/d.py +2 -0
  73. torchx/tracker/__init__.py +12 -6
  74. torchx/tracker/api.py +15 -18
  75. torchx/tracker/backend/fsspec.py +2 -0
  76. torchx/util/cuda.py +2 -0
  77. torchx/util/datetime.py +2 -0
  78. torchx/util/entrypoints.py +39 -15
  79. torchx/util/io.py +2 -0
  80. torchx/util/log_tee_helpers.py +210 -0
  81. torchx/util/modules.py +65 -0
  82. torchx/util/session.py +42 -0
  83. torchx/util/shlex.py +2 -0
  84. torchx/util/strings.py +3 -1
  85. torchx/util/types.py +90 -29
  86. torchx/version.py +4 -2
  87. torchx/workspace/__init__.py +2 -0
  88. torchx/workspace/api.py +136 -6
  89. torchx/workspace/dir_workspace.py +2 -0
  90. torchx/workspace/docker_workspace.py +30 -2
  91. torchx_nightly-2025.12.24.dist-info/METADATA +167 -0
  92. torchx_nightly-2025.12.24.dist-info/RECORD +113 -0
  93. {torchx_nightly-2024.1.6.dist-info → torchx_nightly-2025.12.24.dist-info}/WHEEL +1 -1
  94. {torchx_nightly-2024.1.6.dist-info → torchx_nightly-2025.12.24.dist-info}/entry_points.txt +0 -1
  95. torchx/examples/pipelines/__init__.py +0 -0
  96. torchx/examples/pipelines/kfp/__init__.py +0 -0
  97. torchx/examples/pipelines/kfp/advanced_pipeline.py +0 -287
  98. torchx/examples/pipelines/kfp/dist_pipeline.py +0 -69
  99. torchx/examples/pipelines/kfp/intro_pipeline.py +0 -81
  100. torchx/pipelines/kfp/__init__.py +0 -28
  101. torchx/pipelines/kfp/adapter.py +0 -271
  102. torchx/pipelines/kfp/version.py +0 -17
  103. torchx/schedulers/gcp_batch_scheduler.py +0 -487
  104. torchx/schedulers/ray/ray_common.py +0 -22
  105. torchx/schedulers/ray/ray_driver.py +0 -307
  106. torchx/schedulers/ray_scheduler.py +0 -453
  107. torchx_nightly-2024.1.6.dist-info/METADATA +0 -176
  108. torchx_nightly-2024.1.6.dist-info/RECORD +0 -118
  109. {torchx_nightly-2024.1.6.dist-info → torchx_nightly-2025.12.24.dist-info/licenses}/LICENSE +0 -0
  110. {torchx_nightly-2024.1.6.dist-info → torchx_nightly-2025.12.24.dist-info}/top_level.txt +0 -0
@@ -1,271 +0,0 @@
1
- #!/usr/bin/env python3
2
- # Copyright (c) Meta Platforms, Inc. and affiliates.
3
- # All rights reserved.
4
- #
5
- # This source code is licensed under the BSD-style license found in the
6
- # LICENSE file in the root directory of this source tree.
7
-
8
- import json
9
- import os
10
- import os.path
11
- import shlex
12
- from typing import Mapping, Optional, Tuple
13
-
14
- import yaml
15
- from kfp import components, dsl
16
-
17
- # @manual=fbsource//third-party/pypi/kfp:kfp
18
- from kfp.components.structures import ComponentSpec, OutputSpec
19
- from kubernetes.client.models import (
20
- V1ContainerPort,
21
- V1EmptyDirVolumeSource,
22
- V1Volume,
23
- V1VolumeMount,
24
- )
25
- from torchx.schedulers.kubernetes_scheduler import app_to_resource, pod_labels
26
- from torchx.specs import api
27
- from typing_extensions import Protocol
28
-
29
- from .version import __version__ as __version__ # noqa F401
30
-
31
-
32
- def component_spec_from_app(app: api.AppDef) -> Tuple[str, api.Role]:
33
- """
34
- component_spec_from_app takes in a TorchX component and generates the yaml
35
- spec for it. Notably this doesn't apply resources or port_maps since those
36
- must be applied at runtime which is why it returns the role spec as well.
37
-
38
- >>> from torchx import specs
39
- >>> from torchx.pipelines.kfp.adapter import component_spec_from_app
40
- >>> app_def = specs.AppDef(
41
- ... name="trainer",
42
- ... roles=[specs.Role("trainer", image="foo:latest")],
43
- ... )
44
- >>> component_spec_from_app(app_def)
45
- ('description: ...', Role(...))
46
- """
47
- assert len(app.roles) == 1, f"KFP adapter only support one role, got {app.roles}"
48
-
49
- role = app.roles[0]
50
- assert (
51
- role.num_replicas == 1
52
- ), f"KFP adapter only supports one replica, got {app.num_replicas}"
53
-
54
- command = [role.entrypoint, *role.args]
55
-
56
- spec = {
57
- "name": f"{app.name}-{role.name}",
58
- "description": f"KFP wrapper for TorchX component {app.name}, role {role.name}",
59
- "implementation": {
60
- "container": {
61
- "image": role.image,
62
- "command": command,
63
- "env": role.env,
64
- }
65
- },
66
- "outputs": [],
67
- }
68
- return yaml.dump(spec), role
69
-
70
-
71
- class ContainerFactory(Protocol):
72
- """
73
- ContainerFactory is a protocol that represents a function that when called produces a
74
- kfp.dsl.ContainerOp.
75
- """
76
-
77
- def __call__(self, *args: object, **kwargs: object) -> dsl.ContainerOp:
78
- ...
79
-
80
-
81
- class KFPContainerFactory(ContainerFactory, Protocol):
82
- """
83
- KFPContainerFactory is a ContainerFactory that also has some KFP metadata
84
- attached to it.
85
- """
86
-
87
- component_spec: ComponentSpec
88
-
89
-
90
- METADATA_FILE = "/tmp/outputs/mlpipeline-ui-metadata/data.json"
91
-
92
-
93
- def component_from_app(
94
- app: api.AppDef, ui_metadata: Optional[Mapping[str, object]] = None
95
- ) -> ContainerFactory:
96
- """
97
- component_from_app takes in a TorchX component/AppDef and returns a KFP
98
- ContainerOp factory. This is equivalent to the
99
- `kfp.components.load_component_from_*
100
- <https://kubeflow-pipelines.readthedocs.io/en/1.8.22/source/kfp.components.html#kfp.components.load_component_from_text>`_
101
- methods.
102
-
103
- Args:
104
- app: The AppDef to generate a KFP container factory for.
105
- ui_metadata: KFP UI Metadata to output so you can have model results show
106
- up in the UI. See
107
- https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/
108
- for more info on the format.
109
-
110
- >>> from torchx import specs
111
- >>> from torchx.pipelines.kfp.adapter import component_from_app
112
- >>> app_def = specs.AppDef(
113
- ... name="trainer",
114
- ... roles=[specs.Role("trainer", image="foo:latest")],
115
- ... )
116
- >>> component_from_app(app_def)
117
- <function component_from_app...>
118
- """
119
-
120
- role_spec: api.Role
121
- spec, role_spec = component_spec_from_app(app)
122
- resources: api.Resource = role_spec.resource
123
- assert (
124
- len(resources.capabilities) == 0
125
- ), f"KFP doesn't support capabilities, got {resources.capabilities}"
126
- component_factory: KFPContainerFactory = components.load_component_from_text(spec)
127
-
128
- if ui_metadata is not None:
129
- # pyre-fixme[16]: `ComponentSpec` has no attribute `outputs`
130
- component_factory.component_spec.outputs.append(
131
- OutputSpec(
132
- name="mlpipeline-ui-metadata",
133
- type="MLPipeline UI Metadata",
134
- description="ui metadata",
135
- )
136
- )
137
-
138
- def factory_wrapper(*args: object, **kwargs: object) -> dsl.ContainerOp:
139
- c = component_factory(*args, **kwargs)
140
- container = c.container
141
-
142
- if ui_metadata is not None:
143
- # We generate the UI metadata from the sidecar so we need to make
144
- # both the container and the sidecar share the same tmp directory so
145
- # the outputs appear in the original container.
146
- c.add_volume(V1Volume(name="tmp", empty_dir=V1EmptyDirVolumeSource()))
147
- container.add_volume_mount(
148
- V1VolumeMount(
149
- name="tmp",
150
- mount_path="/tmp/",
151
- )
152
- )
153
- c.output_artifact_paths["mlpipeline-ui-metadata"] = METADATA_FILE
154
- c.add_sidecar(_ui_metadata_sidecar(ui_metadata))
155
-
156
- cpu = resources.cpu
157
- if cpu >= 0:
158
- cpu_str = f"{int(cpu*1000)}m"
159
- container.set_cpu_request(cpu_str)
160
- container.set_cpu_limit(cpu_str)
161
- mem = resources.memMB
162
- if mem >= 0:
163
- mem_str = f"{int(mem)}M"
164
- container.set_memory_request(mem_str)
165
- container.set_memory_limit(mem_str)
166
- gpu = resources.gpu
167
- if gpu > 0:
168
- container.set_gpu_limit(str(gpu))
169
-
170
- for name, port in role_spec.port_map.items():
171
- container.add_port(
172
- V1ContainerPort(
173
- name=name,
174
- container_port=port,
175
- ),
176
- )
177
-
178
- c.pod_labels.update(pod_labels(app, 0, role_spec, 0, app.name))
179
-
180
- return c
181
-
182
- return factory_wrapper
183
-
184
-
185
- def _ui_metadata_sidecar(
186
- ui_metadata: Mapping[str, object], image: str = "alpine"
187
- ) -> dsl.Sidecar:
188
- shell_encoded = shlex.quote(json.dumps(ui_metadata))
189
- dirname = os.path.dirname(METADATA_FILE)
190
- return dsl.Sidecar(
191
- name="ui-metadata-sidecar",
192
- image=image,
193
- command=[
194
- "sh",
195
- "-c",
196
- f"mkdir -p {dirname}; echo {shell_encoded} > {METADATA_FILE}",
197
- ],
198
- mirror_volume_mounts=True,
199
- )
200
-
201
-
202
- def container_from_app(
203
- app: api.AppDef,
204
- *args: object,
205
- ui_metadata: Optional[Mapping[str, object]] = None,
206
- **kwargs: object,
207
- ) -> dsl.ContainerOp:
208
- """
209
- container_from_app transforms the app into a KFP component and returns a
210
- corresponding ContainerOp instance.
211
-
212
- See component_from_app for description on the arguments. Any unspecified
213
- arguments are passed through to the KFP container factory method.
214
-
215
- >>> import kfp
216
- >>> from torchx import specs
217
- >>> from torchx.pipelines.kfp.adapter import container_from_app
218
- >>> app_def = specs.AppDef(
219
- ... name="trainer",
220
- ... roles=[specs.Role("trainer", image="foo:latest")],
221
- ... )
222
- >>> def pipeline():
223
- ... trainer = container_from_app(app_def)
224
- ... print(trainer)
225
- >>> kfp.compiler.Compiler().compile(
226
- ... pipeline_func=pipeline,
227
- ... package_path="/tmp/pipeline.yaml",
228
- ... )
229
- {'ContainerOp': {... 'name': 'trainer-trainer', ...}}
230
- """
231
- factory = component_from_app(app, ui_metadata)
232
- return factory(*args, **kwargs)
233
-
234
-
235
- def resource_from_app(
236
- app: api.AppDef,
237
- queue: str,
238
- service_account: Optional[str] = None,
239
- ) -> dsl.ResourceOp:
240
- """
241
- resource_from_app generates a KFP ResourceOp from the provided app that uses
242
- the Volcano job scheduler on Kubernetes to run distributed apps. See
243
- https://volcano.sh/en/docs/ for more info on Volcano and how to install.
244
-
245
- Args:
246
- app: The torchx AppDef to adapt.
247
- queue: the Volcano queue to schedule the operator in.
248
-
249
- >>> import kfp
250
- >>> from torchx import specs
251
- >>> from torchx.pipelines.kfp.adapter import resource_from_app
252
- >>> app_def = specs.AppDef(
253
- ... name="trainer",
254
- ... roles=[specs.Role("trainer", image="foo:latest", num_replicas=3)],
255
- ... )
256
- >>> def pipeline():
257
- ... trainer = resource_from_app(app_def, queue="test")
258
- ... print(trainer)
259
- >>> kfp.compiler.Compiler().compile(
260
- ... pipeline_func=pipeline,
261
- ... package_path="/tmp/pipeline.yaml",
262
- ... )
263
- {'ResourceOp': {... 'name': 'trainer-0', ... 'name': 'trainer-1', ... 'name': 'trainer-2', ...}}
264
- """
265
- return dsl.ResourceOp(
266
- name=app.name,
267
- action="create",
268
- success_condition="status.state.phase = Completed",
269
- failure_condition="status.state.phase = Failed",
270
- k8s_resource=app_to_resource(app, queue, service_account=service_account),
271
- )
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env python3
2
- # Copyright (c) Meta Platforms, Inc. and affiliates.
3
- # All rights reserved.
4
- #
5
- # This source code is licensed under the BSD-style license found in the
6
- # LICENSE file in the root directory of this source tree.
7
-
8
- # Follows PEP-0440 version scheme guidelines
9
- # https://www.python.org/dev/peps/pep-0440/#version-scheme
10
- #
11
- # Examples:
12
- # 0.1.0.devN # Developmental release
13
- # 0.1.0aN # Alpha release
14
- # 0.1.0bN # Beta release
15
- # 0.1.0rcN # Release Candidate
16
- # 0.1.0 # Final release
17
- __version__ = "0.1.0.dev0"