Skip to content

Keep quantized integer configs inside the search space bounds - #1667

Open
Sohail Shaikh (sohailshk) wants to merge 4 commits into
microsoft:mainfrom
sohailshk:fix/denormalize-quantized-int-bounds
Open

Sohail Shaikh (sohailshk) wants to merge 4 commits into
microsoft:mainfrom
sohailshk:fix/denormalize-quantized-int-bounds

Conversation

@sohailshk

Copy link
Copy Markdown

Why are these changes needed?

tune.qrandint / tune.qlograndint accept bounds that are not multiples of q (the float quantized() rejects them). Quantized.sample() draws from the multiples of q inside [lower, upper], but the search side rounds to the nearest multiple without checking the domain, in two places: denormalize() (FLOW2, used by CFO/BlendSearch) and unflatten_hierarchical() (BlendSearch's global Optuna search for qlograndint). On main, tune.qrandint(1, 11, 3) yields 0 and 12 with CFO, and the default tune.run(obj, config={"x": tune.qlograndint(5, 30, 4)}, metric="loss", mode="min", num_samples=30, use_ray=False) evaluated 4, below the lower bound (with the change the evaluated values are 8 to 28).

Both places now clamp, through one helper, to the first/last multiple of q inside the bounds. Values on the grid are never moved; domains whose bounds are multiples of q (all q=1 domains) are unchanged. Clamping widens the two edge bins of the normalized-to-value map: it is a deterministic projection for local search, not a sampling distribution.

Not changed: for qrandint, Optuna's own step grid starts at lower (1, 4, 7, 10 for qrandint(1, 11, 3)); those values are inside the bounds.

Tests: denormalize over 0..1 for three domains, a CFO run, a BlendSearch run with qlograndint(5, 30, 4) and the default tune.run (the last two skip without optuna); 6 failed on main, 6 pass. The other tune tests (sample, space, unit_quantization, singleton_integer, tune, searcher, reproducibility) give the same results as main apart from ray/optuna-subprocess ones (test_no_optuna fails on main too).

Related issue number

Search-side counterpart of #1605/#1606 (Quantized.sample()).

Checks

Checks run: black (line length 120) and ruff on the changed files. The pinned pre-commit hook versions were not run. No doc changes are needed.

denormalize() (FLOW2, used by CFO and BlendSearch) and unflatten_hierarchical()
(BlendSearch's global Optuna search for qlograndint) rounded values to the nearest
multiple of q without checking the domain, so configs could fall below lower or
above upper whenever a bound was not a multiple of q (qrandint(1, 11, 3) gave 0
and 12, qlograndint(5, 30, 4) gave 4 and 32). Clamp to the multiples of q inside
[lower, upper], the grid Quantized.sample() draws from.

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the quantized-integer bounds fix.

No open issues 🎉

What changed in this PR

This PR extends the quantized-integer sampling fixes from #1605/#1606 to search-generated configurations, keeping values within domain bounds when those bounds are not multiples of q.

Changes:

  • Adds a shared helper to clamp values to the first and last valid integer-grid points.
  • Applies clamping in local-search denormalization and hierarchical reconstruction for quantized logarithmic integers.
  • Adds regression tests for denormalization, CFO, BlendSearch, and default tune.run.
File Description
test/​tune/​test_quantized_integer_bounds.py Adds bounds and grid-alignment regression tests across search paths.
flaml/​tune/​space.py Clamps quantized integer values to valid grid bounds in both conversion paths.

Review effort: Balanced

@thinkall Li Jiang (thinkall) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review update at 214db7e0aee7ea0cbb1f395b2bdce3dd14ca0be8: the submitted six regression cases pass on native Python 3.10 and 3.13 and fail on exact main. Please add a deterministic, Optuna-independent unflatten_hierarchical endpoint test, assert evaluated is nonempty in the final default-search test, and cover negative bounds in the ceiling/floor projection.

I checked the repeated Uniform qrandint grid concern against the explicit PR scope: a real BlendSearch run produces the same lower-anchored proposals on this head and main. That behavior is explicitly excluded here and the values stay inside the numeric bounds; I am not presenting it as an introduced P2 or asking this bounds fix to include unrelated grid changes.

The independent Medium review used gemini-4-carbon at high reasoning. Five of six required lenses have valid results; the remaining lens returned empty output again after its one allowed same-model recovery. All original results and failure diagnostics are committed locally with the scope adjudication. This execution coverage gap is not a contributor regression, but it prevents a complete clean signoff. No PR approval, thread resolution or review dismissal is submitted.

Posted by thinkall-agent-auto-reviewer

…ative bounds

Add a search-backend-free unflatten_hierarchical endpoint test, negative-bound denormalize cases, and a non-empty check in the default-search test.
@sohailshk

Copy link
Copy Markdown
Author

Thanks for the review, thinkall. I've addressed all three requested points and pushed the test updates in commit d6980b3.

  1. Deterministic unflatten_hierarchical endpoint coverage

Added a parametrized test that calls unflatten_hierarchical directly, without depending on Optuna.

The test covers both flat and nested dictionary search spaces using qlograndint(5, 30, 4).

The expected outputs for the raw values are:

Raw value Expected result
1 8
5 8
6 8
17 16
19 20
30 28
31 28
100 28

The test also verifies that the resulting value is an integer.

  1. Non-empty evaluated results

Added an assertion that the evaluated results are non-empty in the final default-search test.

This ensures the test verifies that the search actually evaluates configurations rather than passing without producing any results.

  1. Negative quantized integer bounds

Added denormalization coverage for negative and mixed-sign bounds:

  • qrandint(-10, 10, 4) produces [-8, 8].
  • qrandint(-11, -2, 3) produces [-9, -3].

This extends coverage beyond positive-only integer ranges.

  1. Regression verification

Verified the tests against both the PR implementation and the original implementation from main.

With space.py reverted to main:

  • 12 failed.
  • 4 passed.
  • The failures include the new unflatten_hierarchical and negative-bound cases.

On the PR head:

  • All 16 tests passed.

This confirms that the added tests detect the behavior addressed by the existing implementation.

  1. Additional test results

Also ran:

  • test_unit_quantization.py
  • test_space.py

Both pass, with 37 tests passed in total.

  1. Scope of the commit

Commit d6980b3 modifies test_quantized_integer_bounds.py only. No source code has been changed.

Summary

All three review requests are covered with deterministic regression tests, including endpoint handling, non-empty search results, and negative quantized integer bounds.

The tests demonstrate clear red/green behavior against the original implementation, while the source code remains unchanged in this commit.

Copilot AI 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.

🟢 Approval recommended

There are no active review issues blocking the change to keep quantized integer configurations within their search-space bounds.

No open issues 🎉

Review effort: Balanced

@thinkall Li Jiang (thinkall) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All 16 selected quantized-bound cases pass on both native stacks. The deterministic nested endpoint cases and assert evaluated improve the test evidence.

One low-priority gap remains: upper=-2, q=3 already rounds to -3, so it does not independently exercise flooring the negative upper clamp. An entirely negative domain such as [-11, -1] with q=3 and expected endpoints [-9, -3] would require both clamps to work.

No new production failure is claimed. This Low test-only correction does not recover the earlier missing full Medium lens; its incomplete coverage and failed diagnostics remain retained.

Posted by thinkall-agent-auto-reviewer

@sohailshk

Copy link
Copy Markdown
Author

Added the requested test case:

qrandint(-11, -1, 3) with endpoints [-9, -3].

The test verifies that the upper clamp rounds down.

Comparison with main: Using the current space.py from main, 13 tests fail and 4 pass. The new case passes with the PR change.

Copilot AI 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.

🟢 Approval recommended

No active review issues are identified for the change to keep quantized integer configurations within search-space bounds.

No open issues 🎉

Review effort: Balanced

@thinkall Li Jiang (thinkall) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The test-only delta at f237de8ea248a3377c3cc5f1689ff37ae6c2b773 is clean. The negative off-grid endpoints now detect both missing lower and upper clamps, and the targeted suites passed 34 tests across the two native stacks.

This is one Low review of the narrow test correction, not a replacement for the previously incomplete whole-PR Medium review. Its 5/6 coverage gap remains an approval blocker even with successful workflows and a Balanced approval recommendation.

All review evidence remains in detached local worktrees; nothing is pushed to this PR.

Posted by thinkall-agent-auto-reviewer

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants