Skip to content

Commit

Permalink
Added PyTorch SegNet and Tensorflow MobileNetV2, ResNet50 models; pyl…
Browse files Browse the repository at this point in the history
…int cleanup; Model refactoring and code updates

- Further cleaned up code to minimize errors from static analysis (pylint)
- CI/CD Jenkins pipeline refactored to incorporate proper code quality checks
- Model refactoring, code updates and added artifacts for SalsaNext W4A8
- Releasing fourth package release of aimet model zoo (installable wheel file binaries)
- Added code, documentation and artifacts for the following new TensorFlow models: MobileNetV2, ResNet50
- Added code, documentation and artifacts for the following new PyTorch models: SegNet

Signed-off-by: Hanwen Xiong <quic_hanwxion@quicinc.com>
  • Loading branch information
quic-hanwxion authored and quic-bharathr committed May 4, 2023
1 parent 4326906 commit 667e804
Show file tree
Hide file tree
Showing 536 changed files with 14,662 additions and 3,816 deletions.
10 changes: 9 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=print-statement,
disable=bad-option-value,
useless-option-value,
unrecognized-option,
unknown-option-value,
consider-using-f-string,
f-string-without-interpolation,
unbalanced-tuple-unpacking,
unspecified-encoding,
print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
Expand Down
209 changes: 3 additions & 206 deletions Jenkins/Dockerfile.tf-torch-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -15,219 +15,16 @@

# Docker image file to build and test AIMET for both Tensorflow and PyTorch in a CPU environment

