Skip to content

Commit 5a88b4d

Browse files
Xiaolong Wangfacebook-github-bot
authored andcommitted
env TORCHX_CONFIG for specified config (#504)
Summary: Pull Request resolved: #504 design offline discussed Reviewed By: dracifer Differential Revision: D36692686 fbshipit-source-id: 1d7d8872f3562dba8c4dcfa00943e8cf98dff716
1 parent da8dfa9 commit 5a88b4d

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

torchx/runner/config.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@
7070
$ torchx run -s local_cwd ./my_component.py:train
7171
7272
#. In addition, it is possible to specify a different config other than .torchxconfig to
73-
load at runtime. Requirements are that the config name is specified with a suffix and
74-
passed as environment variable TORCHX_CONFIG_SUFFIX, and the .torchxconfig_${suffix}
75-
resides in the current directory. It also disables hierarchy loading configs from
76-
multiple directories as the case without specifying suffix.
73+
load at runtime. Requirements are that the config path is specified by enviornment
74+
variable TORCHX_CONFIG. It also disables hierarchy loading configs from multiple
75+
directories as the cases otherwise.
7776
7877
**Component Config**
7978
@@ -153,7 +152,7 @@ def my_component(a: int) -> specs.AppDef:
153152

154153

155154
CONFIG_FILE = ".torchxconfig"
156-
ENV_TORCHX_CONFIG_SUFFIX = "TORCHX_CONFIG_SUFFIX"
155+
ENV_TORCHX_CONFIG = "TORCHX_CONFIG"
157156
CONFIG_PREFIX_DELIM = ":"
158157

159158
_NONE = "None"
@@ -433,16 +432,16 @@ def get_config(
433432
def find_configs(dirs: Optional[Iterable[str]] = None) -> List[str]:
434433
"""
435434
find_configs returns all the .torchxconfig files it finds:
436-
- if environment variable TORCHX_CONFIG_SUFFIX is specified, then
437-
./torchxconfig_suffix is expected and will be loaded as the only config
435+
- if environment variable TORCHX_CONFIG is specified, then
436+
it is expected to exists and will be loaded as the only config
438437
- otherwise, directories are checked to look for .torchxconfig and loaded. If
439438
directories is empty it checks the local directory.
440439
"""
441440

442441
config_files = []
443-
suffix = os.getenv(ENV_TORCHX_CONFIG_SUFFIX, "")
444-
if len(suffix) > 0:
445-
configfile = Path.cwd() / (CONFIG_FILE + "." + suffix)
442+
config = os.getenv(ENV_TORCHX_CONFIG, "")
443+
if len(config) > 0:
444+
configfile = Path(config)
446445
assert configfile.exists(), f"{str(configfile)} expected but not found"
447446
config_files.append(str(configfile))
448447
else:

torchx/runner/test/config_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def setUp(self) -> None:
186186
_MY_CONFIG,
187187
)
188188
self._write(
189-
".torchxconfig.suffixtest",
189+
f"{self.test_dir}/another_torchx_config",
190190
_MY_CONFIG2,
191191
)
192192

@@ -332,12 +332,12 @@ def test_apply_dirs(self, _) -> None:
332332
TORCHX_GET_SCHEDULERS,
333333
return_value={"test": TestScheduler()},
334334
)
335-
def test_apply_from_suffix_config(self, _) -> None:
335+
def test_apply_from_annotated_config(self, _) -> None:
336336
def mock_getenv(x: str, y: Optional[str] = None) -> Optional[str]:
337-
if x != "TORCHX_CONFIG_SUFFIX":
337+
if x != "TORCHX_CONFIG":
338338
return os.environ.get(x, y)
339339
else:
340-
return "suffixtest"
340+
return f"{self.test_dir}/another_torchx_config"
341341

342342
with patch(PATH_CWD, return_value=Path(self.test_dir)):
343343
with patch(

0 commit comments

Comments
 (0)