Skip to content

add workspace to TorchXEvent for logging #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions torchx/runner/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run_component(
ComponentNotFoundException: if the ``component_path`` is failed to resolve.
"""

with log_event("run_component") as ctx:
with log_event("run_component", workspace=workspace) as ctx:
dryrun_info = self.dryrun_component(
component,
component_args,
Expand All @@ -187,6 +187,7 @@ def run_component(
parent_run_id=parent_run_id,
)
handle = self.schedule(dryrun_info)
ctx._torchx_event.workspace = workspace
ctx._torchx_event.scheduler = none_throws(dryrun_info._scheduler)
ctx._torchx_event.app_image = none_throws(dryrun_info._app).roles[0].image
ctx._torchx_event.app_id = parse_app_handle(handle)[2]
Expand Down Expand Up @@ -237,7 +238,9 @@ def run(
An application handle that is used to call other action APIs on the app.
"""

with log_event(api="run", runcfg=json.dumps(cfg) if cfg else None) as ctx:
with log_event(
api="run", runcfg=json.dumps(cfg) if cfg else None, workspace=workspace
) as ctx:
dryrun_info = self.dryrun(
app,
scheduler,
Expand Down Expand Up @@ -371,7 +374,12 @@ def dryrun(
role.env[tracker_config_env_var_name(name)] = config

cfg = cfg or dict()
with log_event("dryrun", scheduler, runcfg=json.dumps(cfg) if cfg else None):
with log_event(
"dryrun",
scheduler,
runcfg=json.dumps(cfg) if cfg else None,
workspace=workspace,
):
sched = self._scheduler(scheduler)
resolved_cfg = sched.run_opts().resolve(cfg)
if workspace and isinstance(sched, WorkspaceMixin):
Expand Down
10 changes: 9 additions & 1 deletion torchx/runner/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ def __init__(
app_id: Optional[str] = None,
app_image: Optional[str] = None,
runcfg: Optional[str] = None,
workspace: Optional[str] = None,
) -> None:
self._torchx_event: TorchxEvent = self._generate_torchx_event(
api, scheduler or "", app_id, app_image=app_image, runcfg=runcfg
api,
scheduler or "",
app_id,
app_image=app_image,
runcfg=runcfg,
workspace=workspace,
)
self._start_cpu_time_ns = 0
self._start_wall_time_ns = 0
Expand Down Expand Up @@ -124,6 +130,7 @@ def _generate_torchx_event(
app_image: Optional[str] = None,
runcfg: Optional[str] = None,
source: SourceType = SourceType.UNKNOWN,
workspace: Optional[str] = None,
) -> TorchxEvent:
return TorchxEvent(
session=app_id or "",
Expand All @@ -133,4 +140,5 @@ def _generate_torchx_event(
app_image=app_image,
runcfg=runcfg,
source=source,
workspace=workspace,
)
1 change: 1 addition & 0 deletions torchx/runner/events/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TorchxEvent:
cpu_time_usec: Optional[int] = None
wall_time_usec: Optional[int] = None
start_epoch_time_usec: Optional[int] = None
workspace: Optional[str] = None

def __str__(self) -> str:
return self.serialize()
Expand Down
9 changes: 9 additions & 0 deletions torchx/runner/events/test/lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,22 @@ def test_event_created(self) -> None:
scheduler="test_scheduler",
api="test_api",
app_image="test_app_image",
workspace="test_workspace",
)
self.assertEqual("test_session", event.session)
self.assertEqual("test_scheduler", event.scheduler)
self.assertEqual("test_api", event.api)
self.assertEqual("test_app_image", event.app_image)
self.assertEqual(SourceType.UNKNOWN, event.source)
self.assertEqual("test_workspace", event.workspace)

def test_event_deser(self) -> None:
event = TorchxEvent(
session="test_session",
scheduler="test_scheduler",
api="test_api",
app_image="test_app_image",
workspace="test_workspace",
source=SourceType.EXTERNAL,
)
json_event = event.serialize()
Expand All @@ -74,6 +77,7 @@ def assert_torchx_event(self, expected: TorchxEvent, actual: TorchxEvent) -> Non
self.assertEqual(expected.api, actual.api)
self.assertEqual(expected.app_image, actual.app_image)
self.assertEqual(expected.source, actual.source)
self.assertEqual(expected.workspace, actual.workspace)

def test_create_context(self, _) -> None:
cfg = json.dumps({"test_key": "test_value"})
Expand All @@ -83,6 +87,7 @@ def test_create_context(self, _) -> None:
"test_app_id",
app_image="test_app_image_id",
runcfg=cfg,
workspace="test_workspace",
)
expected_torchx_event = TorchxEvent(
"test_app_id",
Expand All @@ -91,7 +96,9 @@ def test_create_context(self, _) -> None:
"test_app_id",
app_image="test_app_image_id",
runcfg=cfg,
workspace="test_workspace",
)

self.assert_torchx_event(expected_torchx_event, context._torchx_event)

def test_record_event(self, record_mock: MagicMock) -> None:
Expand All @@ -102,6 +109,7 @@ def test_record_event(self, record_mock: MagicMock) -> None:
"test_app_id",
app_image="test_app_image_id",
runcfg=cfg,
workspace="test_workspace",
) as ctx:
pass

Expand All @@ -112,6 +120,7 @@ def test_record_event(self, record_mock: MagicMock) -> None:
"test_app_id",
app_image="test_app_image_id",
runcfg=cfg,
workspace="test_workspace",
cpu_time_usec=ctx._torchx_event.cpu_time_usec,
wall_time_usec=ctx._torchx_event.wall_time_usec,
)
Expand Down
Loading