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

[air] Fix traceback context swallowing in training jobs #29143

Merged
merged 3 commits into from
Oct 7, 2022
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
7 changes: 7 additions & 0 deletions python/ray/air/_internal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def skip_exceptions(exc: Optional[Exception]) -> Exception:
return exc


def exception_cause(exc: Optional[Exception]) -> Optional[Exception]:
if not exc:
return None

return getattr(exc, "__cause__", None)


class RunnerThread(threading.Thread):
"""Supervisor thread that runs your script."""

Expand Down
5 changes: 3 additions & 2 deletions python/ray/train/_internal/worker_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import ray
from ray.actor import ActorHandle
from ray.air._internal.util import skip_exceptions
from ray.air._internal.util import skip_exceptions, exception_cause
from ray.types import ObjectRef
from ray.util.placement_group import PlacementGroup

Expand All @@ -27,7 +27,8 @@ def __execute(self, func: Callable[..., T], *args, **kwargs) -> T:
try:
return func(*args, **kwargs)
except Exception as e:
raise skip_exceptions(e) from None
skipped = skip_exceptions(e)
raise skipped from exception_cause(skipped)


@dataclass
Expand Down
5 changes: 3 additions & 2 deletions python/ray/tune/trainable/trainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import ray
from ray.air._internal.remote_storage import list_at_uri
from ray.air._internal.util import skip_exceptions
from ray.air._internal.util import skip_exceptions, exception_cause
from ray.air.checkpoint import (
Checkpoint,
_DICT_CHECKPOINT_ADDITIONAL_FILE_KEY,
Expand Down Expand Up @@ -351,7 +351,8 @@ def train(self):
try:
result = self.step()
except Exception as e:
raise skip_exceptions(e) from None
skipped = skip_exceptions(e)
raise skipped from exception_cause(skipped)

assert isinstance(result, dict), "step() needs to return a dict."

Expand Down