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

Support saving search space in experiment load&save command #2886

Merged
merged 28 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dcd2ffd
Merge pull request #251 from microsoft/master
SparkSnail May 29, 2020
3b8b6fb
Merge pull request #252 from microsoft/master
SparkSnail Jun 7, 2020
916e444
Merge pull request #253 from microsoft/master
SparkSnail Jun 15, 2020
caeffb8
Merge pull request #254 from microsoft/master
SparkSnail Jun 17, 2020
57c300e
Merge pull request #255 from microsoft/master
SparkSnail Jun 28, 2020
65660e6
Merge pull request #257 from microsoft/master
SparkSnail Jun 30, 2020
9376d6a
Merge pull request #258 from microsoft/master
SparkSnail Jul 1, 2020
5fef3cf
Merge pull request #259 from microsoft/master
SparkSnail Jul 3, 2020
5544ae8
Merge pull request #261 from microsoft/master
SparkSnail Jul 10, 2020
f9fdfee
Merge pull request #262 from microsoft/master
SparkSnail Jul 16, 2020
c5e26ef
add trial job detail link
SparkSnail Jul 19, 2020
10a04ba
Merge branch 'master' of https://github.com/SparkSnail/nni
SparkSnail Jul 23, 2020
aa64fe6
Merge pull request #263 from microsoft/master
SparkSnail Jul 27, 2020
4ed907f
Merge branch 'master' of https://github.com/SparkSnail/nni
SparkSnail Jul 27, 2020
c6a5f8c
Merge pull request #264 from microsoft/master
SparkSnail Jul 31, 2020
68abe2f
Merge pull request #265 from microsoft/master
SparkSnail Aug 4, 2020
c2b50d2
Merge branch 'master' of https://github.com/SparkSnail/nni
SparkSnail Aug 6, 2020
14e9619
Merge pull request #266 from microsoft/master
SparkSnail Aug 13, 2020
f69e206
Merge pull request #267 from microsoft/master
SparkSnail Aug 13, 2020
a5bb753
Merge branch 'master' of https://github.com/SparkSnail/nni
SparkSnail Aug 21, 2020
12ef0aa
Merge pull request #270 from microsoft/master
SparkSnail Sep 10, 2020
7600a0f
Merge branch 'master' of https://github.com/SparkSnail/nni
SparkSnail Sep 10, 2020
ec61b08
init
SparkSnail Sep 11, 2020
6450fe8
fix pylint
SparkSnail Sep 11, 2020
00d52d9
update doc
SparkSnail Sep 11, 2020
a39ccef
fix comments
SparkSnail Sep 11, 2020
7573887
fix comments
SparkSnail Sep 15, 2020
63a9d06
fix comments
SparkSnail Sep 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en_US/Tutorial/Nnictl.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ Debug mode will disable version check function in Trialkeeper.
|--path, -p| True| |the file path of nni package|
|--codeDir, -c| True| |the path of codeDir for loaded experiment, this path will also put the code in the loaded experiment package|
|--logDir, -l| False| |the path of logDir for loaded experiment|
|--searchSpacePath, -s| True| |the path of search space file for loaded experiment, this path contains file name.|

* Examples

Expand Down
2 changes: 2 additions & 0 deletions tools/nni_cmd/nnictl.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def parse_args():
parser_load_experiment.add_argument('--codeDir', '-c', required=True, help='the path of codeDir for loaded experiment, \
this path will also put the code in the loaded experiment package')
parser_load_experiment.add_argument('--logDir', '-l', required=False, help='the path of logDir for loaded experiment')
parser_load_experiment.add_argument('--searchSpacePath', '-s', required=True, help='the path of search space file for \
Copy link
Contributor

@chicm-ms chicm-ms Sep 13, 2020

Choose a reason for hiding this comment

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

Some experiments do not have search space.
Even for the experiment with search space, can we just load search space file to codeDir by default? If there is an naming conflict loading search space into codeDir, then we report error and ask use to specify --searchSpacePath.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

loaded experiment, this path contains file name.')
parser_load_experiment.set_defaults(func=load_experiment)

#parse platform command
Expand Down
36 changes: 34 additions & 2 deletions tools/nni_cmd/nnictl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,17 @@ def save_experiment(args):
temp_code_dir = os.path.join(temp_root_dir, 'code')
shutil.copytree(nni_config.get_config('experimentConfig')['trial']['codeDir'], temp_code_dir)

# Step4. Archive folder
# Step4. Copy searchSpace file
search_space_path = nni_config.get_config('experimentConfig')['searchSpacePath']
if not os.path.exists(search_space_path):
print_error('search space %s does not exist!' % search_space_path)
else:
temp_search_space_dir = os.path.join(temp_root_dir, 'searchSpace')
os.makedirs(temp_search_space_dir, exist_ok=True)
search_space_name = os.path.basename(search_space_path)
shutil.copyfile(search_space_path, os.path.join(temp_search_space_dir, search_space_name))

# Step5. Archive folder
zip_package_name = 'nni_experiment_%s' % args.id
if args.path:
os.makedirs(args.path, exist_ok=True)
Expand All @@ -844,6 +854,9 @@ def load_experiment(args):
if not os.path.exists(args.path):
print_error('file path %s does not exist!' % args.path)
exit(1)
if os.path.isdir(args.searchSpacePath):
print_error('search space path should be a full path with filename, not a directory!')
exit(1)
temp_root_dir = generate_temp_dir()
shutil.unpack_archive(package_path, temp_root_dir)
print_normal('Loading...')
Expand Down Expand Up @@ -929,7 +942,26 @@ def load_experiment(args):
else:
shutil.copy(src_path, target_path)

# Step5. Create experiment metadata
# Step5. Copy searchSpace file
archive_search_space_dir = os.path.join(temp_root_dir, 'searchSpace')
target_path = os.path.expanduser(args.searchSpacePath)
if not os.path.isabs(target_path):
target_path = os.path.join(os.getcwd(), target_path)
print_normal('Expand search space path to %s' % target_path)
nnictl_exp_config['searchSpacePath'] = target_path
# if the path alerady has a search space file, use the original one, otherwise use archived one
Copy link
Contributor

Choose a reason for hiding this comment

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

already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

if not os.path.isfile(target_path):
if len(os.listdir(archive_search_space_dir)) == 0:
print_error('Archive file does not contain search space file!')
exit(1)
else:
for file in os.listdir(archive_search_space_dir):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a dir?

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 storage data and classify. There are a few folders in archive folder, including 'code', 'nnictl', 'experiment', 'searchSpace', the search space file's name is random, put this file into 'searchSpace' folder for identify.

source_path = os.path.join(archive_search_space_dir, file)
os.makedirs(os.path.dirname(target_path), exist_ok=True)
shutil.copyfile(source_path, target_path)
break
Copy link
Contributor

Choose a reason for hiding this comment

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

Throw error when no file is found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is already a judgement in lint 955, don't need to throw error here anymore.


# Step6. Create experiment metadata
nni_config.set_config('experimentConfig', nnictl_exp_config)
experiment_config.add_experiment(experiment_id,
experiment_metadata.get('port'),
Expand Down