torchx-nightly 2025.8.20__py3-none-any.whl → 2025.8.21__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.
- torchx/specs/builders.py +101 -24
- {torchx_nightly-2025.8.20.dist-info → torchx_nightly-2025.8.21.dist-info}/METADATA +1 -1
- {torchx_nightly-2025.8.20.dist-info → torchx_nightly-2025.8.21.dist-info}/RECORD +7 -7
- {torchx_nightly-2025.8.20.dist-info → torchx_nightly-2025.8.21.dist-info}/LICENSE +0 -0
- {torchx_nightly-2025.8.20.dist-info → torchx_nightly-2025.8.21.dist-info}/WHEEL +0 -0
- {torchx_nightly-2025.8.20.dist-info → torchx_nightly-2025.8.21.dist-info}/entry_points.txt +0 -0
- {torchx_nightly-2025.8.20.dist-info → torchx_nightly-2025.8.21.dist-info}/top_level.txt +0 -0
torchx/specs/builders.py
CHANGED
|
@@ -10,7 +10,7 @@ import argparse
|
|
|
10
10
|
import inspect
|
|
11
11
|
import os
|
|
12
12
|
from argparse import Namespace
|
|
13
|
-
from typing import Any, Callable, Dict, List, Mapping, Optional, Union
|
|
13
|
+
from typing import Any, Callable, Dict, List, Mapping, NamedTuple, Optional, Union
|
|
14
14
|
|
|
15
15
|
from torchx.specs.api import BindMount, MountType, VolumeMount
|
|
16
16
|
from torchx.specs.file_linter import get_fn_docstring, TorchXArgumentHelpFormatter
|
|
@@ -19,6 +19,14 @@ from torchx.util.types import decode, decode_optional, get_argparse_param_type,
|
|
|
19
19
|
from .api import AppDef, DeviceMount
|
|
20
20
|
|
|
21
21
|
|
|
22
|
+
class ComponentArgs(NamedTuple):
|
|
23
|
+
"""Parsed component function arguments"""
|
|
24
|
+
|
|
25
|
+
positional_args: dict[str, Any]
|
|
26
|
+
var_args: list[str]
|
|
27
|
+
kwargs: dict[str, Any]
|
|
28
|
+
|
|
29
|
+
|
|
22
30
|
def _create_args_parser(
|
|
23
31
|
cmpnt_fn: Callable[..., AppDef],
|
|
24
32
|
cmpnt_defaults: Optional[Dict[str, str]] = None,
|
|
@@ -140,6 +148,91 @@ def parse_args(
|
|
|
140
148
|
return parsed_args
|
|
141
149
|
|
|
142
150
|
|
|
151
|
+
def component_args_from_str(
|
|
152
|
+
cmpnt_fn: Callable[..., Any], # pyre-fixme[2]: Enforce AppDef type
|
|
153
|
+
cmpnt_args: list[str],
|
|
154
|
+
cmpnt_args_defaults: Optional[Dict[str, Any]] = None,
|
|
155
|
+
config: Optional[Dict[str, Any]] = None,
|
|
156
|
+
) -> ComponentArgs:
|
|
157
|
+
"""
|
|
158
|
+
Parses and decodes command-line arguments for a component function.
|
|
159
|
+
|
|
160
|
+
This function takes a component function and its arguments, parses them using argparse,
|
|
161
|
+
and decodes the arguments into their expected types based on the function's signature.
|
|
162
|
+
It separates positional arguments, variable positional arguments (*args), and keyword-only arguments.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
cmpnt_fn: The component function whose arguments are to be parsed and decoded.
|
|
166
|
+
cmpnt_args: List of command-line arguments to be parsed. Supports both space separated and '=' separated arguments.
|
|
167
|
+
cmpnt_args_defaults: Optional dictionary of default values for the component function's parameters.
|
|
168
|
+
config: Optional dictionary containing additional configuration values.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
ComponentArgs representing the input args to a component function containing:
|
|
172
|
+
- positional_args: Dictionary of positional and positional-or-keyword arguments.
|
|
173
|
+
- var_args: List of variable positional arguments (*args).
|
|
174
|
+
- kwargs: Dictionary of keyword-only arguments.
|
|
175
|
+
|
|
176
|
+
Usage:
|
|
177
|
+
|
|
178
|
+
.. doctest::
|
|
179
|
+
from torchx.specs.api import AppDef
|
|
180
|
+
from torchx.specs.builders import component_args_from_str
|
|
181
|
+
|
|
182
|
+
def example_component_fn(foo: str, *args: str, bar: str = "asdf") -> AppDef:
|
|
183
|
+
return AppDef(name="example")
|
|
184
|
+
|
|
185
|
+
# Supports space separated arguments
|
|
186
|
+
args = ["--foo", "fooval", "--bar", "barval", "arg1", "arg2"]
|
|
187
|
+
parsed_args = component_args_from_str(example_component_fn, args)
|
|
188
|
+
|
|
189
|
+
assert parsed_args.positional_args == {"foo": "fooval"}
|
|
190
|
+
assert parsed_args.var_args == ["arg1", "arg2"]
|
|
191
|
+
assert parsed_args.kwargs == {"bar": "barval"}
|
|
192
|
+
|
|
193
|
+
# Supports '=' separated arguments
|
|
194
|
+
args = ["--foo=fooval", "--bar=barval", "arg1", "arg2"]
|
|
195
|
+
parsed_args = component_args_from_str(example_component_fn, args)
|
|
196
|
+
|
|
197
|
+
assert parsed_args.positional_args == {"foo": "fooval"}
|
|
198
|
+
assert parsed_args.var_args == ["arg1", "arg2"]
|
|
199
|
+
assert parsed_args.kwargs == {"bar": "barval"}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
"""
|
|
203
|
+
parsed_args: Namespace = parse_args(
|
|
204
|
+
cmpnt_fn, cmpnt_args, cmpnt_args_defaults, config
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
positional_args = {}
|
|
208
|
+
var_args = []
|
|
209
|
+
kwargs = {}
|
|
210
|
+
|
|
211
|
+
parameters = inspect.signature(cmpnt_fn).parameters
|
|
212
|
+
for param_name, parameter in parameters.items():
|
|
213
|
+
arg_value = getattr(parsed_args, param_name)
|
|
214
|
+
parameter_type = parameter.annotation
|
|
215
|
+
parameter_type = decode_optional(parameter_type)
|
|
216
|
+
arg_value = decode(arg_value, parameter_type)
|
|
217
|
+
if parameter.kind == inspect.Parameter.VAR_POSITIONAL:
|
|
218
|
+
var_args = arg_value
|
|
219
|
+
elif parameter.kind == inspect.Parameter.KEYWORD_ONLY:
|
|
220
|
+
kwargs[param_name] = arg_value
|
|
221
|
+
elif parameter.kind == inspect.Parameter.VAR_KEYWORD:
|
|
222
|
+
raise TypeError(
|
|
223
|
+
f"component fn param `{param_name}` is a '**kwargs' which is not supported; consider changing the "
|
|
224
|
+
f"type to a dict or explicitly declare the params"
|
|
225
|
+
)
|
|
226
|
+
else:
|
|
227
|
+
# POSITIONAL or POSITIONAL_OR_KEYWORD
|
|
228
|
+
positional_args[param_name] = arg_value
|
|
229
|
+
|
|
230
|
+
if len(var_args) > 0 and var_args[0] == "--":
|
|
231
|
+
var_args = var_args[1:]
|
|
232
|
+
|
|
233
|
+
return ComponentArgs(positional_args, var_args, kwargs)
|
|
234
|
+
|
|
235
|
+
|
|
143
236
|
def materialize_appdef(
|
|
144
237
|
cmpnt_fn: Callable[..., Any], # pyre-ignore[2]
|
|
145
238
|
cmpnt_args: List[str],
|
|
@@ -174,30 +267,14 @@ def materialize_appdef(
|
|
|
174
267
|
An application spec
|
|
175
268
|
"""
|
|
176
269
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
for param_name, parameter in parameters.items():
|
|
185
|
-
arg_value = getattr(parsed_args, param_name)
|
|
186
|
-
parameter_type = parameter.annotation
|
|
187
|
-
parameter_type = decode_optional(parameter_type)
|
|
188
|
-
arg_value = decode(arg_value, parameter_type)
|
|
189
|
-
if parameter.kind == inspect.Parameter.VAR_POSITIONAL:
|
|
190
|
-
var_arg = arg_value
|
|
191
|
-
elif parameter.kind == inspect.Parameter.KEYWORD_ONLY:
|
|
192
|
-
kwargs[param_name] = arg_value
|
|
193
|
-
elif parameter.kind == inspect.Parameter.VAR_KEYWORD:
|
|
194
|
-
raise TypeError("**kwargs are not supported for component definitions")
|
|
195
|
-
else:
|
|
196
|
-
function_args.append(arg_value)
|
|
197
|
-
if len(var_arg) > 0 and var_arg[0] == "--":
|
|
198
|
-
var_arg = var_arg[1:]
|
|
270
|
+
component_args: ComponentArgs = component_args_from_str(
|
|
271
|
+
cmpnt_fn, cmpnt_args, cmpnt_defaults, config
|
|
272
|
+
)
|
|
273
|
+
positional_arg_values = list(component_args.positional_args.values())
|
|
274
|
+
appdef = cmpnt_fn(
|
|
275
|
+
*positional_arg_values, *component_args.var_args, **component_args.kwargs
|
|
276
|
+
)
|
|
199
277
|
|
|
200
|
-
appdef = cmpnt_fn(*function_args, *var_arg, **kwargs)
|
|
201
278
|
if not isinstance(appdef, AppDef):
|
|
202
279
|
raise TypeError(
|
|
203
280
|
f"Expected a component that returns `AppDef`, but got `{type(appdef)}`"
|
|
@@ -84,7 +84,7 @@ torchx/schedulers/ray/ray_common.py,sha256=pyNYFvTKVwdjDAeCBNbPwAWwVNmlLOJWExfn9
|
|
|
84
84
|
torchx/schedulers/ray/ray_driver.py,sha256=RdaCLfth16ky-5PDVOWRe_RuheWJu9xufWux2F9T7iw,12302
|
|
85
85
|
torchx/specs/__init__.py,sha256=c2ALDbqHIhNBhrYxwXXURRwu1Rg5jcwukWF8emEO1Bk,6347
|
|
86
86
|
torchx/specs/api.py,sha256=wkhHOxeWH_tFO3npKqPhNg4VX2NH5gPIFEylkPBo3AU,41315
|
|
87
|
-
torchx/specs/builders.py,sha256=
|
|
87
|
+
torchx/specs/builders.py,sha256=R60CdQvHhpGJ83_cwnJDVa_WAf1E_0Sqm92htJKFZsQ,13665
|
|
88
88
|
torchx/specs/file_linter.py,sha256=QCwob5STTBuy8RsxaevTI-Dk6R8siDJn81LyaOwazes,12333
|
|
89
89
|
torchx/specs/finder.py,sha256=lMCS1hUR-x7j4sAjfJZnKFeS1RlkFTeJtit4EL_ErIo,18182
|
|
90
90
|
torchx/specs/named_resources_aws.py,sha256=ISjHtifRJqB8u7PeAMiyLyO_S0WCaZiK-CFF3qe6JDU,11415
|
|
@@ -115,9 +115,9 @@ torchx/workspace/__init__.py,sha256=FqN8AN4VhR1C_SBY10MggQvNZmyanbbuPuE-JCjkyUY,
|
|
|
115
115
|
torchx/workspace/api.py,sha256=PtDkGTC5lX03pRoYpuMz2KCmM1ZOycRP1UknqvNb97Y,6341
|
|
116
116
|
torchx/workspace/dir_workspace.py,sha256=npNW_IjUZm_yS5r-8hrRkH46ndDd9a_eApT64m1S1T4,2268
|
|
117
117
|
torchx/workspace/docker_workspace.py,sha256=PFu2KQNVC-0p2aKJ-W_BKA9ZOmXdCY2ABEkCExp3udQ,10269
|
|
118
|
-
torchx_nightly-2025.8.
|
|
119
|
-
torchx_nightly-2025.8.
|
|
120
|
-
torchx_nightly-2025.8.
|
|
121
|
-
torchx_nightly-2025.8.
|
|
122
|
-
torchx_nightly-2025.8.
|
|
123
|
-
torchx_nightly-2025.8.
|
|
118
|
+
torchx_nightly-2025.8.21.dist-info/LICENSE,sha256=WVHfXhFC0Ia8LTKt_nJVYobdqTJVg_4J3Crrfm2A8KQ,1721
|
|
119
|
+
torchx_nightly-2025.8.21.dist-info/METADATA,sha256=d8OE6hqXl-kVw-uDpbcKx3z5jH_k6CTmuVA1CIBKIyQ,6104
|
|
120
|
+
torchx_nightly-2025.8.21.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
121
|
+
torchx_nightly-2025.8.21.dist-info/entry_points.txt,sha256=T328AMXeKI3JZnnxfkEew2ZcMN1oQDtkXjMz7lkV-P4,169
|
|
122
|
+
torchx_nightly-2025.8.21.dist-info/top_level.txt,sha256=pxew3bc2gsiViS0zADs0jb6kC5v8o_Yy_85fhHj_J1A,7
|
|
123
|
+
torchx_nightly-2025.8.21.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|