This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add built-in tuner test in CI #112
Closed
+122
−8
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
# Integration Test | ||
cd naive && python3 run.py | ||
# Built-in Tuner Test | ||
cd ../test_builtin_tuner/ && python3 run.py |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
authorName: nni | ||
experimentName: test_builtin_tuner | ||
maxExecDuration: 1h | ||
maxTrialNum: 2 | ||
searchSpacePath: search_space.json | ||
trainingServicePlatform: local | ||
trial: | ||
codeDir: . | ||
command: python3 naive_trial.py | ||
gpuNum: 0 | ||
trialConcurrency: 2 | ||
tuner: | ||
builtinTunerName: Evolution | ||
classArgs: | ||
optimize_mode: maximize | ||
useAnnotation: false |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import nni | ||
|
||
params = nni.get_parameters() | ||
print('params:', params) | ||
x = params['x'] | ||
|
||
nni.report_final_result(x) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure shall we add license here....@quanlu zhang There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, could add license here |
||
|
||
import contextlib | ||
import json | ||
import os | ||
import subprocess | ||
import time | ||
import traceback | ||
import yaml | ||
|
||
GREEN = '\33[32m' | ||
RED = '\33[31m' | ||
CLEAR = '\33[0m' | ||
|
||
TUNER_LIST = ['TPE', 'Random', 'Anneal', 'Evolution'] | ||
|
||
def read_last_line(file_name): | ||
try: | ||
*_, last_line = open(file_name) | ||
return last_line.strip() | ||
except (FileNotFoundError, ValueError): | ||
return None | ||
|
||
def get_yml_content(file_path): | ||
'''Load yaml file content''' | ||
with open(file_path, 'r') as file: | ||
return yaml.load(file) | ||
|
||
def dump_yml_content(file_path, content): | ||
'''Dump yaml file content''' | ||
with open(file_path, 'w') as file: | ||
file.write(yaml.dump(content, default_flow_style=False)) | ||
|
||
def switch_tuner(tuner_name): | ||
'''Change tuner in config.yml''' | ||
config_path = 'local.yml' | ||
experiment_config = get_yml_content(config_path) | ||
experiment_config['tuner'] = { | ||
'builtinTunerName': tuner_name, | ||
'classArgs': { | ||
'optimize_mode': 'maximize' | ||
} | ||
} | ||
dump_yml_content(config_path, experiment_config) | ||
|
||
def test_builtin_tuner(tuner_name): | ||
with contextlib.suppress(FileNotFoundError): | ||
os.remove('/tmp/nni_tuner_result.txt') | ||
switch_tuner(tuner_name) | ||
|
||
print('Testing %s...'%tuner_name) | ||
proc = subprocess.run(['nnictl', 'create', '--config', 'local.yml']) | ||
assert proc.returncode == 0, '`nnictl create` failed with code %d' % proc.returncode | ||
|
||
time.sleep(16) | ||
tuner_status = read_last_line('/tmp/nni_tuner_result.txt') | ||
|
||
assert tuner_status is not None, 'Failed to finish in 16 sec' | ||
assert tuner_status == 'DONE', 'Tuner exited with error' | ||
|
||
if __name__ == '__main__': | ||
|
||
os.environ['PATH'] = os.environ['PATH'] + ':' + os.path.join(os.environ['PWD'],'..') | ||
# Test each built-in tuner | ||
for tuner_name in TUNER_LIST: | ||
try: | ||
test_builtin_tuner(tuner_name) | ||
print(GREEN + 'Test ' +tuner_name+ ' tuner: TEST PASS' + CLEAR) | ||
except Exception as error: | ||
print(GREEN + 'Test ' +tuner_name+ ' tuner: TEST FAIL' + CLEAR) | ||
print('%r' % error) | ||
traceback.print_exc() | ||
raise error | ||
finally: | ||
subprocess.run(['nnictl', 'stop']) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we add all kind of search space to test their format? |
||
"x": | ||
{ | ||
"_type" : "choice", | ||
"_value" : [1, 100] | ||
} | ||
} |
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.
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.
shall we use print as test method?? Or use unit test to instead?