Skip to content

Commit bc5c880

Browse files
committed
Update
[ghstack-poisoned]
1 parent ad359e6 commit bc5c880

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

test/test_inference_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ def test_invalid_server_backend_raises(self):
10571057
create_env_fn=[_counting_env_factory] * 2,
10581058
policy_factory=_make_counting_policy,
10591059
frames_per_batch=10,
1060-
server_backend="proces",
1060+
server_backend="not-a-backend",
10611061
)
10621062

10631063
def test_server_death_raises_instead_of_hanging(self):

torchrl/collectors/_async_batched.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,21 @@ def server_stats(self, *, reset: bool = False) -> dict[str, float | int]:
444444
# Rollout: drain the result queue
445445
# ------------------------------------------------------------------
446446

447-
@staticmethod
448-
def _check_worker_result(item):
449-
"""Re-raise exceptions propagated from coordinator threads."""
447+
def _check_worker_result(self, item):
448+
"""Re-raise exceptions propagated from coordinator threads.
449+
450+
Worker threads may observe a dying server before the liveness
451+
watchdog does (their transport read errors out first); attribute the
452+
failure to the server in that case so the caller gets a
453+
deterministic error regardless of which path wins the race.
454+
"""
450455
if isinstance(item, BaseException):
456+
if not self._server.is_alive:
457+
raise RuntimeError(
458+
"The inference server died while the collector was "
459+
"waiting for transitions. Check the server process "
460+
"logs (e.g. OOM kills or exceptions in the policy)."
461+
) from item
451462
raise RuntimeError(
452463
"A collector worker thread raised an exception."
453464
) from item
@@ -500,6 +511,7 @@ def _rollout_frames(self) -> TensorDictBase:
500511
td = rq.get_nowait()
501512
except queue.Empty:
502513
break
514+
self._check_worker_result(td)
503515
transitions.append(td)
504516
collected += td.numel()
505517
if self.verbose:

0 commit comments

Comments
 (0)