Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 14 additions & 2 deletions .azure-pipelines/code-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ variables:
CODE_SCAN_LOG_PATH: ".azure-pipelines/scripts/codeScan/scanLog"

stages:
- stage: DocStyleCodeScan
displayName: DocStyle Code Scan
dependsOn: []
jobs:
- job: DocStyle
displayName: DocStyle
steps:
- template: template/code-scan-template.yml
parameters:
codeScanFileName: "pydocstyle"
uploadPath: "pydocstyle.log"

- stage: BanditCodeScan
displayName: Bandit Code Scan
dependsOn: []
Expand All @@ -26,7 +38,7 @@ stages:
- template: template/code-scan-template.yml
parameters:
codeScanFileName: "bandit"
uploadPath: "lpot-bandit.log"
uploadPath: "bandit.log"

- stage: PylintCodeScan
displayName: Pylint Code Scan
Expand All @@ -38,7 +50,7 @@ stages:
- template: template/code-scan-template.yml
parameters:
codeScanFileName: "pylint"
uploadPath: "lpot-pylint.json"
uploadPath: "pylint.json"

- stage: CopyRight
displayName: CopyRight Code Scan
Expand Down
3 changes: 2 additions & 1 deletion .azure-pipelines/docker/DockerfileCodeScan.devel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ RUN python -m pip install --no-cache-dir pylint==2.12.1\
tf_slim\
transformers\
horovod\
flask==2.1.3
flask==2.1.3 \
pydocstyle

WORKDIR /
16 changes: 10 additions & 6 deletions .azure-pipelines/scripts/codeScan/bandit/bandit.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/bin/bash

source /neural-compressor/.azure-pipelines/scripts/change_color.sh
mkdir -p /neural-compressor/.azure-pipelines/scripts/codeScan/scanLog
bandit_log_dir="/neural-compressor/.azure-pipelines/scripts/codeScan/scanLog"
RESET="echo -en \\E[0m \\n" # close color

python -m bandit -r -lll -iii /neural-compressor/neural_compressor > $bandit_log_dir/lpot-bandit.log
log_dir="/neural-compressor/.azure-pipelines/scripts/codeScan/scanLog"
mkdir -p $log_dir

python -m bandit -r -lll -iii /neural-compressor/neural_compressor > $log_dir/bandit.log
exit_code=$?

# code-scan close
RESET="echo -en \\E[0m \\n"

$BOLD_YELLOW && echo " ----------------- Current bandit cmd start --------------------------" && $RESET
echo "python -m bandit -r -lll -iii /neural-compressor/neural_compressor > $log_dir/bandit.log"
$BOLD_YELLOW && echo " ----------------- Current bandit cmd end --------------------------" && $RESET

$BOLD_YELLOW && echo " ----------------- Current log file output start --------------------------"
cat $bandit_log_dir/lpot-bandit.log
cat $log_dir/bandit.log
$BOLD_YELLOW && echo " ----------------- Current log file output end --------------------------" && $RESET


Expand Down
25 changes: 25 additions & 0 deletions .azure-pipelines/scripts/codeScan/pydocstyle/pydocstyle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

source /neural-compressor/.azure-pipelines/scripts/change_color.sh
RESET="echo -en \\E[0m \\n" # close color

log_dir="/neural-compressor/.azure-pipelines/scripts/codeScan/scanLog"
mkdir -p $log_dir

pydocstyle --convention=google /neural-compressor/neural_compressor/experimental > $log_dir/pydocstyle.log
exit_code=$?


$BOLD_YELLOW && echo " ----------------- Current pydocstyle cmd start --------------------------" && $RESET
echo "python pydocstyle --convention=google /neural-compressor/neural_compressor/experimental > $log_dir/pydocstyle.log"
$BOLD_YELLOW && echo " ----------------- Current pydocstyle cmd end --------------------------" && $RESET

$BOLD_YELLOW && echo " ----------------- Current log file output start --------------------------"
cat $log_dir/pydocstyle.log
$BOLD_YELLOW && echo " ----------------- Current log file output end --------------------------" && $RESET


if [ ${exit_code} -ne 0 ] ; then
$BOLD_RED && echo "Error!! Please Click on the artifact button to download and view DocStyle error details." && $RESET; exit 1
fi
$BOLD_PURPLE && echo "Congratulations, DocStyle check passed!" && $LIGHT_PURPLE && echo " You can click on the artifact button to see the log details." && $RESET; exit 0
18 changes: 10 additions & 8 deletions .azure-pipelines/scripts/codeScan/pylint/pylint.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#!/bin/bash

source /neural-compressor/.azure-pipelines/scripts/change_color.sh
mkdir -p /neural-compressor/.azure-pipelines/scripts/codeScan/scanLog
pylint_log_dir="/neural-compressor/.azure-pipelines/scripts/codeScan/scanLog"
RESET="echo -en \\E[0m \\n" # close color

log_dir="/neural-compressor/.azure-pipelines/scripts/codeScan/scanLog"
mkdir -p $log_dir

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 > $pylint_log_dir/lpot-pylint.json
exit_code=$?
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

# code-scan close
RESET="echo -en \\E[0m \\n"
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 > $pylint_log_dir/lpot-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,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
cat $pylint_log_dir/lpot-pylint.json
cat $log_dir/pylint.json
$BOLD_YELLOW && echo " ----------------- Current log file output end --------------------------" && $RESET


Expand Down
1 change: 1 addition & 0 deletions neural_compressor/experimental/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Intel® Neural Compressor: An open-source Python library supporting common model."""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
Expand Down
1 change: 1 addition & 0 deletions neural_compressor/experimental/pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _on_after_optimizer_step(self):
pruner.on_after_optimizer_step()

def prepare(self):
"""Functions prepare for generate_hooks, generate_pruners."""
self.generate_hooks()
self.generate_pruners()

Expand Down