facebookresearch / nevergrad

A Python toolbox for performing gradient-free optimization
https://facebookresearch.github.io/nevergrad/
MIT License
3.89k stars 349 forks source link

CMA optimizer error: InjectionWarning: orphanated injected solution #1609

Open andrewjgray1001 opened 1 month ago

andrewjgray1001 commented 1 month ago

Steps to reproduce

  1. create instance of ng.optimizers.CMA
  2. call minimize with a lot of workers

note: this is using a pre-existing utility called Model_Evaluator which parallelizes requests across multiple processes/machines, it has been used extensively in optimizations and has never given any problems. In this example it is set to work with 40 processes. The threadPoolExecutor is just a device to forward multiple calls to the evaluator.

The error implies that if there is too high a degree of parallelization, the logic inside minimize fails, because the function requests (ask) somehow get out of sync with the results returned (tell). The same error occurs whether batch mode is True or False.

Observed Results

the optimizer runs for a while, probably running several hundred evaluations, then produces regular errors like:

evolution_strategy.py:2981: InjectionWarning: orphanated injected solution

then fails with error:

RuntimeError: Mean shift samples are expected but missing. This happens if, for example, ask is called more than once, without calling tell (because the first call removes the samples from the injection list). cma.sigma_adaptation.CMAAdaptSigmaTPA step-size adaptation generates mean shift samples and relies on them.

Expected Results

The optimizer should work

Relevant Code

 # Set up the optimizer
optimizer = ng.optimizers.CMA(parametrization=num_weights, budget=1000000, num_workers=num_workers)

model_eval = Model_Evaluator(config)

with futures.ThreadPoolExecutor(max_workers=optimizer.num_workers) as executor:
    recommendation = optimizer.minimize(model_eval.f_eval, executor=executor, batch_mode=True)