Skip to content
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

torchx - add exception_type and exception_message to torchx event #966

Merged
merged 1 commit into from
Oct 16, 2024
Merged
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
16 changes: 16 additions & 0 deletions torchx/runner/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

"""

import json
import logging
import sys
import time
import traceback
from types import TracebackType
Expand Down Expand Up @@ -123,6 +125,20 @@ def __exit__(
) // 1000
if traceback_type:
self._torchx_event.raw_exception = traceback.format_exc()
typ, value, tb = sys.exc_info()
if tb:
last_frame = traceback.extract_tb(tb)[-1]
self._torchx_event.exception_source_location = json.dumps(
{
"filename": last_frame.filename,
"lineno": last_frame.lineno,
"name": last_frame.name,
}
)
if exec_type:
self._torchx_event.exception_type = exec_type.__name__
if exec_value:
self._torchx_event.exception_message = str(exec_value)
record(self._torchx_event)

def _generate_torchx_event(
Expand Down
3 changes: 3 additions & 0 deletions torchx/runner/events/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class TorchxEvent:
wall_time_usec: Optional[int] = None
start_epoch_time_usec: Optional[int] = None
workspace: Optional[str] = None
exception_type: Optional[str] = None
exception_message: Optional[str] = None
exception_source_location: Optional[str] = None

def __str__(self) -> str:
return self.serialize()
Expand Down
Loading