-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support saving search space in experiment load&save command #2886
Changes from 25 commits
dcd2ffd
3b8b6fb
916e444
caeffb8
57c300e
65660e6
9376d6a
5fef3cf
5544ae8
f9fdfee
c5e26ef
10a04ba
aa64fe6
4ed907f
c6a5f8c
68abe2f
c2b50d2
14e9619
f69e206
a5bb753
12ef0aa
7600a0f
ec61b08
6450fe8
00d52d9
a39ccef
7573887
63a9d06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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...') | ||
|
@@ -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 | ||
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. already 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. 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): | ||
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. Why do we need a dir? 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. 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 | ||
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. Throw error when no file is found? 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. 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'), | ||
|
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.
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.
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.
updated.