备注
Click here to download the full example code
简单的并行化
并行化非常直接 optuna.study.Study.optimize()
.
如果你想要手动执行 Optuna 的优化:
启动一个 RDB 服务器(在本例中我们用 MySQL)
通过 –storage 参数创建 study
在多个节点和进程之间共享 study
当然,你可以像 the kubernetes examples 里一样使用 Kubernetes.
要看并行优化怎么进行的化,请查看下面这个视频。
创建 study
你可以通过 optuna create-study
来创建 study.或者在 Python 脚本中通过 optuna.create_study()
也行。
$ mysql -u root -e "CREATE DATABASE IF NOT EXISTS example"
$ optuna create-study --study-name "distributed-example" --storage "mysql://root@localhost/example"
[I 2020-07-21 13:43:39,642] A new study created with name: distributed-example
然后写一个优化脚本。假设 foo.py
包含了以下代码。
import optuna
def objective(trial):
x = trial.suggest_float("x", -10, 10)
return (x - 2) ** 2
if __name__ == "__main__":
study = optuna.load_study(
study_name="distributed-example", storage="mysql://root@localhost/example"
)
study.optimize(objective, n_trials=100)