Skip to content

Commit

Permalink
add import tests for torch and tensorflow cpu and gpu variants. Add J…
Browse files Browse the repository at this point in the history
…enkinsfile. Add shell script to replicate a user environment

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

add jenkinsfile and import tests

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

update workspace root and test for tf_cpu

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

sanity check

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

add variable to all variants

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

sanity check

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

fix 1 for workspace root

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

add aimet dir

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

sleep

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

enter into correct workspace

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

add proper workspace root for all

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

add copyright to python files

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

add copyright to script

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

update dates on copyrights

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

update dates on copyrights

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

update dates on copyrights

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

update dates on copyrights

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

remove folder double

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

feedback updates

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>

add package root variable to shell script

Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>
  • Loading branch information
quic-jpolizzi authored and quic-bharathr committed Sep 8, 2023
1 parent 1ecf394 commit a3f3f3e
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 0 deletions.
63 changes: 63 additions & 0 deletions packaging/verification/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
pipeline {
parameters {
string(name: 'PROJECT_NAME', defaultValue: 'aimet-verification', description: 'Verify aimet os package install')
string(name: 'BUILD_LABEL_GPU', defaultValue: 'docker-build-aimet-pr-gpu', description: 'Jenkins node host name or label for GPU variants')
string(name: 'BUILD_LABEL_CPU', defaultValue: 'docker-build-aimet-pr-cpu', description: 'Jenkins node host name or label for CPU variants')
string(name: 'BUILD_TIMEOUT', defaultValue: '3', description: 'Build timeout in hours')

}
options {
timestamps()
timeout( time: "${params.BUILD_TIMEOUT}", unit: 'HOURS')
}
environment{
def workspace = pwd()
PROJECT_NAME = "${params.PROJECT_NAME}"
WORKSPACE_ROOT = "${workspace}"
}
agent { label "${params.BUILD_LABEL_CPU}" }
stages {
stage ("Verification") {
parallel {
stage("Tensorflow CPU") {
steps {
script {
env.AIMET_VARIANT = "tf_cpu"
echo "*** Running SETUP on ${env.NODE_NAME} for variant ${env.AIMET_VARIANT} with tag ${params.release_tag} in ${WORKSPACE_ROOT} ***"
sh "bash -l -c \"docker run --rm -v ${WORKSPACE_ROOT}:${WORKSPACE_ROOT} -w ${WORKSPACE_ROOT}/packaging/verification -e AIMET_VARIANT=${env.AIMET_VARIANT} -e release_tag=${params.release_tag} ${ALTERNATIVE_DOCKER_REGISTRY}ubuntu:focal sh -c './aimet-os-install.sh && python3 test_aimet_tf_imports.py'\""
}
}
}
stage("Tensorflow GPU") {
agent { label "${params.BUILD_LABEL_GPU}" }
steps {
script {
env.AIMET_VARIANT = "tf_gpu"
echo "*** Running SETUP on ${env.NODE_NAME} for variant ${env.AIMET_VARIANT} with tag ${params.release_tag} in ${WORKSPACE_ROOT} ***"
sh "bash -l -c \"docker run --gpus all --rm -v ${WORKSPACE_ROOT}:${WORKSPACE_ROOT} -w ${WORKSPACE_ROOT}/packaging/verification -e AIMET_VARIANT=${env.AIMET_VARIANT} -e release_tag=${params.release_tag} ${ALTERNATIVE_DOCKER_REGISTRY}ubuntu:focal sh -c './aimet-os-install.sh && python3 test_aimet_tf_imports.py'\""
}
}
}
stage("Torch CPU") {
steps {
script {
env.AIMET_VARIANT = "torch_cpu"
echo "*** Running SETUP on ${env.NODE_NAME} for variant ${env.AIMET_VARIANT} with tag ${params.release_tag} in ${WORKSPACE_ROOT} ***"
sh "bash -l -c \"docker run --rm -v ${WORKSPACE_ROOT}:${WORKSPACE_ROOT} -w ${WORKSPACE_ROOT}/packaging/verification -e AIMET_VARIANT=${env.AIMET_VARIANT} -e release_tag=${params.release_tag} ${ALTERNATIVE_DOCKER_REGISTRY}ubuntu:focal sh -c './aimet-os-install.sh && python3 test_aimet_torch_imports.py'\""
}
}
}
stage("Torch GPU") {
agent { label "${params.BUILD_LABEL_GPU}" }
steps {
script {
env.AIMET_VARIANT = "torch_gpu"
echo "*** Running SETUP on ${env.NODE_NAME} for variant ${env.AIMET_VARIANT} with tag ${params.release_tag} in ${WORKSPACE_ROOT} ***"
sh "bash -l -c \"docker run --gpus all --rm -v ${WORKSPACE_ROOT}:${WORKSPACE_ROOT} -w ${WORKSPACE_ROOT}/packaging/verification -e AIMET_VARIANT=${env.AIMET_VARIANT} -e release_tag=${params.release_tag} ${ALTERNATIVE_DOCKER_REGISTRY}ubuntu:focal sh -c './aimet-os-install.sh && python3 test_aimet_torch_imports.py'\""
}
}
}
} //parallel
}
}
}
186 changes: 186 additions & 0 deletions packaging/verification/aimet-os-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#!/bin/bash
#==============================================================================
# @@-COPYRIGHT-START-@@
#
# Copyright (c) 2021-2023, Qualcomm Innovation Center, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# @@-COPYRIGHT-END-@@
#==============================================================================

