Skip to content

Commit a0ce14c

Browse files
committed
Merge branch 'feature/triton-qa-model-tests' into 'dev'
Feature/triton qa model tests See merge request arm-research/smarter/armnn_tflite_backend!27
2 parents 6f118d9 + 6fdbe5b commit a0ce14c

File tree

11 files changed

+485
-81
lines changed

11 files changed

+485
-81
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.tflite filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
*.so
55
**/__pycache__
66
**/*.pyc
7-
/qa/test_model_repo

Dockerfile

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ ARG UBUNTU_VERSION=20.04
22

33
FROM ubuntu:${UBUNTU_VERSION} as armnn_tflite_backend
44

5-
# Triton version pins, assumed same across backend, core, and common
6-
ARG TRITON_REPO_TAG=main
5+
ENV DEBIAN_FRONTEND=noninteractive
76

87
# Cmake Version options
98
ARG CMAKE_VERSION=3.21.1
@@ -43,6 +42,21 @@ RUN apt-get update && \
4342
pip3 install -U pip wheel && \
4443
rm -rf /var/lib/apt/lists/*
4544

45+
# Triton version pins, assumed same across backend, core, and common
46+
# Note that this is set to the rX.XX branches, not the vX.X.X tags
47+
ARG TRITON_REPO_TAG=main
48+
49+
# CMake build arguments defaults
50+
ARG CMAKE_BUILD_TYPE=RELEASE
51+
ARG TRITON_ENABLE_MALI_GPU=ON
52+
ARG TFLITE_ENABLE_RUY=ON
53+
ARG TFLITE_BAZEL_BUILD=OFF
54+
ARG TFLITE_ENABLE_FLEX_OPS=OFF
55+
ARG TFLITE_TAG=v2.4.1
56+
ARG ARMNN_TAG=v21.08
57+
ARG ARMNN_DELEGATE_ENABLE=ON
58+
ARG ACL_TAG=${ARMNN_TAG}
59+
4660
# Install Bazel from source
4761
RUN wget -O bazel-3.1.0-dist.zip https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel-3.1.0-dist.zip && \
4862
unzip -d bazel bazel-3.1.0-dist.zip && \
@@ -58,12 +72,20 @@ COPY . .
5872
RUN mkdir build && \
5973
cd build && \
6074
cmake .. \
75+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
6176
-DCMAKE_INSTALL_PREFIX:PATH=`pwd`/install \
6277
-DTRITON_BACKEND_REPO_TAG=${TRITON_REPO_TAG} \
6378
-DTRITON_CORE_REPO_TAG=${TRITON_REPO_TAG} \
6479
-DTRITON_COMMON_REPO_TAG=${TRITON_REPO_TAG} \
6580
-DTRITON_ENABLE_GPU=OFF \
66-
-DTRITON_ENABLE_MALI_GPU=ON \
67-
-DTFLITE_ENABLE_RUY=ON \
68-
-DJOBS=$(nproc) && \
81+
-DTRITON_ENABLE_MALI_GPU=${TRITON_ENABLE_MALI_GPU}} \
82+
-DTFLITE_ENABLE_RUY=${TFLITE_ENABLE_RUY} \
83+
-DTFLITE_BAZEL_BUILD=${TFLITE_BAZEL_BUILD} \
84+
-DTFLITE_ENABLE_FLEX_OPS=${TFLITE_ENABLE_FLEX_OPS} \
85+
-DTFLITE_TAG=${TFLITE_TAG} \
86+
-DARMNN_TAG=${ARMNN_TAG} \
87+
-DARMNN_DELEGATE_ENABLE=${ARMNN_DELEGATE_ENABLE} \
88+
-DACL_TAG=${ACL_TAG} \
89+
-DJOBS=$(nproc) \
90+
&& \
6991
make -j$(nproc) install

Dockerfile.QA

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#
2+
# Copyright © 2021 Arm Ltd. All rights reserved.
3+
# SPDX-License-Identifier: MIT
4+
#
5+
6+
#
7+
# Multistage build.
8+
#
9+
10+
ARG BASE_IMAGE=tritonserver
11+
ARG ARMNN_TFLITE_BACKEND_IMAGE=armnn_tflite_backend
12+
ARG BUILD_IMAGE=tritonserver_build
13+
ARG TRITON_REPO_TAG=main
14+
ARG TRITON_COMMON_REPO_TAG=${TRITON_REPO_TAG}
15+
ARG TRITON_CORE_REPO_TAG=${TRITON_REPO_TAG}
16+
ARG TRITON_THIRD_PARTY_REPO_TAG=${TRITON_REPO_TAG}
17+
ARG TRITON_BACKEND_REPO_TAG=${TRITON_REPO_TAG}
18+
ARG TRITON_ENABLE_MALI_GPU=OFF
19+
20+
21+
############################################################################
22+
## Build tests in the BUILD_IMAGE since it has already been configured
23+
## correctly and has some existing build artifacts. Copy artifacts
24+
## into QA area.
25+
############################################################################
26+
FROM ${BUILD_IMAGE} AS build
27+
28+
# Ensure apt-get won't prompt for selecting options
29+
ENV DEBIAN_FRONTEND=noninteractive
30+
31+
# Build the client library and examples
32+
ARG TRITON_REPO_TAG
33+
ARG TRITON_COMMON_REPO_TAG
34+
ARG TRITON_CORE_REPO_TAG
35+
ARG TRITON_BACKEND_REPO_TAG
36+
ARG TRITON_THIRD_PARTY_REPO_TAG
37+
ARG TRITON_ENABLE_MALI_GPU
38+
39+
RUN apt-get update && \
40+
apt-get install -y --no-install-recommends \
41+
software-properties-common \
42+
autoconf \
43+
automake \
44+
build-essential \
45+
curl \
46+
git \
47+
libb64-dev \
48+
libopencv-dev \
49+
libopencv-core-dev \
50+
libssl-dev \
51+
libtool \
52+
pkg-config \
53+
python3 \
54+
python3-pip \
55+
python3-dev \
56+
rapidjson-dev \
57+
vim \
58+
wget \
59+
python3-pdfkit \
60+
maven \
61+
default-jdk && \
62+
pip3 install --upgrade wheel setuptools && \
63+
pip3 install --upgrade grpcio-tools && \
64+
pip3 install --upgrade pip
65+
66+
# Build the client repo
67+
WORKDIR /workspace
68+
RUN git clone --single-branch --depth=1 -b ${TRITON_REPO_TAG} https://github.com/triton-inference-server/client.git client
69+
WORKDIR /workspace/build
70+
RUN cmake -DCMAKE_INSTALL_PREFIX=/workspace/install \
71+
-DTRITON_VERSION=`cat /workspace/TRITON_VERSION` \
72+
-DTRITON_COMMON_REPO_TAG=${TRITON_COMMON_REPO_TAG} \
73+
-DTRITON_CORE_REPO_TAG=${TRITON_CORE_REPO_TAG} \
74+
-DTRITON_BACKEND_REPO_TAG=${TRITON_BACKEND_REPO_TAG} \
75+
-DTRITON_THIRD_PARTY_REPO_TAG=${TRITON_THIRD_PARTY_REPO_TAG} \
76+
-DTRITON_ENABLE_CC_HTTP=ON -DTRITON_ENABLE_CC_GRPC=ON \
77+
-DTRITON_ENABLE_PYTHON_HTTP=ON -DTRITON_ENABLE_PYTHON_GRPC=ON \
78+
-DTRITON_ENABLE_JAVA_HTTP=ON \
79+
-DTRITON_ENABLE_PERF_ANALYZER=ON \
80+
-DTRITON_ENABLE_EXAMPLES=ON -DTRITON_ENABLE_TESTS=ON \
81+
-DTRITON_ENABLE_GPU=OFF /workspace/client
82+
RUN make -j$(nproc) cc-clients python-clients java-clients
83+
84+
WORKDIR /workspace
85+
RUN cd install && \
86+
export VERSION=`cat /workspace/TRITON_VERSION` && \
87+
tar zcf /workspace/v$VERSION.clients.tar.gz *
88+
89+
# Install the dependencies needed to run the client examples. These
90+
# are not needed for building but including them allows this image to
91+
# be used to run the client examples.
92+
RUN pip3 install --upgrade numpy pillow attrdict && \
93+
find install/python/ -maxdepth 1 -type f -name \
94+
"tritonclient-*linux*.whl" | xargs printf -- '%s[all]' | \
95+
xargs pip3 install --upgrade
96+
97+
# Populate the /workspace/qa directory
98+
WORKDIR /workspace
99+
RUN mkdir -p qa/clients && mkdir -p qa/pkgs && \
100+
cp -a install/bin/* qa/clients/. && \
101+
cp install/lib/libgrpcclient.so qa/clients/. && \
102+
cp install/lib/libhttpclient.so qa/clients/. && \
103+
cp install/python/*.py qa/clients/. && \
104+
cp install/python/triton*.whl qa/pkgs/. && \
105+
cp install/java/examples/*.jar qa/clients/.
106+
RUN cp client/src/grpc_generated/go/*.go qa/L0_simple_go_client/. && \
107+
cp -r client/src/grpc_generated/java qa/L0_client_java/.
108+
109+
110+
############################################################################
111+
## Reference ArmNN TFLite image
112+
############################################################################
113+
FROM $ARMNN_TFLITE_BACKEND_IMAGE as armnn_tflite_backend
114+
115+
############################################################################
116+
## Create CI enabled image
117+
############################################################################
118+
FROM $BASE_IMAGE
119+
120+
ARG TARGETPLATFORM
121+
122+
# Ensure apt-get won't prompt for selecting options
123+
ENV DEBIAN_FRONTEND=noninteractive
124+
125+
# CI/QA for memcheck requires valgrind
126+
# libarchive-dev is required by Python backend
127+
RUN apt-get update && apt-get install -y --no-install-recommends \
128+
curl \
129+
libopencv-dev \
130+
libarchive-dev \
131+
libopencv-core-dev \
132+
libzmq3-dev \
133+
python3-dev \
134+
python3-pip \
135+
python3-protobuf \
136+
python3-setuptools \
137+
swig \
138+
nginx \
139+
libpng-dev \
140+
protobuf-compiler \
141+
g++ \
142+
maven \
143+
jq \
144+
valgrind && \
145+
rm -rf /var/lib/apt/lists/*
146+
147+
# CI/QA expects "python" executable (not python3).
148+
RUN rm -f /usr/bin/python && \
149+
ln -s /usr/bin/python3 /usr/bin/python
150+
151+
RUN pip3 install --upgrade wheel setuptools && \
152+
pip3 install --upgrade numpy pillow attrdict future grpcio requests gsutil awscli six grpcio-channelz && \
153+
pip3 install --upgrade pytest pytest-xdist pytest-xprocess jinja2
154+
155+
# CI expects tests in /opt/tritonserver/qa. The triton-server (1000)
156+
# user should own all artifacts in case CI is run using triton-server
157+
# user.
158+
WORKDIR /opt/tritonserver
159+
COPY --chown=1000:1000 --from=build /workspace/qa/ qa/
160+
161+
# Copy in identity backend used in some qa tests
162+
COPY --from=build /tmp/tritonbuild/identity/install/backends/identity /opt/tritonserver/backends/identity
163+
164+
# Copy in pytest files from the current repo
165+
# These are the tests we use to validate the backend functionality
166+
COPY qa/ qa/armnn_tflite_qa
167+
168+
# Remove CI tests that are meant to run only on build image and
169+
# install the tritonserver/triton python client APIs.
170+
RUN rm -fr qa/L0_copyrights qa/L0_build_variants && \
171+
find qa/pkgs/ -maxdepth 1 -type f -name \
172+
"tritonclient-*linux*.whl" | xargs printf -- '%s[all]' | \
173+
xargs pip3 install --upgrade
174+
175+
ENV LD_LIBRARY_PATH /opt/tritonserver/qa/clients:${LD_LIBRARY_PATH}
176+
177+
# Copy in the built armnn_tflite_backend
178+
COPY --from=armnn_tflite_backend /opt/armnn_tflite_backend/build/install/backends/armnn_tflite /opt/tritonserver/backends/armnn_tflite
179+

qa/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Testing
2+
In order to run the test suite for this backend perform the following steps on an Arm64 machine:
3+
4+
Ensure you have git lfs installed and initialized on your machine, as the tflite models used for testing are tracked using lfs:
5+
```
6+
sudo apt install git-lfs
7+
git lfs install
8+
```
9+
10+
First clone the server repository from the fork and branch specified in the following snippet and move to the repo directory:
11+
```
12+
git clone -b feature/armnn_tflite_test_support https://github.com/jishminor/server
13+
cd server
14+
```
15+
16+
Next run the `build.py` script to just build the triton server with the identity and ensemble backend but without including this backend:
17+
```bash
18+
./build.py --cmake-dir=/workspace/build --build-dir=/tmp/citritonbuild --image=base,arm64v8/ubuntu:20.04 --enable-logging --enable-stats --enable-tracing --enable-metrics --endpoint=http --endpoint=grpc --backend=identity --backend=ensemble
19+
```
20+
21+
Build the ArmNN TFLite Backend using the Dockerfile in this repo:
22+
```bash
23+
cd <backend_directory>
24+
docker build --build-arg TFLITE_BAZEL_BUILD=ON --build-arg TFLITE_ENABLE_FLEX_OPS=ON -t armnn_tflite_backend .
25+
```
26+
27+
This will produce the `tritonserver_build` and `tritonserver` images on your machine.
28+
29+
Build the QA image by running the following:
30+
```bash
31+
docker build -t tritonserver_qa -f Dockerfile.QA .
32+
```
33+
34+
Now run the QA container and mount the QA model repositories into the container so the tests will be able to access them.
35+
36+
```bash
37+
docker run -it --rm -v <backend_directory>/qa/triton_qa_models:/data/inferenceserver tritonserver_qa
38+
```
39+
40+
Within the container the QA tests are in /opt/tritonserver/qa. To run a test simply change directory to the test and run the test.sh script.
41+
42+
To run the the full test suite run:
43+
```bash
44+
cd qa/armnn_tflite_qa/
45+
python3 -m pytest tests/ --model-repo-path /data/inferenceserver/accuracy_test_model_repo
46+
```

qa/conftest.py

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
# SPDX-License-Identifier: MIT
33

44
import pytest
5+
from xprocess import ProcessStarter
56

67
from jinja2 import Environment, Template
78

89
import tritonclient.http as httpclient
910
import tritonclient.grpc as grpcclient
1011

1112
from time import sleep
13+
import requests
1214

1315

1416
@pytest.fixture
@@ -73,19 +75,78 @@ def pytest_addoption(parser):
7375
required=False,
7476
help="Path to triton backends",
7577
)
78+
parser.addoption(
79+
"--triton-qa-model-repo-ver",
80+
action="store",
81+
default="21.09",
82+
required=False,
83+
help="Version of the generated qa-model-repo for triton qa tests",
84+
)
85+
86+
87+
@pytest.fixture(scope="module")
88+
def tritonserver(xprocess, host, model_repo_path):
89+
"""
90+
Starts an instance of the triton server
91+
"""
92+
93+
class Starter(ProcessStarter):
94+
pattern = "Started \w* at \d.\d.\d.\d:\d*"
95+
96+
# checks if triton is ready with request to health endpoint
97+
def startup_check(self):
98+
try:
99+
response = requests.get(f"http://{host}:8000/v2/health/ready")
100+
if response.status_code == 200:
101+
return True
102+
else:
103+
return False
104+
except requests.exceptions.RequestException:
105+
return False
106+
107+
# command to start process
108+
args = [
109+
"tritonserver",
110+
"--model-repository",
111+
model_repo_path,
112+
"--model-control-mode",
113+
"explicit",
114+
]
115+
116+
terminate_on_interrupt = True
117+
118+
# ensure process is running and return its logfile
119+
logfile = xprocess.ensure("tritonserver", Starter)
120+
121+
yield
122+
123+
# clean up whole process tree afterwards
124+
xprocess.getinfo("tritonserver").terminate()
76125

77126

78127
def pytest_generate_tests(metafunc):
79128
"""
80129
Makes the program option 'host' available to all tests as a function fixture
81130
"""
82131
if "host" in metafunc.fixturenames:
83-
metafunc.parametrize("host", [metafunc.config.getoption("host")])
132+
metafunc.parametrize(
133+
"host", [metafunc.config.getoption("host")], scope="module"
134+
)
84135
if "model_repo_path" in metafunc.fixturenames:
85136
metafunc.parametrize(
86-
"model_repo_path", [metafunc.config.getoption("model_repo_path")]
137+
"model_repo_path",
138+
[metafunc.config.getoption("model_repo_path")],
139+
scope="module",
87140
)
88141
if "backend_directory" in metafunc.fixturenames:
89142
metafunc.parametrize(
90-
"backend_directory", [metafunc.config.getoption("backend_directory")]
143+
"backend_directory",
144+
[metafunc.config.getoption("backend_directory")],
145+
scope="module",
146+
)
147+
if "triton_qa_model_repo_ver" in metafunc.fixturenames:
148+
metafunc.parametrize(
149+
"triton_qa_model_repo_ver",
150+
[metafunc.config.getoption("triton_qa_model_repo_ver")],
151+
scope="module",
91152
)

0 commit comments

Comments
 (0)