FROM ubuntu:bionic
FROM artifacts.codelinaro.org/codelinaro-aimet/aimet:latest.tf-torch-cpu

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update > /dev/null && \
apt-get install --no-install-recommends -y \
# Bare minimum Packages
ca-certificates \
git \
ssh \
sudo \
wget \
xterm \
xauth > /dev/null && \
rm -rf /var/lib/apt/lists/*

# Install certificates
RUN sudo update-ca-certificates

# Modified version of bash.bashrc that adjusts the prompt
### COPY bash.bashrc /etc/
### RUN chmod 644 /etc/bash.bashrc

### COPY profile.global /usr/local/etc/
### RUN chmod 555 /usr/local/etc/profile.global

# Add sudo support
RUN echo "%users ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers

RUN apt-get update -y > /dev/null && \
apt-get install --no-install-recommends -y \
# Python
python3.8 \
python3.8-dev \
python3-pip \
python3-setuptools \
build-essential \
# lmdb dependency
libffi-dev && \
python3-pip && \
rm -rf /var/lib/apt/lists/*

# Register the version in alternatives
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
# Set python 3.8 as the default python
RUN update-alternatives --set python3 /usr/bin/python3.8

# Python 2 pip installation
RUN apt-get update && apt-get install -y python-pip && rm -rf /var/lib/apt/lists/* && \
python2.7 -m pip --no-cache-dir install --upgrade \
pip==20.3.4 \
restkit

# Upgrade Python3 pip and install some more packages
RUN python3 -m pip --no-cache-dir install --upgrade \
pip \
setuptools==41.0.1 \
wheel==0.33.4

# Ubuntu packages for tensorflow and pytorch aimet
RUN dpkg --add-architecture i386
RUN apt-get update > /dev/null && \
apt-get install --no-install-recommends -y \
build-essential \
emacs \
environment-modules \
less \
libavcodec-dev \
libavformat-dev \
libgtest-dev \
libgtk2.0-dev \
libsox-dev \
libsox-fmt-all \
libstdc++6:i386 \
libswscale-dev \
libxtst6 \
lsb-release \
meld \
nano \
pandoc \
pkg-config \
python3-tk \
sox \
tree \
vim && \
rm -rf /var/lib/apt/lists/*

# Python3 Packages
RUN python3 -m pip --no-cache-dir install \
astroid==2.5.3 \
attrs==19.1.0 \
behave==1.2.6 \
bert-tensorflow \
blosc==1.10.1 \
cffi==1.12.3 \
click \
cumm==0.2.8 \
cython==0.29.12 \
dataclasses \
Deprecated \
docutils==0.16 \
grpcio \
grpcio-tools \
h5py==2.10.0 \
ipykernel \
Jinja2==3.0.3 \
jupyter \
keras==2.2.4 \
lmdb==1.2.1 \
matplotlib>=3 \
mock \
nbsphinx \
numpy==1.19.5 \
onnx==1.12.0 \
onnxsim \
onnxruntime \
onnxruntime-extensions \
opencv-python \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.1 \
psutil \
ptflops \
pybind11 \
pyDOE2 \
pylint==2.3.1 \
pymoo \
pytest==4.6.5 \
pytest-cov==2.6.1 \
pytorch-ignite \
PyYAML \
scikit-learn==1.1.3 \
scipy==1.8.1 \
spconv==2.1.20 \
sphinx==2.1.1 \
sphinx-jinja==1.1.1 \
sphinx-autodoc-typehints==1.6.0 \
tensorboard==2.4.0 \
tensorboardX==2.4 \
tensorflow-cpu==2.4.3 \
tensorflow-hub \
tensorflow-model-optimization \
tensorlayer==2.2.1 \
timm==0.4.12 \
torch==1.9.1+cpu -f https://download.pytorch.org/whl/torch_stable.html \
torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html \
torchtext==0.10.1 \
torchvision==0.10.1+cpu -f https://download.pytorch.org/whl/torch_stable.html \
tqdm \
transformers==4.11.3 \
wget && \
python3 -m ipykernel.kernelspec

RUN cd /tmp && \
wget https://github.com/Kitware/CMake/releases/download/v3.19.3/cmake-3.19.3-Linux-x86_64.sh && \
mkdir /opt/cmake && \
sh cmake-3.19.3-Linux-x86_64.sh --prefix=/opt/cmake --skip-license

RUN ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
RUN ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
RUN ln -s /opt/cmake/bin/cpack /usr/local/bin/cpack

ENV PATH=/usr/local/bin:$PATH

# Opencv
# Ref: https://docs.opencv.org/3.2.0/d7/d9f/tutorial_linux_install.html
COPY opencv_320_python38.patch /tmp
RUN wget -q https://github.com/Itseez/opencv/archive/3.2.0.tar.gz -O /tmp/3.2.0.tar.gz > /dev/null && \
tar -C /tmp -xvf /tmp/3.2.0.tar.gz > /dev/null && \
patch /tmp/opencv-3.2.0/modules/python/src2/cv2.cpp /tmp/opencv_320_python38.patch && \
cd /tmp/opencv-3.2.0 && mkdir release && cd release && \
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=release -DWITH_FFMPEG=OFF -DBUILD_TESTS=OFF -DWITH_CUDA=OFF -DBUILD_PERF_TESTS=OFF -DWITH_IPP=OFF -DENABLE_PRECOMPILED_HEADERS=OFF .. > /dev/null && \
make -j16 > /dev/null && \
make -j16 install > /dev/null && \
rm -rf /tmp/opencv-3.2.0*

EXPOSE 25000
RUN apt-get update && apt-get install -y openssh-server && rm -rf /var/lib/apt/lists/*
RUN mkdir /var/run/sshd

RUN apt-get update && apt-get install -y liblapacke liblapacke-dev && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y libjpeg8-dev && \
rm -rf /var/lib/apt/lists/*

# Set up symlink to point to the correct python version
RUN ln -sf /usr/bin/python3.8 /usr/bin/python
RUN ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib

RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
sed -i 's/Port 22/Port 25000/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

# Clone the tensorflow repo to enable development
RUN cd / && git clone --depth 1 --single-branch --branch v2.4.3 https://github.com/tensorflow/tensorflow.git

RUN python3 -m pip install git-pylint-commit-hook osqp

# NOTE: We need to pin the holoviews version to this since the latest version has a circular dependency on bokeh 2.0.0 through the panel package
RUN python3 -m pip install holoviews==1.12.7 netron jsonschema pandas==1.4.3

RUN python3 -m pip install bokeh==1.2.0 hvplot==0.4.0

# Remove existing Pillow & Pillow-SIMD and replace with correct version of Pillow-SIMD.
RUN python3 -m pip uninstall -y Pillow Pillow-SIMD
RUN python3 -m pip --no-cache-dir install Pillow-SIMD==9.0.0.post1

RUN apt-get update && apt-get install -y gnupg2
RUN wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add - && echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list
RUN apt-get update --fix-missing -y && apt upgrade -y && apt-get install -y clang-11 clang-format clang-tidy-11 && \
rm -rf /var/lib/apt/lists/*

# Create a version-less symbolic link for clang-tidy
RUN ln -s /usr/bin/run-clang-tidy-11.py /usr/bin/run-clang-tidy.py
pylint==2.17.2
33 changes: 23 additions & 10 deletions Jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pipeline {
PROJECT_NAME = "${params.PROJECT_NAME}"
PROJECT_BRANCH = "${params.PROJECT_BRANCH}"
WORKSPACE_ROOT = "${workspace}"
// Bypass the pre-built images until we have model-zoo-dev images
USE_LINARO = ""

}
stages {
Expand Down Expand Up @@ -54,9 +56,9 @@ pipeline {
cleanWs()
unstash 'AIMETBuildTree'
script {
env.AIMET_ZOO_VARIANT_TF_CPU = "tf-torch-cpu"
env.AIMET_ZOO_VARIANT = "tf-torch-cpu"
}
echo "*** Running SETUP stage for ${env.AIMET_ZOO_VARIANT_TF_CPU} variant on ${env.NODE_NAME} in workspace ${env.WORKSPACE_ROOT} ***"
echo "*** Running SETUP stage for ${env.AIMET_ZOO_VARIANT} variant on ${env.NODE_NAME} in workspace ${env.WORKSPACE_ROOT} ***"
}
}

Expand All @@ -65,7 +67,7 @@ pipeline {
echo 'Building and Creating Package...'
script {
//TODO Change option back to "-bp" as soon as issue is fixed
runStage(env.AIMET_ZOO_VARIANT_TF_CPU, "-bp")
runStage(env.AIMET_ZOO_VARIANT, "-bp")
}
}
}
Expand All @@ -74,7 +76,7 @@ pipeline {
steps {
echo 'Running code violations...'
script {
runStage(env.AIMET_ZOO_VARIANT_TF_CPU, "-v")
runStage(env.AIMET_ZOO_VARIANT, "-v")
}
}
post {
Expand Down Expand Up @@ -117,17 +119,28 @@ pipeline {
}
}

def runStage(AIMET_ZOO_VARIANT, options) {

echo "*** Running stage ${options} for ${AIMET_ZOO_VARIANT} variant on ${env.NODE_NAME} in workspace ${env.WORKSPACE_ROOT} ***"

def didDockerFileChange(AIMET_ZOO_VARIANT) {
def changedFiles = pullRequest.files.collect {
it.getFilename()
}
print changedFiles
if (!changedFiles.contains("Jenkins/Dockerfile.${AIMET_ZOO_VARIANT}".toString())) {
print "Jenkins/Dockerfile.${AIMET_ZOO_VARIANT} not found in changed file list, so using Linaro Docker image for ${AIMET_ZOO_VARIANT}"
if (changedFiles.contains("Jenkins/Dockerfile.${AIMET_ZOO_VARIANT}".toString())) {
print "Jenkins/Dockerfile.${AIMET_ZOO_VARIANT} changed in PR, so building docker image locally."
return true
}
print "Jenkins/Dockerfile.${AIMET_ZOO_VARIANT} NOT changed in PR, so using pre-built docker image."
return false
}

def runStage(AIMET_ZOO_VARIANT, options) {

echo "*** Running stage ${options} for ${AIMET_ZOO_VARIANT} variant on ${env.NODE_NAME} in workspace ${env.WORKSPACE_ROOT} ***"


if (didDockerFileChange(env.AIMET_ZOO_VARIANT)) {
env.USE_LINARO=""
}

sh """
AIMET_ZOO_VARIANT=${AIMET_ZOO_VARIANT} bash -l -c "cd ${REPO_NAME} && ./Jenkins/buildntest.sh -e AIMET_ZOO_VARIANT ${options} ${env.USE_LINARO} ${env.PREBUILT_DOCKER_IMAGE_URL}"
"""
Expand Down
24 changes: 22 additions & 2 deletions Jenkins/dobuildntest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,29 @@ if [ $run_code_violation -eq 1 ]; then
cd $buildFolder

echo -e "\n********** Stage 4: Code violation checks **********\n"

extra_opts=""
# Add build options based on variant
echo -e "Verify aimet variant: $AIMET_ZOO_VARIANT"
if [ -n "$AIMET_ZOO_VARIANT" ]; then
if [[ "$AIMET_ZOO_VARIANT" == *"tf"* ]]; then
extra_opts+=" -DENABLE_TENSORFLOW=ON"
fi
if [[ "$AIMET_ZOO_VARIANT" == *"torch"* ]]; then
extra_opts+=" -DENABLE_TORCH=ON"
fi
if [[ "$AIMET_ZOO_VARIANT" != *"tf"* ]]; then
extra_opts+=" -DENABLE_TENSORFLOW=OFF"
fi
if [[ "$AIMET_ZOO_VARIANT" != *"torch"* ]]; then
extra_opts+=" -DENABLE_TORCH=OFF"
fi
fi
echo -e "Extra Options added: " ${extra_opts}
cmake ${extra_opts} ..

make pylintmodelzoo
check_stage $? "Code Violations" "true"
fi

exit $EXIT_CODE

exit $EXIT_CODE
2 changes: 1 addition & 1 deletion Jenkins/jenkins_threshold_configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"pylint_fail_thresholds" : {
"high_priority" : "10",
"normal_priority" : "10",
"low_priority" : "10"
"low_priority" : "33"
}
}

4 changes: 4 additions & 0 deletions Jenkins/opencv_320_python38.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
730c730
< char* str = PyString_AsString(obj);
---
> const char* str = PyString_AsString(obj);
30 changes: 30 additions & 0 deletions NightlyTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# =============================================================================
# @@-COPYRIGHT-START-@@
#
# Copyright (c) 2023 of Qualcomm Innovation Center, Inc. All rights reserved.
#
# @@-COPYRIGHT-END-@@
# =============================================================================

add_custom_target(AcceptanceTests)

if (ENABLE_TORCH)
add_dependencies(AcceptanceTests
AcceptanceTests.Torch)

endif (ENABLE_TORCH)

#if (ENABLE_TENSORFLOW)
# add_dependencies(AcceptanceTests
# AcceptanceTests.Tensorflow)
#
#endif (ENABLE_TENSORFLOW)

if (ENABLE_TORCH)
add_subdirectory(torch)
endif (ENABLE_TORCH)

#if (ENABLE_TENSORFLOW)
# add_subdirectory(tensorflow)
#endif (ENABLE_TENSORFLOW)
Loading

0 comments on commit 667e804

Please sign in to comment.