Avoid duplications in _log_gauss_mass evaluations#6202
Merged
nabenabe0928 merged 10 commits intooptuna:masterfrom Jul 25, 2025
Merged
Conversation
Contributor
Author
|
@not522 @kAIto47802 |
Contributor
Author
Important 49% Speedup 🚀 Benchmarking Codeimport optuna
def objective(trial: optuna.Trial) -> float:
f1 = sum(trial.suggest_float(f"x{i}", -5, 5)**2 for i in range(5))
f2 = sum(trial.suggest_float(f"x{i+5}", -5, 5, step=0.5)**2 for i in range(5))
return f1 + f2
sampler = optuna.samplers.TPESampler(seed=0, multivariate=True)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=1000)
print((study.trials[-1].datetime_complete - study.trials[0].datetime_start).total_seconds()) |
…licated-eval-of-log-gauss-mass
Merged
kAIto47802
approved these changes
Jul 25, 2025
Collaborator
kAIto47802
left a comment
There was a problem hiding this comment.
LGTM!
I confirmed that the benchmark code you provided produces exactly the same output on the branch in this PR (8ff8e8f510725eb7f7789eefe01c729f91944fac) and the current master branch (49b26b384774e96243c6115423a9e16ac9802183) using the following code:
#!/bin/bash
git switch master
master=$(git rev-parse HEAD)
python benckmark.py > ${master}.txt
git switch nabenabe0928/enhance/avoid-duplicated-eval-of-log-gauss-mass
refactor=$(git rev-parse HEAD)
python benckmark.py > ${refactor}.txt
if cmp -s ${master}.txt ${refactor}.txt; then
echo "Both branches produce the same output."
exit 0
else
echo "The outputs differ between the branches."
exit 1
fi
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
This PR speeds up
_log_gauss_massevaluations forTPESampler.Description of the changes
np.unique_inverseequivalent operation to avoid duplicationsnp.unique_inversefor speedup_truncnorm._log_gauss_masswith the new implementation