Use cached trials for intersection search space calculation#6291
Use cached trials for intersection search space calculation#6291nabenabe0928 merged 2 commits intooptuna:masterfrom
Conversation
5885e37 to
2e0e3ce
Compare
|
@nabenabe0928, could you review this PR? |
gen740
left a comment
There was a problem hiding this comment.
LGTM!
I confirmed that this PR is actually faster.
Master
Benchmark 1: python3 pr6291.py
Time (mean ± σ): 11.597 s ± 0.535 s [User: 9.963 s, System: 1.400 s]
Range (min … max): 10.644 s … 12.332 s 10 runs
This PR
Benchmark 1: python3 pr6291.py
Time (mean ± σ): 10.290 s ± 0.187 s [User: 8.685 s, System: 1.381 s]
Range (min … max): 10.041 s … 10.711 s 10 runs
nabenabe0928
left a comment
There was a problem hiding this comment.
I checked except trial.py!
| self.relative_search_space = self.study.sampler.infer_relative_search_space( | ||
| study, self._cached_frozen_trial | ||
| ) |
There was a problem hiding this comment.
Could you explain why we need to move the call here?
There was a problem hiding this comment.
_get_trials(..., use_cache=use_cache) creates the cache during the first call in that trial. Therefore, this call should be delayed until it's actually needed. For example, in the following objective function, calling infer_relative_search_space in __init__ would be premature:
def objective(trial):
# Very time-consuming initialization process.
...
# Then perform the suggestion.
trial.suggest_xxx(...)There was a problem hiding this comment.
Thanks, this makes a lot of sense.
nabenabe0928
left a comment
There was a problem hiding this comment.
Almost LGTM!
I left a minor comment, please address this comment!
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
nabenabe0928
left a comment
There was a problem hiding this comment.
Thank you for the change, LGTM!
Motivation
The current implementation of
TPESamplerdoes not utilize cached trials when computing the search space. This PR addresses the issue by delaying the execution ofinfer_relative_search_spaceuntil absolutely necessary and performing it concurrently withsample_relative, thus enabling the use of cached trials. Additionally, theTPESampler'sinfer_relative_search_spacemethod now incorporates caching functionality.(While the same performance optimizations are possible for other sampler implementations, for PR brevity, I focus on
TPESamplerhere.)Description of the changes
This PR introduces a
use_cacheargument forIntersectionSearchSpaceand_GroupDecomposedSearchSpaceand makesTPESamplerusing cached trials for intersection search space calculation.Benchmark
group=Falsegroup=True