New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BaseStorage.set_trial_param
to return None
instead of bool
.
#1327
Conversation
tests/test_trial.py
Outdated
assert trial.suggest_float("h", 0.5, 0.5, step=1.0) == 0.5 # Suggesting a param. | ||
assert trial.suggest_float("h", 0.5, 0.5, step=1.0) == 0.5 # Suggesting the same param. | ||
assert trial.suggest_int("i", 1, 1, log=True) == 1 # Suggesting a param. | ||
assert trial.suggest_int("i", 1, 1, log=True) == 1 # Suggesting the same param. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can remove this test function altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it useful to make sure that sampler.sample_independent
is not called. If you don't want to add the check, I think you can remove this test function.
If you remove this test, I'm not sure if there is a test that calls the distributions._get_single_value ()
method. I want to make sure that tests for the method are added when you remove this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, thanks for you suggestion. I changed this test to check the number of calls to distributions._get_single_value
. What do you think?
Codecov Report
@@ Coverage Diff @@
## master #1327 +/- ##
==========================================
+ Coverage 86.69% 87.85% +1.16%
==========================================
Files 95 98 +3
Lines 7412 7339 -73
==========================================
+ Hits 6426 6448 +22
+ Misses 986 891 -95
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for creating this PR.
Please correct me if it's wrong but does this PR remove distribution compatibility check across trials (both within a single worker and across multiple workers)? If yes, I think this point needs discussion.
You are right, we should probably not change this behavior. Do you think we should put the check back to the storage? IMO, we can move this check to the trial to simplify the storage logic since it's possible with the current storage API. However, it might be suboptimal (if there are lots of conditionals) and we'll probably want some other storage API to optimize this check in follow-ups. |
BaseStorage.set_trial_param
to return None
instead of bool
.BaseStorage.set_trial_param
to return None
instead of bool
.
Let me fix the code so that the logic isn't altered for the case you described. I'll add tests on the trial layer as well. |
710032a
to
d463f3b
Compare
BaseStorage.set_trial_param
to return None
instead of bool
.BaseStorage.set_trial_param
to return None
instead of bool
.
PTAL. I moved the distribution compatibility back to the storage from the trial. The reason being that we cannot keep the same behavior explained by @ytsmiling above otherwise. If we try to check for compatibility in the trial, we cannot guarantee the expected behavior in a distributed environment where all initial trials sample the same parameter (having the same name) but with different distributions as they're exposed to race condition when writing the sampled parameter back to the storage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing #1308. This PR looks almost good, but I left a minor comment and I'd like you to check that.
tests/test_trial.py
Outdated
assert trial.suggest_float("h", 0.5, 0.5, step=1.0) == 0.5 # Suggesting a param. | ||
assert trial.suggest_float("h", 0.5, 0.5, step=1.0) == 0.5 # Suggesting the same param. | ||
assert trial.suggest_int("i", 1, 1, log=True) == 1 # Suggesting a param. | ||
assert trial.suggest_int("i", 1, 1, log=True) == 1 # Suggesting the same param. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it useful to make sure that sampler.sample_independent
is not called. If you don't want to add the check, I think you can remove this test function.
If you remove this test, I'm not sure if there is a test that calls the distributions._get_single_value ()
method. I want to make sure that tests for the method are added when you remove this test.
Right, thanks for the suggestion about the test. I changes it to count the number of calls to PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the quick fix. LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It basically looks good to me. I add a comment about a test case, but I think it is optional.
if self._is_fixed_param(name, distribution): | ||
param_value = storage.get_trial_system_attrs(trial_id)["fixed_params"][name] | ||
elif distribution.single(): | ||
param_value = distributions._get_single_value(distribution) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is optional, but how about adding a test case to raise warnings if single-value distributions are given with fixed params that are out of ranges? This code correctly handles such a case, and I propose it for future development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion. I added tests for enqueue_trial
since it's relevant (although a bit stretched) to this PR.
PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your swift action! LGTM.
Motivation
See #1308.
Description of the changes
Fixes #1308 and the following.
Trial
by removing_set_new_param_or_get_existing
.