Skip to content

Remove unnecessary deep-copies.#1135

Merged
sile merged 1 commit intooptuna:masterfrom
ytsmiling:remove-unnecessary-deep-copy
Apr 19, 2020
Merged

Remove unnecessary deep-copies.#1135
sile merged 1 commit intooptuna:masterfrom
ytsmiling:remove-unnecessary-deep-copy

Conversation

@ytsmiling
Copy link
Copy Markdown
Member

This PR removes unnecessary deep-copies. This PR significantly speeds up in-memory execution, which is the default setting of optuna.

Microbench with 1000 trials and 30 params (CPU: Intel Core i7-6700K, python: 3.5.2):

Master:
         1546802373 function calls (1310307516 primitive calls) in 627.117 seconds
This PR:
         234867048 function calls (211661688 primitive calls) in 170.741 seconds

Code:

import argparse
import cProfile
import math

import optuna


def objective(trial):
    return sum(
        math.sin(trial.suggest_float('param-{}'.format(i), 0, math.pi * 2))
        for i in range(30)
    )


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('n_trial', type=int)
    args = parser.parse_args()
    sampler = optuna.samplers.TPESampler(consider_prior=False)
    study = optuna.create_study(sampler=sampler)
    cProfile.run(
        "study.optimize(objective, n_trials=args.n_trial, gc_after_trial=False)",
        sort="cumtime"
    )

@codecov-io
Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@93a55d7). Click here to learn what that means.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1135   +/-   ##
=========================================
  Coverage          ?   90.39%           
=========================================
  Files             ?      128           
  Lines             ?    11187           
  Branches          ?        0           
=========================================
  Hits              ?    10113           
  Misses            ?     1074           
  Partials          ?        0           
Impacted Files Coverage Δ
optuna/study.py 92.83% <100.00%> (ø)
optuna/exceptions.py 100.00% <0.00%> (ø)
tests/visualization_tests/test_contour.py 96.96% <0.00%> (ø)
optuna/visualization/utils.py 77.77% <0.00%> (ø)
optuna/samplers/cmaes.py 77.93% <0.00%> (ø)
optuna/integration/chainer.py 80.85% <0.00%> (ø)
tests/integration_tests/test_sampler.py 97.80% <0.00%> (ø)
optuna/integration/chainermn.py 77.40% <0.00%> (ø)
optuna/testing/sampler.py 63.15% <0.00%> (ø)
optuna/importance/_fanova.py 87.14% <0.00%> (ø)
... and 119 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93a55d7...d403e26. Read the comment docs.

@ytsmiling ytsmiling added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Apr 19, 2020
@ytsmiling
Copy link
Copy Markdown
Member Author

Related PR: #1139.

@sile sile added this to the v1.4.0 milestone Apr 19, 2020
Copy link
Copy Markdown
Member

@sile sile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Change that does not break compatibility and not affect public interfaces, but improves performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants