torchx-nightly 2025.8.20__py3-none-any.whl → 2025.8.22__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.

@@ -1159,6 +1159,7 @@ class LogIterator:
1159
1159
  self._check_finished() # check to see if app has finished running
1160
1160
 
1161
1161
  if os.path.isfile(self._log_file):
1162
+ time.sleep(0.1) # fix timing issue
1162
1163
  self._log_fp = open(
1163
1164
  self._log_file,
1164
1165
  mode="rt",
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
- function_args = []
178
- var_arg = []
179
- kwargs = {}
180
-
181
- parsed_args = parse_args(cmpnt_fn, cmpnt_args, cmpnt_defaults, config)
182
-
183
- parameters = inspect.signature(cmpnt_fn).parameters
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)}`"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: torchx-nightly
3
- Version: 2025.8.20
3
+ Version: 2025.8.22
4
4
  Summary: TorchX SDK and Components
5
5
  Home-page: https://github.com/pytorch/torchx
6
6
  Author: TorchX Devs
@@ -74,7 +74,7 @@ torchx/schedulers/gcp_batch_scheduler.py,sha256=JQuaEJVL_7NSa9AeUc_0Qo74XZNJk_kp
74
74
  torchx/schedulers/ids.py,sha256=3E-_vwVYC-8Tv8kjuY9-W7TbOe_-Laqd8a65uIN3hQY,1798
75
75
  torchx/schedulers/kubernetes_mcad_scheduler.py,sha256=1tuzq3OutCMdSPqg_dNmCHt_wyuSFKG0-ywLc3qITJo,42949
76
76
  torchx/schedulers/kubernetes_scheduler.py,sha256=0_loGJ7WnxEr9dhgFt3Gw-7nVLirMDVN-MAFTCq7erE,28217
77
- torchx/schedulers/local_scheduler.py,sha256=lOtVtmMIhytdju1Dlc3p99VALMY3qYRDPqjxdyTAbQQ,41877
77
+ torchx/schedulers/local_scheduler.py,sha256=ttnxFDy48_DSYDEW-no27OirFZOyfrjwJ2S1MwBUi74,41929
78
78
  torchx/schedulers/lsf_scheduler.py,sha256=YS6Yel8tXJqLPxbcGz95lZG2nCi36AQXdNDyuBJePKg,17661
79
79
  torchx/schedulers/ray_scheduler.py,sha256=T-jsGSOa8O-h1kTUU7Q7Fk1RILL1Yzvuos_WFSQF8Fo,15795
80
80
  torchx/schedulers/slurm_scheduler.py,sha256=GlHGZBIklIyvBxxzw2CtFvCBmLQGCy_o8kf5lf411Ng,28592
@@ -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=f5Yy8KoL2OgPUiqJRkZ4E6lboq5Srkh5mD17F0EBdeg,10506
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.20.dist-info/LICENSE,sha256=WVHfXhFC0Ia8LTKt_nJVYobdqTJVg_4J3Crrfm2A8KQ,1721
119
- torchx_nightly-2025.8.20.dist-info/METADATA,sha256=CJUK_Qtonba1BfbkhD7aGRxC8hqa6KfGV2n6tcwUBFE,6104
120
- torchx_nightly-2025.8.20.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
121
- torchx_nightly-2025.8.20.dist-info/entry_points.txt,sha256=T328AMXeKI3JZnnxfkEew2ZcMN1oQDtkXjMz7lkV-P4,169
122
- torchx_nightly-2025.8.20.dist-info/top_level.txt,sha256=pxew3bc2gsiViS0zADs0jb6kC5v8o_Yy_85fhHj_J1A,7
123
- torchx_nightly-2025.8.20.dist-info/RECORD,,
118
+ torchx_nightly-2025.8.22.dist-info/LICENSE,sha256=WVHfXhFC0Ia8LTKt_nJVYobdqTJVg_4J3Crrfm2A8KQ,1721
119
+ torchx_nightly-2025.8.22.dist-info/METADATA,sha256=7kaWelQVEvJlxHiJgop63Yih7fl92ks46ixiqhwbeIw,6104
120
+ torchx_nightly-2025.8.22.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
121
+ torchx_nightly-2025.8.22.dist-info/entry_points.txt,sha256=T328AMXeKI3JZnnxfkEew2ZcMN1oQDtkXjMz7lkV-P4,169
122
+ torchx_nightly-2025.8.22.dist-info/top_level.txt,sha256=pxew3bc2gsiViS0zADs0jb6kC5v8o_Yy_85fhHj_J1A,7
123
+ torchx_nightly-2025.8.22.dist-info/RECORD,,