Created
May 12, 2023 01:26
-
-
Save c-bata/fa8efc075e86a1f7e6dd6d83b85c1017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import time | |
import optuna | |
import numpy as np | |
def objective(trial: optuna.Trial, n_params: int) -> float: | |
return sum([ | |
math.sin(trial.suggest_float('param-{}'.format(i), 0, math.pi * 2)) | |
for i in range(n_params) | |
]) | |
def main(): | |
storage_url = "mysql+pymysql://optuna:[email protected]:3306/optuna" | |
sampler = optuna.samplers.TPESampler(seed=1) | |
optuna.logging.set_verbosity(optuna.logging.ERROR) | |
for n_params in [5, 30]: | |
elapsed = [] | |
for i in range(5): | |
study = optuna.create_study(storage=storage_url, sampler=sampler) | |
start = time.time() | |
study.optimize(lambda t: objective(t, n_params=n_params), n_trials=100) | |
elapsed.append(time.time() - start) | |
optuna.delete_study(study_name=study.study_name, storage=storage_url) | |
print(f"Elapsed {n_params=}: {np.mean(elapsed):.4f} (+/- {np.std(elapsed):.4f})s", elapsed) | |
if __name__ == '__main__': | |
main() |
Branch | n_params=5 (Average Time ± Std Deviation) (s) |
n_params=30 (Average Time ± Std Deviation) (s) |
---|---|---|
PR 4631 | 10.1026 ± 0.1046 | 35.8279 ± 0.1306 |
cache-set-trial-state-values | 9.6567 ± 0.1974 | 35.8301 ± 0.1761 |
main | 7.6167 ± 0.0959 | 32.8131 ± 0.1010 |
v3.1.1 | 9.0216 ± 0.1590 | 42.7193 ± 0.1940 |
PR 4672
$ python tmp/benchmark_mysql.py
Elapsed n_params=5: 10.6553 (+/- 0.1029)s [10.456530094146729, 10.68004822731018, 10.673655033111572, 10.745635986328125, 10.720831871032715]
Elapsed n_params=30: 38.3893 (+/- 1.0469)s [40.44225525856018, 38.048758029937744, 38.034186124801636, 37.936782121658325, 37.484426975250244]
master ee15fcc95
$ python tmp/benchmark_mysql.py
Elapsed n_params=5: 10.7897 (+/- 0.0556)s [10.832643032073975, 10.73856782913208, 10.873303890228271, 10.728083848953247, 10.77579402923584]
Elapsed n_params=30: 38.0671 (+/- 0.5129)s [37.734352111816406, 39.08030891418457, 37.885014057159424, 37.919699907302856, 37.71600008010864
Branch | n_params=5 (Average Time ± Std Deviation) (s) |
n_params=30 (Average Time ± Std Deviation) (s) |
---|---|---|
master ee15fcc95 |
10.7897 (+/- 0.0556) | 38.0671 (+/- 0.5129) |
PR 4672 | 10.6553 (+/- 0.1029) | 38.3893 (+/- 1.0469) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup MySQL database
Benchmark result
PR 4631
cache-set-trial-state-values
I rejected this change due to similar speed as PR 4631 branch.
main
v3.1.1