Repository navigation
Conversation
Signed-off-by: Daraan <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request removes a problematic piece of code that forcibly casts perturbed hyperparameters back to integers. This logic was flawed as it could cause runtime errors (e.g., when a value becomes None), lead to silent data loss by truncating floats (e.g., 1.9 becoming 1), and failed to handle numpy integer types correctly. Removing this block is the right approach. It makes the behavior of Population Based Training more predictable and robust by leaving hyperparameter type handling to the user's training code. This is a great improvement to the scheduler's reliability.
When does this happen? What happens if 1 -> None happens vs 1 -> 0? |
When the mutation choices are for example |
|
Hmm I ignored the perturbation_factor in my thinking. We want to keep the int casting, for batch_size * 0.8, should stay an int. New way: no casting when we resample, do not modify use choice. There could still be a situation where the users inputs mix of floats and ints and expects floats. |
Signed-off-by: Daraan <[email protected]>
|
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. |
|
💤stale |
…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]>
I am performing PBT based on a grid search, for examples I had the values (0.1, 1, None).
The following code causes an error if the perturbation is
1 -> Noneand silently casts1 -> 0.1 -> 0,it should only be applied when we perturb with a float factor but not when we resample to respect the user choices.
It will also not work for numpy data types:
`python -c "import numpy as np; assert isinstance(np.int_(2), int)"``
As an alternative I could think that a float.is_integer might be an alternative but I am not sure if that is really worth it.