Skip to content

Commit

Permalink
Add test for multiple model versions (#79)
Browse files Browse the repository at this point in the history
Signed-off-by: szalpal <[email protected]>
  • Loading branch information
szalpal authored Jun 17, 2021
1 parent 752f93f commit 61f318b
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 1 deletion.
80 changes: 80 additions & 0 deletions qa/L0_many_versions/many_versions_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python

# The MIT License (MIT)
#
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import argparse, os, sys
import numpy as np
from numpy.random import randint
import tritongrpcclient
from PIL import Image
import math


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action="store_true", required=False, default=False,
help='Enable verbose output')
parser.add_argument('-u', '--url', type=str, required=False, default='localhost:8001',
help='Inference server URL. Default is localhost:8001.')
return parser.parse_args()



def main():
FLAGS = parse_args()
try:
triton_client = tritongrpcclient.InferenceServerClient(url=FLAGS.url, verbose=FLAGS.verbose)
except Exception as e:
print("channel creation failed: " + str(e))
sys.exit(1)

if not (triton_client.is_server_live() or triton_client.is_server_ready()):
print("Error connecting to server: Server live {}. Server ready {}.".format(
triton_client.is_server_live(), triton_client.is_server_ready()))
sys.exit(1)

models_loaded = {
"dali_all": [1, 2, 3],
"dali_latest": [2, 3],
"dali_specific": [2, 3],
}

models_not_loaded = {
"dali_latest": [1],
"dali_specific": [1],
}

for name, versions in models_loaded.items():
for ver in versions:
if not triton_client.is_model_ready(name, str(ver)):
print("FAILED: Model {} version {} not ready".format(name, ver))
sys.exit(1)

for name, versions in models_not_loaded.items():
for ver in versions:
if triton_client.is_model_ready(name, str(ver)):
print("FAILED: Model {} version {} incorrectly loaded".format(name, ver))
sys.exit(1)


if __name__ == '__main__':
main()
46 changes: 46 additions & 0 deletions qa/L0_many_versions/model_repository/addition_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# The MIT License (MIT)
#
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import nvidia.dali as dali


def _parse_args():
import argparse
parser = argparse.ArgumentParser(description="Serialize the pipeline and save it to a file")
parser.add_argument('file_path', type=str, help='The path where to save the serialized pipeline')
parser.add_argument('add_value', type=int, help='Value to add to the input')
return parser.parse_args()


@dali.pipeline_def(batch_size=3, num_threads=1, device_id=0)
def pipe(add_value):
data = dali.fn.external_source(device="cpu", name="DALI_INPUT_0")
return data + add_value


def main(filename, add_value):
pipe(add_value=add_value).serialize(filename=filename)


if __name__ == '__main__':
args = _parse_args()
print(args)
main(args.file_path, args.add_value)
41 changes: 41 additions & 0 deletions qa/L0_many_versions/model_repository/dali_all/config.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# The MIT License (MIT)
#
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

name: "dali_all"
backend: "dali"
max_batch_size: 256
input [
{
name: "DALI_INPUT_0"
data_type: TYPE_UINT8
dims: [ -1 ]
}
]

output [
{
name: "DALI_OUTPUT_0"
data_type: TYPE_UINT8
dims: [ -1 ]
}
]

version_policy: { all{} }
43 changes: 43 additions & 0 deletions qa/L0_many_versions/model_repository/dali_latest/config.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# The MIT License (MIT)
#
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

name: "dali_latest"
backend: "dali"
max_batch_size: 256
input [
{
name: "DALI_INPUT_0"
data_type: TYPE_UINT8
dims: [ -1 ]
}
]

output [
{
name: "DALI_OUTPUT_0"
data_type: TYPE_UINT8
dims: [ -1 ]
}
]

version_policy: {
latest: { num_versions: 2 }
}
43 changes: 43 additions & 0 deletions qa/L0_many_versions/model_repository/dali_specific/config.pbtxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# The MIT License (MIT)
#
# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

name: "dali_specific"
backend: "dali"
max_batch_size: 256
input [
{
name: "DALI_INPUT_0"
data_type: TYPE_UINT8
dims: [ -1 ]
}
]

output [
{
name: "DALI_OUTPUT_0"
data_type: TYPE_UINT8
dims: [ -1 ]
}
]

version_policy: {
specific: { versions: [2, 3] }
}
16 changes: 16 additions & 0 deletions qa/L0_many_versions/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -ex

pushd model_repository

for policy in all latest specific
do
for version in 1 2 3
do
mkdir -p dali_$policy/$version
python addition_pipeline.py "dali_$policy/$version/model.dali" $(( version * 10 ))
done
done

echo "Many-versions model ready."

popd
5 changes: 5 additions & 0 deletions qa/L0_many_versions/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -ex

: ${GRPC_ADDR:=${1:-"localhost:8001"}}

python many_versions_client.py -u $GRPC_ADDR
2 changes: 1 addition & 1 deletion src/dali_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DaliModel : public ::triton::backend::BackendModel {
// We have the json DOM for the model configuration...
common::TritonJson::WriteBuffer buffer;
RETURN_IF_ERROR(model_config_.PrettyWrite(&buffer));
LOG_MESSAGE(TRITONSERVER_LOG_INFO,
LOG_MESSAGE(TRITONSERVER_LOG_VERBOSE,
(std::string("model configuration:\n") + buffer.Contents()).c_str());

return nullptr; // success
Expand Down

0 comments on commit 61f318b

Please sign in to comment.