Skip to content

Commit bcb4414

Browse files
authored
add workspace to TorchXEvent for logging
Differential Revision: D56324592 Pull Request resolved: #891
1 parent 6df20ea commit bcb4414

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

Diff for: torchx/runner/api.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def run_component(
177177
ComponentNotFoundException: if the ``component_path`` is failed to resolve.
178178
"""
179179

180-
with log_event("run_component") as ctx:
180+
with log_event("run_component", workspace=workspace) as ctx:
181181
dryrun_info = self.dryrun_component(
182182
component,
183183
component_args,
@@ -237,7 +237,9 @@ def run(
237237
An application handle that is used to call other action APIs on the app.
238238
"""
239239

240-
with log_event(api="run", runcfg=json.dumps(cfg) if cfg else None) as ctx:
240+
with log_event(
241+
api="run", runcfg=json.dumps(cfg) if cfg else None, workspace=workspace
242+
) as ctx:
241243
dryrun_info = self.dryrun(
242244
app,
243245
scheduler,
@@ -371,7 +373,12 @@ def dryrun(
371373
role.env[tracker_config_env_var_name(name)] = config
372374

373375
cfg = cfg or dict()
374-
with log_event("dryrun", scheduler, runcfg=json.dumps(cfg) if cfg else None):
376+
with log_event(
377+
"dryrun",
378+
scheduler,
379+
runcfg=json.dumps(cfg) if cfg else None,
380+
workspace=workspace,
381+
):
375382
sched = self._scheduler(scheduler)
376383
resolved_cfg = sched.run_opts().resolve(cfg)
377384
if workspace and isinstance(sched, WorkspaceMixin):

Diff for: torchx/runner/events/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ def __init__(
8585
app_id: Optional[str] = None,
8686
app_image: Optional[str] = None,
8787
runcfg: Optional[str] = None,
88+
workspace: Optional[str] = None,
8889
) -> None:
8990
self._torchx_event: TorchxEvent = self._generate_torchx_event(
90-
api, scheduler or "", app_id, app_image=app_image, runcfg=runcfg
91+
api,
92+
scheduler or "",
93+
app_id,
94+
app_image=app_image,
95+
runcfg=runcfg,
96+
workspace=workspace,
9197
)
9298
self._start_cpu_time_ns = 0
9399
self._start_wall_time_ns = 0
@@ -124,6 +130,7 @@ def _generate_torchx_event(
124130
app_image: Optional[str] = None,
125131
runcfg: Optional[str] = None,
126132
source: SourceType = SourceType.UNKNOWN,
133+
workspace: Optional[str] = None,
127134
) -> TorchxEvent:
128135
return TorchxEvent(
129136
session=app_id or "",
@@ -133,4 +140,5 @@ def _generate_torchx_event(
133140
app_image=app_image,
134141
runcfg=runcfg,
135142
source=source,
143+
workspace=workspace,
136144
)

Diff for: torchx/runner/events/api.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class TorchxEvent:
4747
cpu_time_usec: Optional[int] = None
4848
wall_time_usec: Optional[int] = None
4949
start_epoch_time_usec: Optional[int] = None
50+
workspace: Optional[str] = None
5051

5152
def __str__(self) -> str:
5253
return self.serialize()

Diff for: torchx/runner/events/test/lib_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,22 @@ def test_event_created(self) -> None:
4646
scheduler="test_scheduler",
4747
api="test_api",
4848
app_image="test_app_image",
49+
workspace="test_workspace",
4950
)
5051
self.assertEqual("test_session", event.session)
5152
self.assertEqual("test_scheduler", event.scheduler)
5253
self.assertEqual("test_api", event.api)
5354
self.assertEqual("test_app_image", event.app_image)
5455
self.assertEqual(SourceType.UNKNOWN, event.source)
56+
self.assertEqual("test_workspace", event.workspace)
5557

5658
def test_event_deser(self) -> None:
5759
event = TorchxEvent(
5860
session="test_session",
5961
scheduler="test_scheduler",
6062
api="test_api",
6163
app_image="test_app_image",
64+
workspace="test_workspace",
6265
source=SourceType.EXTERNAL,
6366
)
6467
json_event = event.serialize()
@@ -74,6 +77,7 @@ def assert_torchx_event(self, expected: TorchxEvent, actual: TorchxEvent) -> Non
7477
self.assertEqual(expected.api, actual.api)
7578
self.assertEqual(expected.app_image, actual.app_image)
7679
self.assertEqual(expected.source, actual.source)
80+
self.assertEqual(expected.workspace, actual.workspace)
7781

7882
def test_create_context(self, _) -> None:
7983
cfg = json.dumps({"test_key": "test_value"})
@@ -83,6 +87,7 @@ def test_create_context(self, _) -> None:
8387
"test_app_id",
8488
app_image="test_app_image_id",
8589
runcfg=cfg,
90+
workspace="test_workspace",
8691
)
8792
expected_torchx_event = TorchxEvent(
8893
"test_app_id",
@@ -91,7 +96,9 @@ def test_create_context(self, _) -> None:
9196
"test_app_id",
9297
app_image="test_app_image_id",
9398
runcfg=cfg,
99+
workspace="test_workspace",
94100
)
101+
95102
self.assert_torchx_event(expected_torchx_event, context._torchx_event)
96103

97104
def test_record_event(self, record_mock: MagicMock) -> None:
@@ -102,6 +109,7 @@ def test_record_event(self, record_mock: MagicMock) -> None:
102109
"test_app_id",
103110
app_image="test_app_image_id",
104111
runcfg=cfg,
112+
workspace="test_workspace",
105113
) as ctx:
106114
pass
107115

@@ -112,6 +120,7 @@ def test_record_event(self, record_mock: MagicMock) -> None:
112120
"test_app_id",
113121
app_image="test_app_image_id",
114122
runcfg=cfg,
123+
workspace="test_workspace",
115124
cpu_time_usec=ctx._torchx_event.cpu_time_usec,
116125
wall_time_usec=ctx._torchx_event.wall_time_usec,
117126
)

0 commit comments

Comments
 (0)