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 preCommand option to support configuring experimental environment by user #2875
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c627afc
Allow users to set pre-command in remote mode
1fd74c5
add doc and example for remote-machineList-preCommand
c8a3d80
add note in doc about using preCommand
1c84f6a
add preCommand UT
22afaa5
make preCommand UT more accurate and fix bug in linuxCommands
01020d8
update preCommand doc
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,3 +107,79 @@ Files in `codeDir` will be uploaded to remote machines automatically. You can ru | |
```bash | ||
nnictl create --config examples/trials/mnist-annotation/config_remote.yml | ||
``` | ||
|
||
### Configure python environment | ||
|
||
By default, commands and scripts will be executed in the default environment in remote machine. If there are multiple python virtual environments in your remote machine, and you want to run experiments in a specific environment, then use __preCommand__ to specify a python environment on your remote machine. | ||
|
||
Use `examples/trials/mnist-tfv2` as the example. Below is content of `examples/trials/mnist-tfv2/config_remote.yml`: | ||
|
||
```yaml | ||
authorName: default | ||
experimentName: example_mnist | ||
trialConcurrency: 1 | ||
maxExecDuration: 1h | ||
maxTrialNum: 10 | ||
#choice: local, remote, pai | ||
trainingServicePlatform: remote | ||
searchSpacePath: search_space.json | ||
#choice: true, false | ||
useAnnotation: false | ||
tuner: | ||
#choice: TPE, Random, Anneal, Evolution, BatchTuner, MetisTuner | ||
#SMAC (SMAC should be installed through nnictl) | ||
builtinTunerName: TPE | ||
classArgs: | ||
#choice: maximize, minimize | ||
optimize_mode: maximize | ||
trial: | ||
command: python3 mnist.py | ||
codeDir: . | ||
gpuNum: 0 | ||
#machineList can be empty if the platform is local | ||
machineList: | ||
- ip: ${replace_to_your_remote_machine_ip} | ||
username: ${replace_to_your_remote_machine_username} | ||
sshKeyPath: ${replace_to_your_remote_machine_sshKeyPath} | ||
# Pre-command will be executed before the remote machine executes other commands. | ||
# Below is an example of specifying python environment. | ||
# If you want to execute multiple commands, please use "&&" to connect them. | ||
# preCommand: source ${replace_to_absolute_path_recommended_here}/bin/activate | ||
# preCommand: source ${replace_to_conda_path}/bin/activate ${replace_to_conda_env_name} | ||
preCommand: export PATH=${replace_to_python_environment_path_in_your_remote_machine}:$PATH | ||
``` | ||
|
||
The __preCommand__ will be executed before the remote machine executes other commands. So you can configure python environment path like this: | ||
|
||
```yaml | ||
# Linux remote machine | ||
preCommand: export PATH=${replace_to_python_environment_path_in_your_remote_machine}:$PATH | ||
# Windows remote machine | ||
preCommand: set path=${replace_to_python_environment_path_in_your_remote_machine};%path% | ||
``` | ||
|
||
Or if you want to activate the `virtualenv` environment: | ||
|
||
```yaml | ||
# Linux remote machine | ||
preCommand: source ${replace_to_absolute_path_recommended_here}/bin/activate | ||
# Windows remote machine | ||
preCommand: ${replace_to_absolute_path_recommended_here}\\scripts\\activate | ||
``` | ||
|
||
Or if you want to activate the `conda` environment: | ||
|
||
```yaml | ||
# Linux remote machine | ||
preCommand: source ${replace_to_conda_path}/bin/activate ${replace_to_conda_env_name} | ||
# Windows remote machine | ||
preCommand: call activate ${replace_to_conda_env_name} | ||
``` | ||
|
||
If there are multiple commands want to execute, you can use `&&` to connect these commands: | ||
|
||
```yaml | ||
preCommand: command1 && command2 && command3 | ||
``` | ||
|
||
__Note__: Because __preCommand__ will execute before other commands each time, it is strongly not recommended to set __preCommand__ that will make changes to system, i.e. `mkdir` or `touch`. | ||
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. this doc is very clear! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
authorName: default | ||
experimentName: example_mnist | ||
trialConcurrency: 1 | ||
maxExecDuration: 1h | ||
maxTrialNum: 10 | ||
#choice: local, remote, pai | ||
trainingServicePlatform: remote | ||
searchSpacePath: search_space.json | ||
#choice: true, false | ||
useAnnotation: false | ||
tuner: | ||
#choice: TPE, Random, Anneal, Evolution, BatchTuner, MetisTuner | ||
#SMAC (SMAC should be installed through nnictl) | ||
builtinTunerName: TPE | ||
classArgs: | ||
#choice: maximize, minimize | ||
optimize_mode: maximize | ||
trial: | ||
command: python3 mnist.py | ||
codeDir: . | ||
gpuNum: 0 | ||
#machineList can be empty if the platform is local | ||
machineList: | ||
- ip: ${replace_to_your_remote_machine_ip} | ||
username: ${replace_to_your_remote_machine_username} | ||
sshKeyPath: ${replace_to_your_remote_machine_sshKeyPath} | ||
# Pre-command will be executed before the remote machine executes other commands. | ||
# Below is an example of specifying python environment. | ||
# If you want to execute multiple commands, please use "&&" to connect them. | ||
# preCommand: source ${replace_to_absolute_path_recommended_here}/bin/activate | ||
# preCommand: source ${replace_to_conda_path}/bin/activate ${replace_to_conda_env_name} | ||
preCommand: export PATH=${replace_to_python_environment_path_in_your_remote_machine}:$PATH |
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
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
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
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.
"If there are multiple commands want to execute" -> "If you want multiple commands to be executed"