Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f419a7f
Update normalization in predictors
Nov 4, 2022
363bdff
Add notebook's checkpoint to gitignore
Nov 4, 2022
9d7f1f4
Add TODO note.
Nov 4, 2022
1dceb8a
Add Runners dictionary
Nov 4, 2022
2c17af6
add transformer example
sharathns93 Nov 7, 2022
7b20527
Run `autopep8`
Nov 17, 2022
dec5dfa
Merge branch 'master' into dynas/transformer
Nov 17, 2022
4b05fd2
Cleanup imports
Nov 18, 2022
1e19ff8
Cleanup imports
Nov 18, 2022
8d7f56b
Replace print with logger
Nov 18, 2022
55e7725
Replace `os.system('rm ...')` with `os.remove`
Nov 18, 2022
16cccb4
Remove unused logs
Nov 18, 2022
cb121e2
Make variable names more descriptive
Nov 18, 2022
1e9b6b8
Remove duplicate definitions
Nov 18, 2022
322c277
Remove unused code
Nov 18, 2022
abddec7
Add TODOs
Nov 18, 2022
051ae26
Update progress tracking
Nov 18, 2022
d70c55e
Move supernetwork dir under dynast dir
Nov 18, 2022
4a60f47
Update logging and TODos
Nov 18, 2022
d8866a9
Log warning when measuring MACs for transformer LT (not supported)
Nov 18, 2022
41bebb4
Update LINAS loop
Nov 18, 2022
e773a55
Fix error when CSV file does not exist
Nov 18, 2022
aba0495
Change column names in CSV file for Transformer LT
Nov 18, 2022
ead6999
add macs computation for transformers
sharathns93 Nov 19, 2022
e222eb7
Add `batch size` to compute latency for TransformerLT
Nov 21, 2022
f5b7922
Remove old cuda calls
Nov 21, 2022
4ef8f05
Remove comment
Nov 22, 2022
f022e2a
replace bleu with sacrebleu
sharathns93 Nov 28, 2022
c624eda
Merge branch 'dynas/transformer' of https://github.com/intel-innersou…
Nov 28, 2022
c2fbc12
Merge branch 'master' into dynas/transformer
Nov 29, 2022
a35901b
Fix problem with `dataset` for OFA
Nov 29, 2022
8b3a795
Remove unused imports
Nov 29, 2022
53f4af7
Fix indentation
Nov 30, 2022
d255b68
replace fvcore with torchprofile to avoid mem leaks
sharathns93 Nov 30, 2022
bb2a53a
Add DyNAS Transformer LT example
Nov 30, 2022
1cd635f
Code cleanup
Nov 30, 2022
1c6ddf6
Add fairseq and HAT license
Nov 30, 2022
3afbcc7
Update license headers in transformer t supernet code
Dec 6, 2022
2ea3572
Revert "Add DyNAS Transformer LT example"
Dec 7, 2022
6dba114
Add example results for Transformer LT search space
Dec 8, 2022
0b2fa19
Update MobileNetV3 example
Dec 8, 2022
bfd3dc3
Add Transformer LT example notebook
Dec 8, 2022
8d8aaab
Update NAAS.md
Dec 8, 2022
61301b8
Merge branch 'master' into dynas/transformer
Dec 8, 2022
9d95d77
Fix UT
Dec 9, 2022
0c5dea8
Change "TransformerLT" to "Transformer_LT" to fix pyspelling error
Dec 9, 2022
51ee756
Update imports
Dec 9, 2022
d6223a2
Update requirements
Dec 9, 2022
95b7d39
Fix styling check
Dec 9, 2022
6f16722
Ignore fairseq in pylint
Dec 9, 2022
2299d9d
Address styling issues
Dec 9, 2022
48518dd
Merge branch 'master' into dynas/transformer
Dec 9, 2022
7e46cad
Pin torch version
Dec 9, 2022
d822611
LazyImport fairseq
Dec 9, 2022
79a4758
Remove reference to DyNAS from UTs
Dec 9, 2022
07943de
Revert "Remove reference to DyNAS from UTs"
Dec 9, 2022
e3e67e2
LazyLoad transformer_interface
Dec 9, 2022
eb5b063
Removed commented code
Dec 10, 2022
8f1e03e
Shorten import line
Dec 10, 2022
0a84cf7
Merge branch 'master' into dynas/transformer
Dec 10, 2022
6951d7a
Remove cached torch files when running tests
Dec 10, 2022
e9f872a
Split NAS tests
Dec 10, 2022
ce29fe4
Catch network timeout in tests
Dec 10, 2022
36365ed
Remove try catch from tests
Dec 10, 2022
858d7b0
Move `.torch` cleanup to teardown
Dec 10, 2022
758701c
Merge branch 'master' into dynas/transformer
XinyuYe-Intel Dec 12, 2022
706eb4f
Merge branch 'master' into dynas/transformer
Dec 12, 2022
7dd6615
Skip cleanup
Dec 12, 2022
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
4 changes: 2 additions & 2 deletions .azure-pipelines/scripts/codeScan/pylint/pylint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ pip install -r /neural-compressor/requirements.txt
pip install torch==1.12.0