###############################################################################
# Install script to build various aimet varients into an empty Ubuntu
# container to test replicability of documentation.
###############################################################################

set -e

# Set Package Root

export PACKAGE_ROOT="/usr/local/lib/python3.8/dist-packages"

# Install packages
apt-get update
apt-get install python3.8 python3.8-dev python3-pip -y
python3 -m pip install --upgrade pip
apt-get install --assume-yes wget gnupg2

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
update-alternatives --set python3 /usr/bin/python3.8

# GPU varients
if [[ "$AIMET_VARIANT" == *"gpu"* ]]; then

#. PyTorch 1.13 GPU variant: `CUDA Toolkit 11.6.2 <https://developer.nvidia.com/cuda-11-6-2-download-archive>`_
if [[ "$AIMET_VARIANT" == *"torch"* || "$AIMET_VARIANT" == *"onnx"* ]]; then
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda-repo-ubuntu2004-11-6-local_11.6.2-510.47.03-1_amd64.deb
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64/7fa2af80.pub
dpkg -i cuda-repo-ubuntu2004-11-6-local_11.6.2-510.47.03-1_amd64.deb
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
apt-get update

apt-get install cuda-nvrtc-11-6 \
cuda-nvrtc-dev-11-6 \
cuda-nvprune-11-6 \
cuda-compat-11-6 \
libcufft-dev-11-6 \
libcurand-dev-11-6 \
libcusolver-dev-11-6 \
libcusparse-dev-11-6 \
libcublas-11-6 \
cuda-libraries-11-6 -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64/nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
dpkg -i nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
apt-get update
fi

# Tensorflow GPU varaint
if [[ "$AIMET_VARIANT" == *"tf"* ]]; then
echo "*** Tensorflow GPU ***"
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda-repo-ubuntu2004-11-2-local_11.2.2-460.32.03-1_amd64.deb
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64/7fa2af80.pub
dpkg -i cuda-repo-ubuntu2004-11-2-local_11.2.2-460.32.03-1_amd64.deb
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
apt-get update

apt-get install cuda-nvrtc-11-2 \
cuda-nvrtc-dev-11-2 \
cuda-nvprune-11-2 \
cuda-compat-11-2 \
libcufft-dev-11-2 \
libcurand-dev-11-2 \
libcusolver-dev-11-2 \
libcusparse-dev-11-2=11.4.1.1152-1 \
libcublas-11-2=11.4.1.1043-1 \
cuda-libraries-11-2=11.2.2-1 -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64/nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
dpkg -i nvidia-machine-learning-repo-ubuntu2004_1.0.0-1_amd64.deb
apt-get update

fi
fi

# Aimet install
export download_url="https://github.com/quic/aimet/releases/download/${release_tag}"
export wheel_file_suffix="cp38-cp38-linux_x86_64.whl"

python3 -m pip install ${download_url}/AimetCommon-${AIMET_VARIANT}_${release_tag}-${wheel_file_suffix}

# Install ONE of the following depending on the variant
if [[ "$AIMET_VARIANT" == *"torch"* ]]; then
python3 -m pip install ${download_url}/AimetTorch-${AIMET_VARIANT}_${release_tag}-${wheel_file_suffix} -f https://download.pytorch.org/whl/torch_stable.html
fi

if [[ "$AIMET_VARIANT" == *"tf"* ]]; then
python3 -m pip install ${download_url}/AimetTensorflow-${AIMET_VARIANT}_${release_tag}-${wheel_file_suffix}
fi

if [[ "$AIMET_VARIANT" == *"onnx"* ]]; then
python3 -m pip install ${download_url}/AimetOnnx-${AIMET_VARIANT}_${release_tag}-${wheel_file_suffix}
fi

