Skip to content

Commit 413db85

Browse files
authored
Resolve run_opts before passing it to the workspace (#755) (#755)
Summary: Pull Request resolved: #755 We were resolving the default values for runopts during the dryrun call on the scheduler. This made the ops passed to the workspace not have the defaults correctly populated for workspace opts. This change also resolves the runopts in the runner dryrun and scheduler submit apis. Haven't removed the runopts resolution in scheduler dry run here as a lot of other tests broke with it and it seems reasonable to also have runopts resolved for just the scheduler dryrun. The double resolving of runopts for the runner dryrun and scheduler submit cases shouldnt cause any meaningful differences. There is a separate question on whether workspace should also be built during scheduler dryrun but that can be a follow up change. Differential Revision: D48395915 fbshipit-source-id: c076e933fe3b8c64ff1d9a6b68c37815f73ab060
1 parent 744706b commit 413db85

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

torchx/runner/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def dryrun(
357357
cfg = cfg or dict()
358358
with log_event("dryrun", scheduler, runcfg=json.dumps(cfg) if cfg else None):
359359
sched = self._scheduler(scheduler)
360-
360+
resolved_cfg = sched.run_opts().resolve(cfg)
361361
if workspace and isinstance(sched, WorkspaceMixin):
362362
role = app.roles[0]
363363
old_img = role.image
@@ -366,7 +366,7 @@ def dryrun(
366366
logger.info(
367367
'To disable workspaces pass: --workspace="" from CLI or workspace=None programmatically.'
368368
)
369-
sched.build_workspace_and_update_role(role, workspace, cfg)
369+
sched.build_workspace_and_update_role(role, workspace, resolved_cfg)
370370

371371
if old_img != role.image:
372372
logger.info(
@@ -380,7 +380,7 @@ def dryrun(
380380
)
381381

382382
sched._validate(app, scheduler)
383-
dryrun_info = sched.submit_dryrun(app, cfg)
383+
dryrun_info = sched.submit_dryrun(app, resolved_cfg)
384384
dryrun_info._scheduler = scheduler
385385
return dryrun_info
386386

torchx/runner/test/api_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def test_run(self, _) -> None:
114114

115115
def test_dryrun(self, _) -> None:
116116
scheduler_mock = MagicMock()
117+
scheduler_mock.run_opts.return_value.resolve.return_value = {
118+
**self.cfg,
119+
"foo": "bar",
120+
}
117121
with Runner(
118122
name=SESSION_NAME,
119123
scheduler_factories={"local_dir": lambda name: scheduler_mock},
@@ -127,7 +131,9 @@ def test_dryrun(self, _) -> None:
127131
)
128132
app = AppDef("name", roles=[role])
129133
runner.dryrun(app, "local_dir", cfg=self.cfg)
130-
scheduler_mock.submit_dryrun.assert_called_once_with(app, self.cfg)
134+
scheduler_mock.submit_dryrun.assert_called_once_with(
135+
app, {**self.cfg, "foo": "bar"}
136+
)
131137
scheduler_mock._validate.assert_called_once()
132138

133139
def test_dryrun_env_variables(self, _) -> None:

torchx/schedulers/api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,15 @@ def submit(
136136
Returns:
137137
The application id that uniquely identifies the submitted app.
138138
"""
139+
# pyre-fixme: Generic cfg type passed to resolve
140+
resolved_cfg = self.run_opts().resolve(cfg)
139141
if workspace:
140142
sched = self
141143
assert isinstance(sched, WorkspaceMixin)
142144
role = app.roles[0]
143-
sched.build_workspace_and_update_role(role, workspace, cfg)
144-
dryrun_info = self.submit_dryrun(app, cfg)
145+
sched.build_workspace_and_update_role(role, workspace, resolved_cfg)
146+
# pyre-fixme: submit_dryrun takes Generic type for resolved_cfg
147+
dryrun_info = self.submit_dryrun(app, resolved_cfg)
145148
return self.schedule(dryrun_info)
146149

147150
@abc.abstractmethod

torchx/schedulers/test/api_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def test_submit_workspace(self) -> None:
108108

109109
scheduler_mock = SchedulerTest.MockScheduler("test_session")
110110

111-
bad_type_cfg = {"foo": "asdf"}
112-
scheduler_mock.submit(app, bad_type_cfg, workspace="some_workspace")
111+
cfg = {"foo": "asdf"}
112+
scheduler_mock.submit(app, cfg, workspace="some_workspace")
113113
self.assertEqual(app.roles[0].image, "some_workspace")
114114

115115
def test_invalid_dryrun_cfg(self) -> None:

0 commit comments

Comments
 (0)