Repository navigation
[train][1/n] Support WorkerProbes in the Ray Train WorkerGroup - #67521
Conversation
6d00d8d to
33b7647
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces support for scheduled and on-demand worker health probes in Ray Train v2. It adds probe tracking to TrainContext and WorkerStatus, implements background sampling threads for scheduled probes, and adds asynchronous polling mechanisms (poll_probes_async and poll_probe_results) to the WorkerGroup. Feedback on these changes highlights two key issues: first, popping ranks from _world_rank_to_on_demand_poll during replica group replacement can cause missing results and potential KeyErrors, so it is better to let the dead actor's ObjectRef fail naturally; second, the infinite loop in _sample_probe can lead to thread leaks upon worker re-initialization, which can be mitigated by checking if the active train context has changed.
| self._world_rank_to_on_demand_poll.pop( | ||
| w.distributed_context.world_rank, None | ||
| ) |
There was a problem hiding this comment.
Popping the rank from _world_rank_to_on_demand_poll during replica group replacement will cause poll_probe_results to completely omit this rank from the returned results dictionary. This can lead to unexpected KeyErrors or incomplete results in the controller. If we do not pop it, the pending ObjectRef from the dead actor will naturally fail with a RayActorError when resolved, which _get_on_demand_results will catch and correctly report as an error for that rank. Consider removing this pop operation.
…nd AIR (#67621) ## Summary Adds the missing docstrings, `Args:` entries, and `Returns:` sections on public Ray Train and AIR symbols in `ray.train.v2`, `ray.train.context`, `ray.train._internal`, `ray.train._checkpoint`, `ray.train.health`, and `ray.air.config`. Each describes existing behavior, written from the code. #67620 covers the framework integrations. ## Before Across these modules, 13 public symbols had no docstring, 4 parameters had no `Args:` entry, and 31 callables that annotate a return type had no `Returns:` section. ## After - The `ray.train._internal.session` accessors (`get_metadata`, `get_experiment_name`, `get_trial_name`, `get_trial_id`, `get_run_id`, `get_trial_resources`, `get_trial_dir`, `get_world_size`, `get_world_rank`, `get_local_rank`) have `Returns:` sections, including the default each returns outside a Train or Tune function. - `ray.train.v2` `TrainContext` methods, both `get_context` functions, `JaxConfig`, `ValidationFn.__call__`, `CheckpointUploadMode.default_delete_local_checkpoint_after_upload`, and `RunConfig.storage_context` are documented. - `Checkpoint.get_metadata`, `set_metadata`, and `update_metadata`, `DataConfig.default_ingest_options`, both `ScalingConfig` placement-group methods, and `Probe.probe_name` are documented. `ray.train.context.TrainContext` and `ray.tune.context.TuneContext` copy their accessor docstrings from `ray.train._internal.session` through `@_copy_doc`, so the session `Returns:` sections document those methods too. A docstring written on the context methods would be overwritten. Behavior is unchanged. The diff touches only docstrings, which the guard below confirms. ## Not in this PR - `JaxConfig.backend_cls`, `framework`, and `to_dict` inherit their docstrings from `BackendConfig`, which #67620 documents. - `WandbLoggerCallback.on_experiment_end`: its `**info` parameter has no type hint, so an `Args:` section raises pydoclint DOC107 under `--arg-type-hints-in-signature`. #67622 adds the type hint and documents it. ## For reviewers These are worth a close read: - The session accessors are `@PublicAPI` but have no public import path. They're documented here because the public `TrainContext` and `TuneContext` render their docstrings. Whether they stay public is a separate question. - `ScalingConfig.as_placement_group_factory` describes the bundle layout: an empty head bundle, a bundle combining the trainer with the first worker, and one bundle per other worker. - `JaxConfig` documents that Ray Train skips JAX distributed setup when neither `use_tpu` nor `use_gpu` is set. ## Duplicate check No open PR documents these symbols. #67521 changes Ray Train health probes but touches only `ray.train.v2._internal`, not `health/probe.py`. ## Testing - `python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)"`: `docstring-only guard: 12 file(s), docstrings only.` - The full pre-commit suite on the changed files, including ruff, black, pydoclint, and the docstyle hook: passed. - `ci/ray_ci/doc/api_param_coverage.py` over the changed modules and `ray.air.integrations`: 11 undocumented parameters on `master`, 8 on this branch. The rest are on `WandbLoggerCallback`, outside this PR's scope or blocked as above. - The commit carries an `@rtd-build` line, so the Read the Docs preview renders the changed docstrings. AI assistance (Claude Code) was used to prepare this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
pseudo-rnd-thoughts
left a comment
There was a problem hiding this comment.
PR looks good, this is my initial comment
| self._world_rank_to_on_demand_poll.pop( | ||
| w.distributed_context.world_rank, None | ||
| ) |
33b7647 to
66e86db
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 66e86db. Configure here.
040c366 to
58a2993
Compare
pseudo-rnd-thoughts
left a comment
There was a problem hiding this comment.
Could you add the comments for future readers, then LGTM
- A WorkerGroupCallback passes worker_probes to init_train_context. Each worker samples each ScheduledProbe in its own thread into TrainContext, and poll_status returns the latest samples as WorkerStatus.probe_results. - WorkerGroup.poll_probes_async(probes, timeout_s, ranks) and poll_probe_results() poll probes once on some workers, like NodeMonitorGroup. Each worker runs them in a ThreadRunner started through execute_async, so poll_status keeps answering meanwhile. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lehui Liu <[email protected]>
58a2993 to
4623b96
Compare
Replaced by a newer auto-merge request
## Description 2nd PR of the new [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics) stack, on top of #67521 (1/n). This PR adds `ray.train.health.report()`, the way a training function reports health metrics it computes itself. ```python import ray.train.health as health def train_func(config): for step, batch in enumerate(loader): ... health.report({"grad_norm": grad_norm}, step=step) ``` `ray.train.health.report(metrics, step=None)`: - Is not a barrier: each worker can call it any number of times. - Goes through `TrainFnUtils.report_health` into the worker's `TrainContext`, under the same `health_lock` the `WorkerProbe` samplers use. `poll_status()` returns it as `WorkerStatus.health_report`, alongside `probe_results`. Feeding these reports into the `HealthManager` comes in a later PR. ## Test unit tests Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…State (#67879) ## Description WorkerProbe 3/n of the [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics) stack, stacked on #67671 (5/n). WorkerProbe 1/n #67521 and 2/n #67520 are merged. Since 1/n and 2/n, each worker returns its `WorkerProbe` results in `WorkerStatus.probe_results` and its latest `ray.train.health.report()` in `WorkerStatus.health_report`. Nothing passes them to the `HealthManager` yet, so no evaluator sees them. This PR is the `HealthManager` side: - **`HealthState.health_reports`**: `{world rank: ProbeResult}`, the latest `ray.train.health.report()` of each worker that reported. - **`HealthManager.worker_probes`**: the in-flight checks' `WorkerProbe` `ScheduledProbe`s, for each worker to sample. `NodeMonitorGroup` still ignores them. - **`HealthManager.evaluate_inflight_checks(worker_statuses=None, timeout=...)`** takes `{world rank: WorkerStatus}` from the worker group's latest poll. `_to_health_state()` adds each worker's `WorkerProbe` results to `HealthState.probe_results`, keyed by world rank, next to the `NodeProbe` results keyed by node ID, and each `health_report` to `health_reports`. Nothing calls these yet. WorkerProbe 4/n, after 6/n #67856, wires them up: `HealthCallback` gives the workers their `WorkerProbe`s, the controller passes `worker_group_status.worker_statuses`, a `Diagnose` runs its on-demand `WorkerProbe`s, and an e2e test covers it. ### Not a duplicate `gh pr list --repo ray-project/ray --state open --search` for `WorkerProbe`, `health_reports` and `HealthState worker` finds only 5/n #67671 and 6/n #67856 of this stack, and neither passes worker results to the `HealthManager`. This PR leaves `evaluate_on_demand_checks()`, which 6/n changes, alone, and merges cleanly with 6/n. ## Test ```bash python python/ray/train/v2/tests/test_health_manager.py # 24 passed python python/ray/train/v2/tests/test_health_contracts.py # 17 passed python python/ray/train/v2/tests/test_health_node_monitor.py # 13 passed pre-commit run --files python/ray/train/health/state.py python/ray/train/health/_internal/manager.py python/ray/train/v2/tests/test_health_manager.py # passed ``` New tests: `test_worker_probes_are_the_inflight_worker_probes` and `test_worker_results_and_health_reports_reach_the_evaluators`. AI assistance (Claude Code) was used for this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
## Description 4th PR of the WorkerProbe stack (#67521, #67520, #67879), and part of the [Ray Train Monitoring and Diagnostics REP](https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics) stack #67671 → #67856 → #67879. Workers sample their `WorkerProbe`s (1/n) and the `HealthManager` can put their results in the `HealthState` (3/n), but nothing gave the workers their probes or passed the worker poll in, and on-demand `WorkerProbe`s were dropped. This PR wires them in: - **`HealthCallback.before_init_train_context`** gives each worker the in-flight `WorkerProbe`s, `HealthManager.worker_probes`. - **The controller** passes its worker poll to `evaluate_inflight_checks(worker_statuses)`, so `WorkerProbe` results and `ray.train.health.report()` reach the evaluators. - **`HealthManager.reset()`** takes the attempt's worker group. The on-demand checks, pre-flight checks and the checks of a `Diagnose`, send their `WorkerProbe`s to `WorkerGroup.poll_probes_async()`. `evaluate_on_demand_checks()` waits for the workers as well as the node monitors, then evaluates one `HealthState` with `WorkerProbe`, `NodeProbe` and `ControllerProbe` results. On-demand checks without evaluators start nothing. ## Related 1. REP: https://github.com/ray-project/enhancements/tree/main/reps/2026-08-11-ray-train-monitoring-and-diagnostics 2. #67521, #67520, #67879, #67856, #67671 Not a duplicate: no open PR passes `WorkerProbe`s or their results between the Ray Train controller and the `HealthManager`. ## Test ``` python python/ray/train/v2/tests/test_health_manager.py # 26 passed python python/ray/train/v2/tests/test_health_controller.py # 9 passed python python/ray/train/v2/tests/test_health_e2e.py # 2 passed python python/ray/train/v2/tests/test_controller.py # 25 passed python python/ray/train/v2/tests/test_controller_callback_behaviour.py # 10 passed python python/ray/train/v2/tests/test_worker.py # 5 passed python python/ray/train/v2/tests/test_worker_group.py # 46 passed ``` `test_health_e2e` runs the Diagnose scenario with a training step report (`ray.train.health.report()`) as one of the signals, and an on-demand `WorkerProbe` in each diagnosis. This PR was written with AI assistance (Claude Code). I reviewed every changed line and ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Lehui Liu <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>

Description
1st PR of a new Ray Train Monitoring and Diagnostics REP stack for Worker level integration with Ray Train V2. Adds
WorkerProbesupport to the Ray TrainWorkerGroup, mirroring whatNodeMonitorGroupdoes forNodeProbes.Each train worker samples its
WorkerProbes in their own daemon threads everypoll_interval_s, and keeps the latest samples on itsTrainContext.WorkerGroupCallback'sbefore_init_train_context, asworker_probes.poll_status()returns the latest samples asWorkerStatus.probe_results, so they ride the poll the controller already makes.WorkerGroup:poll_probes_async(probes, timeout_s, ranks=None)polls probes once on some or all workers. Each worker runs them in aThreadRunnerstarted throughexecute_async, sopoll_status()keeps answering meanwhile.poll_probe_results()returns{probe name: {world rank: ProbeResult}}once every worker answered or the timeout passed, andNoneuntil then, likeNodeMonitorGroup.poll_probe_results(). A worker that did not answer, or whose actor failed, carries the error in its results.Wiring these results into the
HealthManagercomes in a later PR.Illustration of how periodic and on-demand probes flow through the WorkerGroup
periodic:

on demand:

Related:
Test
unit tests