Repository navigation
Conversation
Data.bounds forwards the bounds through the operations after the bound layer but kept their order, so -Scalar(lower=1, upper=5) reported (-1, -5). The Int layer clamps with these bounds, so integer casting mapped every value to one integer. Take the elementwise min/max when both bounds are set, and move a single bound to the other side when the operation is decreasing.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
Motivation and Context / Related issue
Data.boundsforwards the bounds through the operations that come after the bound layer. It keeps them in the same order even when the operation is decreasing, so-ng.p.Scalar(lower=1, upper=5)reports bounds(-1, -5), and10 / ng.p.Scalar(lower=1, upper=10)reports(10, 1).The docstring says this estimate "may be inaccurate", but the
Intlayer depends on it for correctness: it clamps the rounded value betweenround(lower + 0.5)andround(upper - 0.5). With the bounds swapped, every value ends up clamped to the same integer:RandomSearchon that parameter returns-5on every ask.ng.p.Scalar(lower=-5, upper=-1).set_integer_casting()covers the same range and returns all of-5..-1. A half-bounded parameter is also wrong:(-ng.p.Scalar(init=3, lower=1)).set_integer_casting().valueis-1instead of-3.The fix is in
Data.bounds:Bounds for increasing operations, including
Logwith one or two bounds, are unchanged. Two cases are still not handled: a half-bounded array multiplied by factors of mixed signs keeps the current behavior, and non-monotonic operations (e.g.x ** 2over a range containing 0) are still estimated from the bounds alone.How Has This Been Tested (if it applies)
test_bound_estimation_decreasing_operationinnevergrad/parametrization/test_layers.py. It covers negation,* -1,10 / x,0.5 ** x, and a half-bounded negation, and checks the bounds and that every integer in range round-trips through integer casting. It fails on main for all 5 cases and passes with the change.pytest nevergrad/parametrizationpasses (238 tests).black,mypy --implicit-reexportandpylint(with the CI flags) report nothing new on the changed files.Checklist
This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.