8000 Adds a warning message to suggestion metadata for NaNs encountered in acquisition function optimization by copybara-service[bot] · Pull Request #1263 · google/vizier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adds a warning message to suggestion metadata for NaNs encountered in acquisition function optimization #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
24 changes: 20 additions & 4 deletions vizier/_src/algorithms/optimizers/vectorized_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
VectorizedOptimizerInput = types.ContinuousAndCategorical[types.Array]


ACQUISITION_OPTIMIZATION_WARNING_KEY = 'acquisition_optimization_warning'


class RandomSampler(abc.ABC):
"""Random sampler for vectorized optimizer."""

Expand Down Expand Up @@ -622,13 +625,26 @@ def best_candidates_to_trials(
)[0]
)
metadata = trial.metadata.ns('devinfo')
aux_tree = jax.tree.map(
lambda x, ind=ind: np.asarray(x[ind]), best_results.aux
)
metadata['acquisition_optimization'] = json.dumps(
{'acquisition': best_results.rewards[ind]}
| jax.tree.map(
lambda x, ind=ind: np.asarray(x[ind]), best_results.aux
),
{'acquisition': best_results.rewards[ind]} | aux_tree,
cls=json_utils.NumpyEncoder,
)
leaves, _ = jax.tree.flatten(
{
'acquisition': best_results.rewards[ind],
'aux': aux_tree,
},
)
any_nan = any([jnp.isnan(leaf).any() for leaf in leaves])
if an 8000 y_nan:
metadata[ACQUISITION_OPTIMIZATION_WARNING_KEY] = (
'NaNs encountered in acquisition optimization. See the'
' "acquisition_optimization" field in the metadata for more'
' details.'
)

trial.complete(vz.Measurement({'acquisition': reward}))
trials.append(trial)
Expand Down
42 changes: 42 additions & 0 deletions vizier/_src/algorithms/optimizers/vectorized_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,48 @@ def test_best_candidates_count_is_3(self, use_fori):
-((0.4 - 0.52) ** 2),
)

@parameterized.named_parameters(
('score_nan_aux_ok', jnp.nan, 1.0), ('score_ok_aux_nan', -2.0, jnp.nan)
)
def test_best_candidates_to_trials_warnings_on_nans(
self, score_value: float, aux1_value: float
):
problem = vz.ProblemStatement()
problem.search_space.root.add_float_param('f1', 0.0, 1.0)
problem.search_space.root.add_float_param('f2', 0.0, 1.0)
converter = converters.TrialToModelInputConverter.from_problem(problem)
score_with_aux_fn = lambda x, seed: (
score_value * jnp.ones(x.continuous.padded_array.shape[0]),
{
'aux1': aux1_value * jnp.ones(x.continuous.padded_array.shape[0]),
'aux2': 5.0 * jnp.ones(x.continuous.padded_array.shape[0]),
},
)
optimizer = vb.VectorizedOptimizerFactory(
strategy_factory=fake_increment_strategy_factory,
suggestion_batch_size=5,
max_evaluations=10,
)(converter=converter)
best_candidates_array = optimizer(
score_fn=lambda x, seed: score_with_aux_fn(x, seed)[0],
score_with_aux_fn=score_with_aux_fn,
count=1,
)
best_candidates = vb.best_candidates_to_trials(
best_candidates_array, converter=converter
)
self.assertLen(best_candidates, 1)
self.assertIn(
vb.ACQUISITION_OPTIMIZATION_WARNING_KEY,
best_candidates[0].metadata.ns('devinfo'),
)
self.assertIn(
'NaN',
best_candidates[0].metadata.ns('devinfo')[
vb.ACQUISITION_OPTIMIZATION_WARNING_KEY
],
)

def test_vectorized_optimizer_factory(self):
problem = vz.ProblemStatement()
problem.search_space.root.add_float_param('f1', 0.0, 1.0)
Expand Down
0