Repository navigation
[train] Yield the controller while waiting for a scaling decision, and fix the elastic node-killing release test - #67478
Conversation
…ecision In INITIALIZING, RESTARTING and RESCHEDULING, `TrainController._step` never awaits. While the scaling policy keeps returning `NoopDecision` (an elastic run waiting for `min_workers` to fit, or a failed coordinator query), `run()` loops without giving up the event loop. The controller actor then spins a full core, and calls like `abort()` can't reach it. This has been the case for elastic runs since elastic training landed; it isn't caused by the reservation pinning that was reverted. `_step` now sleeps `RAY_TRAIN_HEALTH_CHECK_INTERVAL_S` before asking the policy again, matching the running path's poll interval. Once `abort()` can run during that sleep, the control loop must not overwrite the `AbortedState` it sets with the state the iteration computed before the abort, or `run()` would go back to waiting. The loop now leaves a terminal state set concurrently by `abort()` in place. The yield is the control-loop change from ray-project#66763, split out so it can land on its own. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
…sk dies with its node `terminate_node` runs `terminate_current_instance` on the node it terminates, with hard node affinity and the default task retries. The task usually dies with the instance, so Ray retries it, and the retry can never be scheduled: its node is gone. `ray.get` then raises `TaskUnschedulableError`, which fails `train_elastic_e2e_with_node_killing` even when training finished successfully (failure mode A in the release history). Don't retry the killer task, and treat `NodeDiedError`, `WorkerCrashedError` and `TaskUnschedulableError` as the node having gone down, which is the intended outcome. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Mark Towers <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request ensures the Ray Train controller yields the event loop while waiting for scaling decisions, allowing concurrent operations like abort() to execute. It also prevents overwriting terminal states after awaiting and improves node termination resilience by handling expected task failures. The review feedback suggests two key improvements: adding a terminal state check within the control loop's exception handler to prevent exceptions from overwriting the state, and properly awaiting the cancelled task in the new unit tests to avoid unhandled exception warnings.
| if self.get_state().is_terminal(): | ||
| # `abort()` ran while `_step` was awaiting. Don't overwrite its | ||
| # terminal state with the state this iteration computed. | ||
| return |
There was a problem hiding this comment.
While this check successfully prevents overwriting the terminal state when _step() returns normally, it does not protect against the case where _step() raises an exception (e.g., RayActorError or CancelledError due to the worker group being aborted concurrently).\n\nIf _step() raises an exception after abort() has run, the exception is caught by the outer except Exception as e: block. If the failure policy or its callbacks raise an exception during this handling, the fallback block will directly overwrite self._state with ErroredState (line 948), bypassing this terminal state check entirely.\n\nTo make this fully robust, we should also check if the state is terminal at the beginning of the except Exception as e: block:\n\npython\n except Exception as e:\n if self.get_state().is_terminal():\n return\n
|
|
||
| assert not run_task.done() | ||
| assert isinstance(controller.get_state(), InitializingState) | ||
| run_task.cancel() |
There was a problem hiding this comment.
Signed-off-by: Mark Towers <[email protected]>
Description
This PR fixes two issues with the controller.
INITIALIZING,RESTARTINGandRESCHEDULING,TrainController._stepnever awaits, yielding the event loop. While the scaling policy keeps returningNoopDecision(an elastic run waiting formin_workersto fit, or a failed coordinator query),run()loops without yielding the event loop meaning that the controller actor spins a full core and that anabort()can't reach it, so Ctrl-C on the driver doesn't stop the run.This has been true for elastic runs since #60721. This PR updates
_stepto now sleepsRAY_TRAIN_HEALTH_CHECK_INTERVAL_Sbefore asking the policy again, matching the running path's poll interval. Onceabort()can run during that sleep, the control loop must not overwrite theAbortedStateit set with the state computed before the abort, so a terminal state set concurrently is left in place.terminate_nodeinelastic_util.pyruns its killer task on the node it terminates, with hard affinity and default retries. When the task dies with the node, Ray retries it, and the retry can never be scheduled, soray.getraisesTaskUnschedulableErrorandtrain_elastic_e2e_with_node_killingfails after training already succeeded (failure mode A). The killer task is no longer retried, andNodeDiedError,WorkerCrashedErrorandTaskUnschedulableErrorcount as the node having gone down.New test:
test_abort_while_waiting_for_a_scaling_decisionintest_controller.py. It raisesTimeoutErrorwithout the fix. The end-to-end version,test_ctrl_c_aborts_a_run_waiting_for_workers(a real driver process receiving SIGINT), is in #67481.AI assistance (Claude Code) was used to write these changes and tests, run the suites, and write this description.