Skip to content

Support discrete choices in random generators (#5257) - #5257

Open
saitcakmak wants to merge 1 commit into
facebook:mainfrom
saitcakmak:export-D113627036
Open

Support discrete choices in random generators (#5257)#5257
saitcakmak wants to merge 1 commit into
facebook:mainfrom
saitcakmak:export-D113627036

Conversation

@saitcakmak

@saitcakmak saitcakmak commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary:

Problem:
Random generation previously used OrderedChoiceToIntegerRange, which encoded ordered numeric choices as integer indices while leaving parameter constraints in the original value space. Constraints could therefore be checked against indices and produce candidates that violated the user-defined constraint after transforming back. This also prevented correct handling of irregularly spaced choices.

What Changed:

  • Add a choice-preserving transform base shared by random generators and MBM, using ChoiceToNumericChoice without IntToFloat or model-side UnitX for random generation.
  • Preserve numeric ChoiceParameter values and integer ranges in SearchSpaceDigest.discrete_choices.
  • Teach RandomGenerator, and therefore Sobol and Uniform generators, to sample every discrete dimension uniformly by rank and decode it to the actual choice value before constraint checks, rounding, and deduplication.
  • Handle purely discrete equality constraints with rejection sampling.
  • In the polytope fallback, sample the continuous relaxation in the original value space, project each discrete coordinate to its nearest supported value, and recheck feasibility. Irregular value-to-index mappings are nonlinear, so transforming the polytope to index space would not preserve its linear constraints.
  • Avoid calling PyTorch SobolEngine.fast_forward(0): the fresh-engine implementation converts zero to -1, while advancing by zero should be a no-op.
  • Cover irregular choices, discrete equality constraints, and integer ranges through generator, adapter, generation strategy, and public Client tests.

Differential Revision: D113627036

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jul 28, 2026
@meta-codesync

meta-codesync Bot commented Jul 28, 2026

Copy link
Copy Markdown

@saitcakmak has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113627036.

@codecov-commenter

codecov-commenter commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.59%. Comparing base (00b03db) to head (0dedfa2).

Files with missing lines Patch % Lines
ax/generators/random/base.py 86.95% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5257   +/-   ##
=======================================
  Coverage   96.58%   96.59%           
=======================================
  Files         621      621           
  Lines       70745    70805   +60     
=======================================
+ Hits        68330    68395   +65     
+ Misses       2415     2410    -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@meta-codesync meta-codesync Bot changed the title Support discrete choices in random generators Support discrete choices in random generators (#5257) Jul 29, 2026
saitcakmak added a commit to saitcakmak/Ax that referenced this pull request Jul 29, 2026
Summary:

Problem:
Random generation previously used `OrderedChoiceToIntegerRange`, which encoded ordered numeric choices as integer indices while leaving parameter constraints in the original value space. Constraints could therefore be checked against indices and produce candidates that violated the user-defined constraint after transforming back. This also prevented correct handling of irregularly spaced choices.

What Changed:
- Add a choice-preserving transform base shared by random generators and MBM, using `ChoiceToNumericChoice` without `IntToFloat` or model-side `UnitX` for random generation.
- Preserve numeric `ChoiceParameter` values and integer ranges in `SearchSpaceDigest.discrete_choices`.
- Teach `RandomGenerator`, and therefore Sobol and Uniform generators, to sample every discrete dimension uniformly by rank and decode it to the actual choice value before constraint checks, rounding, and deduplication.
- Handle purely discrete equality constraints with rejection sampling.
- In the polytope fallback, sample the continuous relaxation in the original value space, project each discrete coordinate to its nearest supported value, and recheck feasibility. Irregular value-to-index mappings are nonlinear, so transforming the polytope to index space would not preserve its linear constraints.
- Avoid calling PyTorch `SobolEngine.fast_forward(0)`: the fresh-engine implementation converts zero to `-1`, while advancing by zero should be a no-op.
- Cover irregular choices, discrete equality constraints, and integer ranges through generator, adapter, generation strategy, and public `Client` tests.

Differential Revision: D113627036
Summary:

Problem:
Random generation previously used `OrderedChoiceToIntegerRange`, which encoded ordered numeric choices as integer indices while leaving parameter constraints in the original value space. Constraints could therefore be checked against indices and produce candidates that violated the user-defined constraint after transforming back. This also prevented correct handling of irregularly spaced choices.

What Changed:
- Add a choice-preserving transform base shared by random generators and MBM, using `ChoiceToNumericChoice` without `IntToFloat` or model-side `UnitX` for random generation.
- Preserve numeric `ChoiceParameter` values and integer ranges in `SearchSpaceDigest.discrete_choices`.
- Teach `RandomGenerator`, and therefore Sobol and Uniform generators, to sample every discrete dimension uniformly by rank and decode it to the actual choice value before constraint checks, rounding, and deduplication.
- Handle purely discrete equality constraints with rejection sampling.
- In the polytope fallback, sample the continuous relaxation in the original value space, project each discrete coordinate to its nearest supported value, and recheck feasibility. Irregular value-to-index mappings are nonlinear, so transforming the polytope to index space would not preserve its linear constraints.
- Avoid calling PyTorch `SobolEngine.fast_forward(0)`: the fresh-engine implementation converts zero to `-1`, while advancing by zero should be a no-op.
- Cover irregular choices, discrete equality constraints, and integer ranges through generator, adapter, generation strategy, and public `Client` tests.

Differential Revision: D113627036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants