NatLibFi / Annif

Annif is a multi-algorithm automated subject indexing tool for libraries, archives and museums.
https://annif.org
Other
204 stars 41 forks source link

Update to Optuna 3.x to get rid of deprecation message #532

Closed osma closed 1 year ago

osma commented 3 years ago

In recent versions of Annif (which use Optuna 2.8.0), running the annif hyperopt command with a --jobs parameter gives the following warning:

FutureWarning: `n_jobs` argument has been deprecated in v2.7.0. This feature will be removed in v4.0.0. See https://github.com/optuna/optuna/releases/tag/v2.7.0.

The Optuna documentation for the 2.7.0 release explains that process-based parallelism should be used instead (tutorial). But that would require a PostgreSQL or MySQL database (SQLite is possible but not recommended).

Another option is to keep using thread-level parallelism using ThreadPoolExecutor instead of the n_jobs parameter. That would be easier to implement at least.

osma commented 2 years ago

It seems that Optuna has decided to continue supporting the n_jobs parameter after all: https://github.com/optuna/optuna/issues/2937 It is also possible that in the future it will become easier to run Optuna in parallel using real multiprocessing: https://github.com/optuna/optuna/issues/2950

Both of these are on the Optuna version 3 roadmap.

So for now I think we should wait and see what happens on the Optuna side.

osma commented 1 year ago

Optuna 3 has been released (the current release is 3.1.0), the n_jobs option is still present, and even mentioned in the FAQ with the caveat that it's based on multi-threading which is hampered by the GIL. Process-based parallelism would probably be better, but that's a different story and issue.

I'll keep this issue open to remind us to update to Optuna 3.x, which should get rid of the deprecation message.

juhoinkinen commented 1 year ago

In recent versions of Annif (which use Optuna 2.8.0), running the annif hyperopt command with a --jobs parameter gives the following warning:

FutureWarning: `n_jobs` argument has been deprecated in v2.7.0. This feature will be removed in v4.0.0. See https://github.com/optuna/optuna/releases/tag/v2.7.0.

When updating now to latest Optuna release, i.e. v3.3.0, the above is not shown, but a different one is:

FutureWarning: suggest_uniform has been deprecated in v3.0.0. This feature will be removed in v6.0.0. See https://github.com/optuna/optuna/releases/tag/v3.0.0. Use suggest_float instead.

When just updating to Optuna 3.3.0 unit tests pass. The migration guide tells that the (new) method trial.suggest_float(“x”, low, high) corresponds to the deprecated method trial.suggest_uniform(“x”, low, high).

osma commented 1 year ago

The https://github.com/optuna/optuna/discussions/3930 tells that the (new) method trial.suggest_float(“x”, low, high) corresponds to the deprecated method trial.suggest_uniform(“x”, low, high).

Okay, let's switch to the new method then! I don't see why it wouldn't work.