Skip to content

Commit

Permalink
Merge pull request #271 from microsoft/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
SparkSnail authored Sep 15, 2020
2 parents 12ef0aa + 98a49b1 commit ddcf229
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 62 deletions.
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- script: |
set -e
sudo apt-get install -y pandoc
python3 -m pip install pygments --user --upgrade
python3 -m pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html --user
python3 -m pip install tensorflow==2.2.0 --user
python3 -m pip install keras==2.4.2 --user
Expand Down
4 changes: 2 additions & 2 deletions deployment/pypi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This is the PyPI build and upload tool for NNI project.
Ubuntu 16.04 LTS
make
wget
Python >= 3.5
Python >= 3.6
Pip
Node.js
Yarn
Expand Down Expand Up @@ -45,7 +45,7 @@ This is the PyPI build and upload tool for NNI project.
```
Windows 10
powershell
Python >= 3.5
Python >= 3.6
Pip
Yarn
```
Expand Down
39 changes: 39 additions & 0 deletions docs/en_US/CommunitySharings/AutoCompletion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Auto Completion for nnictl Commands

NNI's command line tool __nnictl__ support auto-completion, i.e., you can complete a nnictl command by pressing the `tab` key.

For example, if the current command is
```
nnictl cre
```
By pressing the `tab` key, it will be completed to
```
nnictl create
```

For now, auto-completion will not be enabled by default if you install NNI through `pip`, and it only works on Linux with bash shell. If you want to enable this feature on your computer, please refer to the following steps:

### Step 1. Download `bash-completion`
```
cd ~
wget https://raw.githubusercontent.com/microsoft/nni/{nni-version}/tools/bash-completion
```
Here, {nni-version} should by replaced by the version of NNI, e.g., `master`, `v1.9`. You can also check the latest `bash-completion` script [here](https://github.com/microsoft/nni/blob/master/tools/bash-completion).

### Step 2. Install the script
If you are running a root account and want to install this script for all the users
```
install -m644 ~/bash-completion /usr/share/bash-completion/completions/nnictl
```
If you just want to install this script for your self
```
mkdir -p ~/.bash_completion.d
install -m644 ~/bash-completion ~/.bash_completion.d/nnictl
echo '[[ -f ~/.bash_completion.d/nnictl ]] && source ~/.bash_completion.d/nnictl' >> ~/.bash_completion
```

### Step 3. Reopen your terminal
Reopen your terminal and you should be able to use the auto-completion feature. Enjoy!

### Step 4. Uninstall
If you want to uninstall this feature, just revert the changes in the steps above.
1 change: 1 addition & 0 deletions docs/en_US/CommunitySharings/community_sharings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Different from the tutorials and examples in the rest of the document which show
Feature Engineering <feature_engineering>
Performance measurement, comparison and analysis <perf_compare>
Use NNI on Google Colab <NNI_colab_support>
Auto Completion for nnictl Commands <AutoCompletion>
29 changes: 27 additions & 2 deletions docs/en_US/Compressor/QuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ It means following the algorithm's default setting for compressed operations wit

#### Quantization specific keys

**If you use quantization algorithms, you need to specify more keys. If you use pruning algorithms, you can safely skip these keys**
Besides the keys explained above, if you use quantization algorithms you need to specify more keys in `config_list`, which are explained below.

* __quant_types__ : list of string.

Expand All @@ -148,6 +148,31 @@ when the value is int type, all quantization types share same bits length. eg.
}
```

The following example shows a more complete `config_list`, it uses `op_names` (or `op_types`) to specify the target layers along with the quantization bits for those layers.
```
configure_list = [{
'quant_types': ['weight'],
'quant_bits': 8,
'op_names': ['conv1']
}, {
'quant_types': ['weight'],
'quant_bits': 4,
'quant_start_step': 0,
'op_names': ['conv2']
}, {
'quant_types': ['weight'],
'quant_bits': 3,
'op_names': ['fc1']
},
{
'quant_types': ['weight'],
'quant_bits': 2,
'op_names': ['fc2']
}
]
```
In this example, 'op_names' is the name of layer and four layers will be quantized to different quant_bits.

### APIs for Updating Fine Tuning Status

Some compression algorithms use epochs to control the progress of compression (e.g. [AGP](https://nni.readthedocs.io/en/latest/Compressor/Pruner.html#agp-pruner)), and some algorithms need to do something after every minibatch. Therefore, we provide another two APIs for users to invoke: `pruner.update_epoch(epoch)` and `pruner.step()`.
Expand All @@ -168,4 +193,4 @@ pruner.export_model(model_path='model.pth')
pruner.export_model(model_path='model.pth', mask_path='mask.pth', onnx_path='model.onnx', input_shape=[1, 1, 28, 28])
```

