Repository navigation
[tune] Fix HyperBand ending brackets short of max_t - #66710
vineethsaivs wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the HyperBand scheduler to ensure that the last rung of every bracket correctly ends at max_t even when max_t is not a power of eta. It replaces the multiplication and negative exponent calculations with division to avoid floating-point rounding issues (e.g., preventing a bracket from being dropped due to rounding). A new unit test testLastRungIsMaxT has been added to verify these changes. There are no review comments to address, and I have no additional feedback to provide.
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
Still relevant. It merges cleanly with master and is ready for review. |
…rs (#67608) ## Summary Adds the missing docstrings, `Args:` entries, and `Returns:` sections on the public `ray.tune.schedulers` API: `FIFOScheduler`, `AsyncHyperBandScheduler`, `HyperBandScheduler`, `HyperBandForBOHB`, `MedianStoppingRule`, `PopulationBasedTraining`, `PopulationBasedTrainingReplay`, and `ResourceChangingScheduler`. Each describes existing behavior, written from the code. A follow-up PR covers the rest of the public Tune API. ## Before On these schedulers, 5 public methods had no docstring, 85 parameters had no `Args:` entry, and 23 methods that annotate a return type had no `Returns:` section. ## After All of those are documented. Ray's `api_param_coverage.py` reports no undocumented parameters in `python/ray/tune/schedulers/`. Most of the scheduler callbacks, such as `on_trial_add`, `on_trial_result`, and `choose_trial_to_run`, override `TrialScheduler` without a docstring of their own. Sphinx renders the base docstring for them, and that docstring had no `Args:` or `Returns:`. So this PR documents the `TrialScheduler` methods once instead of repeating the same entries on each override. Overrides that already had their own docstring, mostly in `HyperBandScheduler` and `HyperBandForBOHB`, get their entries in place. Behavior is unchanged. The diff touches only docstrings, which the guard below confirms. ## For reviewers These are the docstrings worth a close read: - `TrialScheduler.on_trial_result` now documents `TrialScheduler.NOOP` as a return value, for a scheduler that has already changed the trial's state itself. `PopulationBasedTraining` and `PopulationBasedTrainingReplay` return it, and `TuneController` treats it as no action. The existing prose above it still lists only `CONTINUE`, `PAUSE`, and `STOP`. - `HyperBandForBOHB.choose_trial_to_run` documents `allow_recurse`, and describes how the method processes brackets that have a paused trial when no trial is running. - `PopulationBasedTraining.reset_stats` and `last_scores` carry a "Unit test only" comment but are public methods, so they now have docstrings. Two existing docstrings say something the code doesn't do. This PR leaves them as they are, since changing what a docstring asserts belongs in a separate correctness PR: - `HyperBandForBOHB.choose_trial_to_run` repeats the "Fair scheduling within iteration by completion percentage" summary from `HyperBandScheduler`, but it iterates brackets in creation order without sorting by completion. - `MedianStoppingRule.on_trial_result` says it compares against "all completed trials". The code compares against every trial that has reported a result at or beyond the current step, whether or not it has completed. ## Duplicate check No open PR documents these symbols. Open PRs #66710 and #67137 change code in `hyperband.py`, and #58165, #59383, and #60646 change code in `pbt.py`. None of them edit the docstrings changed here, and #66710, #67137, and #58165 apply cleanly on top of this branch. ## Testing - `python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)"`: `docstring-only guard: 6 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`, run over `python/ray/tune/schedulers/` with a class index of `python/ray/`: 85 undocumented parameters on `master`, 0 on this branch. - 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]>
## Summary Corrects eight Ray Tune docstrings that describe behavior the code doesn't have. This is a correctness change: it changes what the docstrings assert, so each item needs a technical read rather than a skim. The items surfaced while backfilling docstrings in #67608 and #67610. Stacked on #67610, which is stacked on #67608. Several corrected lines sit right next to `Args:` blocks those PRs add, so a branch off `master` would conflict with both. This PR retargets to `master` once they merge. ## Before and after **`HyperBandForBOHB.choose_trial_to_run`** (`schedulers/hb_bohb.py`) opened with "Fair scheduling within iteration by completion percentage," copied from `HyperBandScheduler`. `HyperBandScheduler` sorts brackets by `completion_percentage()`, but the BOHB override iterates them in creation order and returns the first ready trial. The next sentence said the trial list from `tune_controller` isn't used, but the override reads `tune_controller.get_trials()` to check whether any trial is running. Both sentences now describe the override. **`MedianStoppingRule.on_trial_result`** (`schedulers/median_stopping_rule.py`) said it compares a trial against "the running averages of all completed trials' objectives reported up to step `t`." The code compares against every other trial whose last result is at step `t` or later (`_trials_beyond_time`), whether or not it has completed, and each running average covers results from `grace_period` to `t` (`_running_mean`). **`tune.quniform`** (`search/sample.py`) gave `tune.uniform(1, 10)` as its example. It now uses `tune.quniform(1, 10, 0.5)` and says the value is rounded to a multiple of `0.5`, which is what `Quantized.sample` does. **`tune.randint`** (`search/sample.py`) gave `tune.randint(10)` as its example, but `upper` has no default, so that call raises a `TypeError`. It now uses `tune.randint(0, 10)`. **`Stopper`** (`stopper/stopper.py`) said "By default, this class does not stop any trials." The base `__call__` and `stop_all` raise `NotImplementedError`. The docstring now says so. **`ExperimentPlateauStopper`** (`stopper/experiment_plateau.py`) listed a `ValueError` when `patience` isn't "a strictly positive integer." The check is `patience < 0`, and `patience` defaults to `0`. The `Raises:` entry now says "a non-negative integer." The runtime error message says "strictly positive" too, but it's a code string, so it changes in #67612. **`BasicVariantGenerator.restore_from_dir`** (`search/basic_variant.py`) said it "Restores self + searcher + search wrappers," copied from `SearchGenerator`. `BasicVariantGenerator` has no searcher or wrappers. It loads the newest checkpoint and calls `set_state`, and the summary now says that. **`tune.run` and `RunConfig`, `verbose`** (`tune/tune.py` and `air/config.py`) said that setting `RAY_AIR_NEW_OUTPUT=1` switches to the old verbosity levels. It's the reverse. `get_air_verbosity` in `tune/experimental/output.py` falls back to the old output only when the variable is `"0"`, and it defaults to `"1"`. Both docstrings now say `RAY_AIR_NEW_OUTPUT=0`. Behavior is unchanged. The diff touches only docstrings, which the guard below confirms. ## For reviewers If `HyperBandForBOHB` is meant to schedule by completion percentage like its parent, the bug is in the code rather than the docstring. Say so and I'll drop that item in favor of a code fix. The override's comments mark it as BOHB-specific ("MAIN CHANGE HERE"), but none of them explain the ordering. `air/config.py` is owned by `@ray-project/ray-train`. It carries the same `RAY_AIR_NEW_OUTPUT` sentence as `tune.py`, so both get the same fix here. ## Duplicate check No open PR edits these docstrings. Open PRs #66710 and #67137 change code in `hyperband.py`, and #66923 changes `CombinedStopper` code in `stopper.py`. None of them touch the lines changed here. ## Testing - `python ci/ray_ci/doc/check_docstring_only.py --base doc-1922-tune-api-docstrings`: `docstring-only guard: 8 file(s), docstrings only.` - The full pre-commit suite on the changed files, including ruff, black, pydoclint, and the docstyle hook: passed. - 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]>
Rungs were built as r0 * eta**i with r0 = int(max_t * eta**-s), so a bracket's last rung is max_t rounded down to a multiple of eta**s, and its best trials stop there (162 of 200 in hyperband_example.py). Compute rung i as int(max_t / eta**(s - i)) so every bracket ends at max_t. The division also stops 729 * 3**-6 from rounding r0 down to 0. Signed-off-by: Vineeth Sai <[email protected]>
01b8d4a to
8d85de0
Compare
Description
HyperBand stops a bracket's best trials before
max_tunlessmax_tis a multiple ofeta**s. Inhyperband_example.py(max_t=200), the 98-trial bracket's rungs are 2, 6, 18, 54, 162.Cause:
successive_halvingmultiplies the flooredr0byeta, so the last rung ismax_trounded down to a multiple ofeta**s. #39157 fixed this only wheneta**sdividesmax_t.Fix: rung
iisint(max_t / eta**(s - i)), per the HyperBand paper's Alg. 1.r0uses the same division, so729 * 3**-6 == 0.9999999999999999no longer drops a bracket. The defaultmax_t=81is unchanged.Why this is not a duplicate
Searched PRs and issues (open and closed) for hyperband, HyperBandScheduler and successive_halving; no other PR changes HyperBand's rung computation. #67137 (NaN ranking) edits
successive_halvingnearby. #11695 reported this symptom under the older formula.Tests run and their results
Master's
python/ray/tuneon the ray 2.56.1 wheel:A real
Tunerrun withhyperband_example.py's settings: the 98-trial bracket's best trials stop at 162 on master, 200 on this branch.