python3 -m pip install ${download_url}/Aimet-${AIMET_VARIANT}_${release_tag}-${wheel_file_suffix}

cat ${PACKAGE_ROOT}/aimet_common/bin/reqs_deb_common.txt | xargs apt-get --assume-yes install


if [[ "$AIMET_VARIANT" == *"torch"* ]]; then
cat ${PACKAGE_ROOT}/aimet_onnx/bin/reqs_deb_torch_common.txt | xargs apt-get --assume-yes install
if [[ "$AIMET_VARIANT" == *"gpu"* ]]; then
cat ${PACKAGE_ROOT}/aimet_torch/bin/reqs_deb_torch_gpu.txt | xargs apt-get --assume-yes install
fi
fi

if [[ "$AIMET_VARIANT" == *"onnx"* ]]; then
cat ${PACKAGE_ROOT}/aimet_onnx/bin/reqs_deb_onnx_common.txt | xargs apt-get --assume-yes install
if [[ "$AIMET_VARIANT" == *"gpu"* ]]; then
cat ${PACKAGE_ROOT}/aimet_onnx/bin/reqs_deb_onnx_gpu.txt | xargs apt-get --assume-yes install
fi
fi

if [[ "$AIMET_VARIANT" == *"tf"* ]]; then
if [[ "$AIMET_VARIANT" == *"gpu"* ]]; then
cat ${PACKAGE_ROOT}/aimet_tensorflow/bin/reqs_deb_tf_gpu.txt | xargs apt-get --assume-yes install
fi
fi

python3 -m pip uninstall -y pillow
python3 -m pip install --no-cache-dir Pillow-SIMD==9.0.0.post1

if [[ "$AIMET_VARIANT" == *"torch"* ]]; then
if [[ "$AIMET_VARIANT" == *"gpu"* ]]; then
export ONNXRUNTIME_VER=$(python3 -c 'import onnxruntime; print(onnxruntime.__version__)')
python3 -m pip uninstall -y onnxruntime
python3 -m pip install --no-cache-dir onnxruntime-gpu==$ONNXRUNTIME_VER
fi
fi

ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib

if [[ "$AIMET_VARIANT" == "tf_gpu" ]]; then
ln -s /usr/local/cuda-11.2 /usr/local/cuda
elif [[ "$AIMET_VARIANT" == "torch_gpu" ]]; then
ln -s /usr/local/cuda-11.6 /usr/local/cuda
fi

source ${PACKAGE_ROOT}/aimet_common/bin/envsetup.sh

57 changes: 57 additions & 0 deletions packaging/verification/test_aimet_tf_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
#==============================================================================
# @@-COPYRIGHT-START-@@
#
# Copyright (c) 2021-2023, Qualcomm Innovation Center, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# @@-COPYRIGHT-END-@@
#==============================================================================

""" Import Verification for Aimet Tensorflow """

from aimet_common.defs import QuantScheme
import aimet_common.defs as aimet_common_defs
## import aimet_common.AimetTensorQuantizer
import aimet_common.libpymo as libpymo

import tensorflow

from aimet_tensorflow.compress import ModelCompressor
import aimet_tensorflow.defs as aimet_tensorflow_defs
from aimet_tensorflow.utils.graph_saver import save_model_to_meta

from aimet_tensorflow import batch_norm_fold as aimet_bnf
from aimet_tensorflow import quantsim as aimet_tf_quantsim
from aimet_tensorflow import bias_correction as aimet_bc
from aimet_tensorflow import cross_layer_equalization as aimet_cle
from aimet_tensorflow.adaround.adaround_weight import Adaround, AdaroundParameters
from aimet_tensorflow.utils.graph_saver import save_and_load_graph

51 changes: 51 additions & 0 deletions packaging/verification/test_aimet_torch_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
#==============================================================================
# @@-COPYRIGHT-START-@@
#
# Copyright (c) 2021-2023, Qualcomm Innovation Center, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# @@-COPYRIGHT-END-@@
#==============================================================================

""" Import verification for Aimet Torch """

from aimet_common.defs import QuantScheme
import aimet_common.defs as aimet_common_defs
## import aimet_common.AimetTensorQuantizer
import aimet_common.libpymo as libpymo

import torch
from aimet_torch.quantsim import QuantizationSimModel
from aimet_torch.compress import ModelCompressor

from aimet_torch.adaround.adaround_weight import Adaround, AdaroundParameters
from aimet_torch.batch_norm_fold import fold_all_batch_norms
from aimet_torch.quantsim import QuantizationSimModel

0 comments on commit a3f3f3e

Please sign in to comment.