If you want to really speed up the compressed model, please refer to [NNI model speedup](./ModelSpeedup.md) for details.
If you want to really speed up the compressed model, please refer to [NNI model speedup](./ModelSpeedup.md) for details.
19 changes: 17 additions & 2 deletions docs/en_US/Tutorial/Nnictl.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Debug mode will disable version check function in Trialkeeper.
> update experiment's trial num

```bash
nnictl update trialnum --id [experiment_id] --value [trial_num]
nnictl update trialnum [experiment_id] --value [trial_num]
```

<a name="trial"></a>
Expand Down Expand Up @@ -347,7 +347,7 @@ Debug mode will disable version check function in Trialkeeper.
> kill trail job
```bash
nnictl trial [trial_id] --experiment [experiment_id]
nnictl trial kill [experiment_id] --trial_id [trial_id]
```
<a name="top"></a>
Expand Down Expand Up @@ -704,6 +704,21 @@ Debug mode will disable version check function in Trialkeeper.
### Manage webui

* __nnictl webui url__
* Description

Show an experiment's webui url
* Usage
```bash
nnictl webui url [options]
```
* Options
|Name, shorthand|Required|Default|Description|
|------|------|------ |------|
|id| False| |Experiment ID|
<a name="tensorboard"></a>
### Manage tensorboard
Expand Down
3 changes: 3 additions & 0 deletions docs/en_US/Tutorial/QuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ python -m pip install --upgrade nni
```eval_rst
.. Note:: For the system requirements of NNI, please refer to :doc:`Install NNI on Linux & Mac <InstallationLinux>` or :doc:`Windows <InstallationWin>`.
```
### Enable NNI Command-line Auto-Completion (Optional)

After the installation, you may want to enable the auto-completion feature for __nnictl__ commands. Please refer to this [tutorial](../CommunitySharings/AutoCompletion.md).

## "Hello World" example on MNIST

Expand Down
1 change: 1 addition & 0 deletions src/webui/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/consistent-type-assertions": 0,
"@typescript-eslint/no-inferrable-types": 0,
"@typescript-eslint/no-use-before-define": [2, "nofunc"],
"no-inner-declarations": 0,
"@typescript-eslint/no-var-requires": 0,
"react/display-name": 0
Expand Down
59 changes: 32 additions & 27 deletions tools/bash-completion
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
# list of commands/arguments
__nnictl_cmds="create resume view update stop trial experiment platform import export webui config log package tensorboard top"
__nnictl_create_cmds="--config --port --debug --watch"
__nnictl_resume_cmds="--port --debug --watch"
__nnictl_cmds="create resume view update stop trial experiment platform webui config log package tensorboard top ss_gen --version"
__nnictl_create_cmds="--config --port --debug --foreground"
__nnictl_resume_cmds="--port --debug --foreground"
__nnictl_view_cmds="--port"
__nnictl_update_cmds="searchspace concurrency duration trialnum"
__nnictl_update_searchspace_cmds="--filename"
__nnictl_update_concurrency_cmds="--value"
__nnictl_update_duration_cmds="--value"
__nnictl_update_trialnum_cmds="--value"
__nnictl_stop_cmds="--port --all"
__nnictl_trial_cmds="ls kill codegen"
__nnictl_trial_cmds="ls kill"
__nnictl_trial_ls_cmds="--head --tail"
__nnictl_trial_kill_cmds="--trial_id"
__nnictl_trial_codegen_cmds="--trial_id"
__nnictl_experiment_cmds="show status list delete"
__nnictl_experiment_cmds="show status list delete export import save load"
__nnictl_experiment_list_cmds="--all"
__nnictl_experiment_delete_cmds="--all"
__nnictl_experiment_export_cmds="--filename --type --intermediate"
__nnictl_experiment_import_cmds="--filename"
__nnictl_experiment_save_cmds="--path --saveCodeDir"
__nnictl_experiment_load_cmds="--path --codeDir --logDir"
__nnictl_platform_cmds="clean"
__nnictl_platform_clean_cmds="--config"
__nnictl_import_cmds="--filename"
__nnictl_export_cmds="--type --filename"
__nnictl_webui_cmds="url"
__nnictl_config_cmds="show"
__nnictl_log_cmds="stdout stderr trial"
__nnictl_log_stdout_cmds="--tail --head --path"
__nnictl_log_stderr_cmds="--tail --head --path"
__nnictl_log_trial_cmds="--trial_id"
__nnictl_package_cmds="install show"
__nnictl_package_cmds="install show list uninstall"
__nnictl_package_install_cmds="--name"
__nnictl_package_list_cmds="--all"
__nnictl_tensorboard_cmds="start stop"
__nnictl_tensorboard_start_cmds="--trial_id --port"
__nnictl_top_cmds="--time"
__nnictl_ss_gen_cmds="--trial_command --trial_dir --file"

# list of commands that accept an experiment ID as second argument
__nnictl_2nd_expid_cmds=" resume view stop import export "
__nnictl_2nd_expid_cmds=" resume view stop top "
# list of commands that accept an experiment ID as third argument
__nnictl_3rd_expid_cmds=" update trial experiment webui config log tensorboard "

