Skip to content

Worker killed error #78

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

Merged
merged 7 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
basic WorkerKilledError
  • Loading branch information
pmcurtin committed Oct 26, 2024
commit 76e046265ac7ecf3ef9288e5565845b1eab40346
11 changes: 10 additions & 1 deletion src/torchrunx/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@

from .environment import auto_hosts, auto_workers, slurm_hosts, slurm_workers
from .logging_utils import LogRecordSocketReceiver, default_handlers
from .utils import AgentStatus, LauncherAgentGroup, LauncherPayload, WorkerException, get_open_port
from .utils import (
AgentStatus,
LauncherAgentGroup,
LauncherPayload,
WorkerException,
WorkerKilledError,
get_open_port,
)


class AgentKilledError(Exception):
Expand Down Expand Up @@ -152,6 +159,8 @@ def run( # noqa: C901, PLR0912
for value in s.return_values:
if isinstance(value, WorkerException):
raise value.exception
if isinstance(value, WorkerKilledError):
raise value

if all(s.state == "done" for s in agent_statuses):
break
Expand Down
9 changes: 7 additions & 2 deletions src/torchrunx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class WorkerException:
exception: Exception


@dataclass
class WorkerKilledError(Exception):
failure: str


@dataclass
class AgentStatus:
state: Literal["running", "failed", "done"]
Expand All @@ -105,9 +110,9 @@ class AgentStatus:
def from_result(cls, result: RunProcsResult | None) -> Self:
if result is None:
return cls(state="running")

for local_rank, failure in result.failures.items():
result.return_values[local_rank] = WorkerKilledError(failure.message)
return_values = list(result.return_values.values())

failed = any(isinstance(v, WorkerException) for v in return_values)
state = "failed" if failed else "done"

Expand Down
1 change: 1 addition & 0 deletions tests/test_func.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time

import torch
import torch.distributed as dist
Expand Down