Skip to content

[Tune] Fix PBT hyperparameter mutation bug when config value is int type with Float distribution - #60646

Open
sjp611 wants to merge 5 commits into
ray-project:masterfrom
sjp611:fix/pbt-float-mutation-bug
Open

sjp611 wants to merge 5 commits into
ray-project:masterfrom
sjp611:fix/pbt-float-mutation-bug

Conversation

@sjp611

@sjp611 sjp611 commented Feb 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix PBT scheduler's _explore function incorrectly converting resampled float values back to integers when the original config value happens to be an int type (e.g., 0 instead of 0.0).

This commonly occurs after JSON serialization/deserialization during checkpoint save/restore, where 0.0 becomes 0.

Before fix: clip_param: 0 -> 0 (int(0.25) = 0)
After fix: clip_param: 0 -> 0.25

Related issues

Fixes #54755

Additional information

Root Cause

In _explore() function, the type preservation logic converts sampled floats back to int when isinstance(config[key], int) is True, regardless of the distribution type.

Solution

Added check to skip int conversion when distribution is Float type:

if isinstance(config[key], int) and not isinstance(distribution, Float):
    new_config[key] = int(new_config[key])

@sjp611
sjp611 requested a review from a team as a code owner February 1, 2026 15:36
@sjp611 sjp611 closed this Feb 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug in Population Based Training (PBT) where a hyperparameter with an initial integer value but a Float distribution was incorrectly cast back to an integer after mutation. The fix is to add a condition to prevent this cast if the distribution is of type Float. This change correctly preserves the floating-point nature of perturbed values for float-based search spaces. The implementation is correct and well-targeted. The code looks good.

@sjp611 sjp611 reopened this Feb 1, 2026
@sjp611 sjp611 changed the title [Tune] Fix PBT hyperparameter mutation bug when config value is int t… [Tune] Fix PBT hyperparameter mutation bug when config value is int type with Float distribution Feb 1, 2026
@ray-gardener ray-gardener Bot added tune Tune-related issues community-contribution Contributed by the community labels Feb 1, 2026
…ype with Float distribution

Fix PBT scheduler's _explore function incorrectly converting resampled float values back to integers when the original config value happens to be an int type (e.g., 0 instead of 0.0).

This commonly occurs after JSON serialization/deserialization during checkpoint save/restore, where 0.0 becomes 0.

Before fix: clip_param: 0 -> 0 (int(0.25) = 0)
After fix: clip_param: 0 -> 0.25

Fixes ray-project#54755

Added check to skip int conversion when distribution is Float type:
if isinstance(config[key], int) and not isinstance(distribution, Float):
    new_config[key] = int(new_config[key])

Signed-off-by: Sung Joon Park <[email protected]>
@sjp611
sjp611 force-pushed the fix/pbt-float-mutation-bug branch from 2090c8a to 78ff57a Compare February 1, 2026 23:06
@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

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.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Mar 1, 2026
@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Mar 2, 2026
@justinvyu
justinvyu enabled auto-merge (squash) March 2, 2026 19:13
@github-actions github-actions Bot added the go add ONLY when ready to merge, run all tests label Mar 2, 2026
@sjp611

sjp611 commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

CI failure (wanda binary download) is unrelated to this PR.

@github-actions
github-actions Bot disabled auto-merge April 6, 2026 08:09
@sjp611

sjp611 commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@justinvyu Could you please merge this?

dstrodtman added a commit that referenced this pull request Oct 30, 2026
…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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests tune Tune-related issues unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tune] PBT scheduler ignoring some of hyperparam_mutations (or incorrectly reporting parameter changes?)

2 participants