Expand All @@ -41,10 +45,12 @@ __nnictl_3rd_expid_cmds=" update trial experiment webui config log tensorboard "
__nnictl_remain_args()
{
local ret=${!1} # ret = $__nnictl_xxx_cmds
# for arg in COMP_WORDS[:-1]:
for arg in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}"; do
local ret=${ret/$arg/} # remove it from $ret
done
# prevent that "--trial_id" changes to "--_id" in this situation: "nnictl trial kill --trial_id"
if [[ ${ret} != "--trial_id" ]]; then
for arg in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}"; do
local ret=${ret/$arg/} # remove it from $ret
done
fi
echo $ret
}

Expand All @@ -63,9 +69,8 @@ _nnictl()
{
local cur=${COMP_WORDS[-1]}
local last=${COMP_WORDS[-2]}

if [[ ${#COMP_WORDS[@]} -eq 2 ]]; then
# completing frst argument from __nnictl_cmds
# completing first argument from __nnictl_cmds
COMPREPLY=($(compgen -W "$__nnictl_cmds" -- "${COMP_WORDS[1]}"))

elif [[ ${#COMP_WORDS[@]} -eq 3 ]]; then
Expand All @@ -79,11 +84,11 @@ _nnictl()
COMPREPLY+=($(compgen -W "$experiments" -- $cur))
fi

elif [[ $last != -* || $last == --debug ]]; then
elif [[ $last != -* || $last == --debug || $last == --foreground || $last == --intermediate || $last == --all ]]; then
# last argument does not starts with "-", so this one is likely to be "--xxx"
local args=__nnictl_${COMP_WORDS[1]}_${COMP_WORDS[2]}_cmds
if [[ $args =~ "-" || -z ${!args} ]]; then
# the second argument starts with "-", use __nnictl_${FirstArg}_cmds
if [[ $args =~ "-" || $__nnictl_2nd_expid_cmds =~ " ${COMP_WORDS[1]} " ]]; then
# the second argument starts with "-" or is an experiment id, use __nnictl_${FirstArg}_cmds
local args=__nnictl_${COMP_WORDS[1]}_cmds
fi
# remove already set arguments from candidates
Expand All @@ -93,12 +98,12 @@ _nnictl()
# if this is 3rd arguments, try adding experiment IDs to candidates
if [[ ${#COMP_WORDS[@]} -eq 4 ]]; then
if [[ $__nnictl_3rd_expid_cmds =~ " ${COMP_WORDS[1]} " && ${COMP_WORDS[2]} != "list" ]]; then
local experiments=$(ls ~/nni/experiments 2>/dev/null)
local experiments=$(ls ~/nni-experiments 2>/dev/null)
COMPREPLY+=($(compgen -W "$experiments" -- $cur))
fi
fi

elif [[ ${COMP_WORDS[1]} == "export" ]]; then
elif [[ ${COMP_WORDS[2]} == "export" ]]; then
# "export" command is somewhat unique
if [[ " --type -t " =~ " $last " ]]; then
COMPREPLY=($(compgen -W "json csv" -- $cur))
Expand All @@ -117,14 +122,14 @@ _nnictl()
__nnictl_complete_extension "$ext"
fi

elif [[ " --trial_id -t " =~ " $last " ]]; then
elif [[ " --trial_id -T " =~ " $last " ]]; then
# complete trial ID
if [[ -e ${HOME}/nni/experiments/${COMP_WORDS[2]} ]]; then
local trials=$(ls -d ~/nni/experiments/${COMP_WORDS[2]}/trials/* 2>/dev/null | grep -o '[^/]*$')
elif [[ -e "${HOME}/nni/experiments/${COMP_WORDS[3]}" ]]; then
local trials=$(ls -d ~/nni/experiments/${COMP_WORDS[3]}/trials/* 2>/dev/null | grep -o '[^/]*$')
if [[ -e ${HOME}/nni-experiments/${COMP_WORDS[2]} ]]; then
local trials=$(ls -d ~/nni-experiments/${COMP_WORDS[2]}/trials/* 2>/dev/null | grep -o '[^/]*$')
elif [[ -e "${HOME}/nni-experiments/${COMP_WORDS[3]}" ]]; then
local trials=$(ls -d ~/nni-experiments/${COMP_WORDS[3]}/trials/* 2>/dev/null | grep -o '[^/]*$')
else
local trials=$(ls -d ~/nni/experiments/*/trials/* 2>/dev/null | grep -o '[^/]*$')
local trials=$(ls -d ~/nni-experiments/*/trials/* 2>/dev/null | grep -o '[^/]*$')
fi
COMPREPLY=($(compgen -W "$trials" -- $cur))

Expand Down
Loading

0 comments on commit ddcf229

Please sign in to comment.