python -m pylint -f json --disable=R,C,W,E1129 --enable=line-too-long --max-line-length=120 --extension-pkg-whitelist=numpy --ignored-classes=TensorProto,NodeProto \
--ignored-modules=tensorflow,torch,torch.quantization,torch.tensor,torchvision,mxnet,onnx,onnxruntime,intel_extension_for_pytorch /neural-compressor/neural_compressor \
--ignored-modules=tensorflow,torch,torch.quantization,torch.tensor,torchvision,fairseq,mxnet,onnx,onnxruntime,intel_extension_for_pytorch /neural-compressor/neural_compressor \
> $log_dir/pylint.json

exit_code=$?

$BOLD_YELLOW && echo " ----------------- Current pylint cmd start --------------------------" && $RESET
echo "python -m pylint -f json --disable=R,C,W,E1129 --enable=line-too-long --max-line-length=120 --extension-pkg-whitelist=numpy --ignored-classes=TensorProto,NodeProto --ignored-modules=tensorflow,torch,torch.quantization,torch.tensor,torchvision,mxnet,onnx,onnxruntime,intel_extension_for_pytorch /neural-compressor/neural_compressor > $log_dir/pylint.json"
echo "python -m pylint -f json --disable=R,C,W,E1129 --enable=line-too-long --max-line-length=120 --extension-pkg-whitelist=numpy --ignored-classes=TensorProto,NodeProto --ignored-modules=tensorflow,torch,torch.quantization,torch.tensor,torchvision,fairseq,mxnet,onnx,onnxruntime,intel_extension_for_pytorch /neural-compressor/neural_compressor > $log_dir/pylint.json"
$BOLD_YELLOW && echo " ----------------- Current pylint cmd end --------------------------" && $RESET

$BOLD_YELLOW && echo " ----------------- Current log file output start --------------------------" && $RESET
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.idea
/venv/
*/__pycache__
.ipynb_checkpoints/
*.snapshot
*.csv
*.pb
Expand All @@ -17,4 +18,4 @@ build/
_build
lpot_workspace/
.torch/
node_modules
node_modules
4 changes: 3 additions & 1 deletion docs/source/NAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class NASBase(object):

def search(self, res_save_path=None):
# NAS search process.
...
...

def estimate(self, model): # pragma: no cover
# Estimate performance of the model. Depends on specific NAS algorithm.
Expand Down Expand Up @@ -175,3 +175,5 @@ Following examples are supported in Intel® Neural Compressor:

- DyNAS MobileNetV3 supernet Example:
- [DyNAS MobileNetV3 supernet Example](../examples/notebook/dynas/MobileNetV3_Supernet_NAS.ipynb): DyNAS with MobileNetV3 supernet on ImageNet dataset.
- DyNAS Transformer LT supernet Example:
- [DyNAS Transformer LT supernet Example](../examples/notebook/dynas/Transformer_LT_Supernet_NAS.ipynb): DyNAS with Transformer LT supernet on WMT En-De dataset.
43 changes: 34 additions & 9 deletions examples/notebook/dynas/MobileNetV3_Supernet_NAS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"\n",
"#### Super-Networks\n",
"\n",
"The computational overhead of evaluating DNN architectures during the neural architecture search process can be very costly due to the training and validation cycles. To address the training overhead, novel weight-sharing approaches known as one-shot or super-networks have offered a way to mitigate the training overhead by reducing training times from thousands to a few GPU days. These approaches train a task-specific super-network architecture with a weight-sharing mechanism that allows the sub-networks to be treated as unique individual architectures. This enables sub-network model extraction and validation without a separate training cycle. This tutorial offers pre-trained Once-for-All (OFA) super-networks [1] for the image classification task on ImageNet-ilsvrc2012.\n",
"The computational overhead of evaluating DNN architectures during the neural architecture search process can be very costly due to the training and validation cycles. To address the training overhead, novel weight-sharing approaches known as one-shot or super-networks have offered a way to mitigate the training overhead by reducing training times from thousands to a few GPU days. These approaches train a task-specific super-network architecture with a weight-sharing mechanism that allows the sub-networks to be treated as unique individual architectures. This enables sub-network model extraction and validation without a separate training cycle. This tutorial offers pre-trained Once-for-All (OFA) super-networks [1] for the image classification on ImageNet-ilsvrc2012 as well as Transformer Language Translation (based on [6]) for the language translation tasks.\n",
"\n",
"#### Methodology\n",
"\n",
Expand All @@ -38,7 +38,25 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install neural_compressor autograd==1.4 fvcore==0.1.5.post20220119 numpy==1.19.2 ofa==0.1.0.post202203231606 pandas==1.1.5 pymoo==0.5.0 pyyaml==5.4.1 scikit-learn==0.24.2 scipy==1.5.4 torch==1.10.1 torchvision==0.11.2"
"!pip -q install neural_compressor autograd==1.4 fvcore==0.1.5.post20220119 numpy ofa==0.1.0.post202203231606 pandas==1.1.5 pymoo==0.5.0 pyyaml==5.4.1 scikit-learn==0.24.2 scipy==1.5.4 torch==1.10.1 torchvision==0.11.2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatievely, if you have a local copy of https://github.com/intel/neural-compressor, you can uncomment and run the code below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import sys\n",
"# sys.path.insert(0,'<path to neural compressor>')\n",
"# !pip install -q autograd==1.4 fvcore==0.1.5.post20220119 numpy ofa==0.1.0.post202203231606 pandas==1.1.5 pymoo==0.5.0 pyyaml==5.4.1 scikit-learn==0.24.2 scipy==1.5.4 torch==1.10.1 torchvision==0.11.2 sacremoses==0.0.53 torchprofile==0.0.4 fairseq==0.12.2"
]
},
{
Expand Down Expand Up @@ -84,12 +102,16 @@
"metadata": {},
"source": [
"### Define Architecture\n",
"We currently leverage pre-trained Once-for-All (OFA) super-networks [4] for the image classification task on ImageNet-ilsvrc2012. In the case where the super-network PyTorch model download fails, you can manually copy the pre-trained models from https://github.com/mit-han-lab/once-for-all and place them in the `.torch/ofa_nets` path. \n",
"We currently support pre-trained super-networks:\n",
"\n",
"1. Once-for-All (OFA) super-networks [4] for the image classification task on ImageNet-ilsvrc2012. In the case where the super-network PyTorch model download fails, you can manually copy the pre-trained models from https://github.com/mit-han-lab/once-for-all and place them in the `.torch/ofa_nets` path.\n",
"2. Hardware-Aware-Transformers (HAT) supernetwork [6] for language translation task on WMT14 En-De. To run this supernetwork you have to manually download preprocessed dataset from https://github.com/mit-han-lab/hardware-aware-transformers/blob/master/configs/wmt14.en-de/get_preprocessed.sh and pretrained model from https://www.dropbox.com/s/pkdddxvvpw9a4vq/HAT_wmt14ende_super_space0.pt?dl=0\n",
"\n",
"Super-network options (choose 1): \n",
"- `ofa_resnet50` - based on the ResNet50 architecture [4]. Search space of ~$10^{15}$ architectures.\n",
"- `ofa_mbv3_d234_e346_k357_w1.0` - based on the MobileNetV3 architecture [5], width multiplier 1.0. Search space of ~$10^{19}$ architectures.\n",
"- `ofa_mbv3_d234_e346_k357_w1.2` - based on the MobileNetV3 architecture [5], width multiplier 1.2. Search space of ~$10^{19}$ architectures. "
"- `ofa_mbv3_d234_e346_k357_w1.2` - based on the MobileNetV3 architecture [5], width multiplier 1.2. Search space of ~$10^{19}$ architectures. \n",
"- `transformer_lt_wmt_en_de` - based on the Transformer architecture [7]."
]
},
{
Expand All @@ -113,7 +135,7 @@
"* `['acc', 'lat']` \n",
"\n",
"Description:\n",
"* `'acc'` - ImageNet Top-1 Accuracy (%)\n",
"* `'acc'` - ImageNet Top-1 Accuracy (%) (for OFA supetnetworks) and Bleu (for Transformer LT)\n",
"* `'macs'` - Multiply-and-accumulates as measured from FVCore. \n",
"* `'lat'` - Latency (inference time) measurement (ms)"
]
Expand All @@ -137,7 +159,8 @@
"* `config.dynas.num_evals` - Validation measurement count, a higher count comes with greater computational cost but a higher chance of finding optimal sub-networks\n",
"* `config.dynas.results_csv_path` - Location of the search (validation measurement) results. This file is also used to provide training data to the metric predictors. \n",
"* `config.dynas.batch_size` - Batch size used during latency measurements.\n",
"* `config.dynas.dataset_path` - Path to the imagenet-ilsvrc2012 dataset. This can be obtained at: https://www.image-net.org/download.php"
"* `config.dynas.dataset_path` - For OFA it's a path to the imagenet-ilsvrc2012 dataset. This can be obtained at: https://www.image-net.org/download.php; For Transformer LT it's a path to preprocessed WMT EnDe directory (`(...)/data/binary/wmt16_en_de`)\n",
"* `config.dynas.supernet_ckpt_path` - Transformer LT only. Path to downloaded pretrained super-network (`HAT_wmt14ende_super_space0.pt` file)."
]
},
{
Expand Down Expand Up @@ -272,8 +295,10 @@
"[1] Cai, H., Gan, C., & Han, S. (2020). Once for All: Train One Network and Specialize it for Efficient Deployment. ArXiv, abs/1908.09791. \n",
"[2] K. Deb, A. Pratap, S. Agarwal and T. Meyarivan, \"A fast and elitist multiobjective genetic algorithm: NSGA-II,\" in IEEE Transactions on Evolutionary Computation, vol. 6, no. 2, pp. 182-197, April 2002, doi: 10.1109/4235.996017. \n",
"[3] Cummings, D., Sarah, A., Sridhar, S.N., Szankin, M., Muñoz, J.P., & Sundaresan, S. (2022). A Hardware-Aware Framework for Accelerating Neural Architecture Search Across Modalities. ArXiv, abs/2205.10358. \n",
"[4] He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep Residual Learning for Image Recognition. 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 770-778. \n",
"[5] Howard, A.G., Sandler, M., Chu, G., Chen, L., Chen, B., Tan, M., Wang, W., Zhu, Y., Pang, R., Vasudevan, V., Le, Q.V., & Adam, H. (2019). Searching for MobileNetV3. 2019 IEEE/CVF International Conference on Computer Vision (ICCV), 1314-1324. "
"[4] He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep Residual Learning for Image Recognition. 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 770-778. \n",
"[5] Howard, A.G., Sandler, M., Chu, G., Chen, L., Chen, B., Tan, M., Wang, W., Zhu, Y., Pang, R., Vasudevan, V., Le, Q.V., & Adam, H. (2019). Searching for MobileNetV3. 2019 IEEE/CVF International Conference on Computer Vision (ICCV), 1314-1324. \n",
"[6] Wang, H., Wu, Z., Liu, Z., Cai, H., Zhu, L., Gan, C. and Han, S., 2020. Hat: Hardware-aware transformers for efficient natural language processing. arXiv preprint arXiv:2005.14187. \n",
"[7] Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., Kaiser, Ł. and Polosukhin, I., 2017. Attention is all you need. Advances in neural information processing systems, 30."
]
},
{
Expand All @@ -300,7 +325,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.7.11"
}
},
"nbformat": 4,
Expand Down
Loading