Skip to content

Commit

Permalink
Add some autofill unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
David Goodwin committed Nov 14, 2018
1 parent e9b541b commit 73e62fe
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/core/model_config_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ ModelConfigManager::ReadModelConfigs(

for (const auto& child : real_children) {
const auto full_path = tensorflow::io::JoinPath(model_store_path, child);
if (!tensorflow::Env::Default()->IsDirectory(full_path).ok()) {
continue;
}

const auto& ret = model_configs->emplace(child, ModelConfig{});
if (!ret.second) {
return tensorflow::errors::InvalidArgument(
Expand Down
12 changes: 10 additions & 2 deletions src/core/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ GetAutoFillPlatform(
real_versions.insert(version.substr(0, version.find_first_of('/')));
}

if (real_versions.empty()) {
std::set<std::string> version_dirs;
for (const auto& version : real_versions) {
const auto vp = tensorflow::io::JoinPath(model_path, version);
if (tensorflow::Env::Default()->IsDirectory(vp).ok()) {
version_dirs.insert(version);
}
}

if (version_dirs.empty()) {
return tensorflow::errors::NotFound(
"no version sub-directories for model '", model_name, "'");
}

// If a default named file/directory exists in a version
// sub-directory then assume the corresponding platform.
for (const auto& version : real_versions) {
for (const auto& version : version_dirs) {
const auto vp = tensorflow::io::JoinPath(model_path, version);

// TensorRT
Expand Down
7 changes: 7 additions & 0 deletions src/servables/caffe2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ cc_library(
alwayslink = 1,
)

filegroup(
name = "caffe2_testdata",
srcs = glob(
["testdata/**/*"]),
)

cc_test(
name = "netdef_bundle_test",
srcs = ["netdef_bundle_test.cc"],
Expand All @@ -94,6 +100,7 @@ cc_test(
"-lnvidia-ml"
],
data = [
":caffe2_testdata"
],
deps = [
":netdef_bundle",
Expand Down
5 changes: 5 additions & 0 deletions src/servables/caffe2/netdef_bundle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ TEST_F(NetDefBundleTest, ModelConfigSanity)

// Standard testing...
ValidateAll(kCaffe2NetDefPlatform, init_func);

// Sanity tests with autofill and not providing the platform.
ValidateOne(
"inference_server/src/servables/caffe2/testdata/autofill_sanity",
true /* autofill */, std::string() /* platform */, init_func);
}

}}} // namespace nvidia::inferenceserver::test
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
max_batch_size: 1
input [
{
name: "input"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
output [
{
name: "output"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "no_name_platform"
platform: "caffe2_netdef"
version_policy {
latest {
num_versions: 1
}
}
max_batch_size: 1
input {
name: "input"
data_type: TYPE_FP32
dims: 16
}
output {
name: "output"
data_type: TYPE_FP32
dims: 16
}
instance_group {
name: "no_name_platform"
count: 1
gpus: 0
kind: KIND_GPU
}
default_model_filename: "model.netdef"
8 changes: 8 additions & 0 deletions src/servables/tensorflow/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ cc_library(
alwayslink = 1,
)

filegroup(
name = "tf_testdata",
srcs = glob(
["testdata/**/*"]),
)

cc_test(
name = "graphdef_bundle_test",
srcs = ["graphdef_bundle_test.cc"],
Expand All @@ -135,6 +141,7 @@ cc_test(
"-lnvidia-ml"
],
data = [
":tf_testdata"
],
deps = [
":graphdef_bundle",
Expand All @@ -155,6 +162,7 @@ cc_test(
"-lnvidia-ml"
],
data = [
":tf_testdata"
],
deps = [
":savedmodel_bundle",
Expand Down
6 changes: 6 additions & 0 deletions src/servables/tensorflow/graphdef_bundle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ TEST_F(GraphDefBundleTest, ModelConfigSanity)

// Standard testing...
ValidateAll(kTensorFlowGraphDefPlatform, init_func);

// Sanity tests with autofill and not providing the platform.
ValidateOne(
"inference_server/src/servables/tensorflow/testdata/"
"graphdef_autofill_sanity",
true /* autofill */, std::string() /* platform */, init_func);
}

}}} // namespace nvidia::inferenceserver::test
6 changes: 6 additions & 0 deletions src/servables/tensorflow/savedmodel_bundle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ TEST_F(SavedModelBundleTest, ModelConfigSanity)

// Standard testing...
ValidateAll(kTensorFlowSavedModelPlatform, init_func);

// Sanity tests with autofill and not providing the platform.
ValidateOne(
"inference_server/src/servables/tensorflow/testdata/"
"savedmodel_autofill_sanity",
true /* autofill */, std::string() /* platform */, init_func);
}

}}} // namespace nvidia::inferenceserver::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
max_batch_size: 1
input [
{
name: "input"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
output [
{
name: "output"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "no_name_platform"
platform: "tensorflow_graphdef"
version_policy {
latest {
num_versions: 1
}
}
max_batch_size: 1
input {
name: "input"
data_type: TYPE_FP32
dims: 16
}
output {
name: "output"
data_type: TYPE_FP32
dims: 16
}
instance_group {
name: "no_name_platform"
count: 1
gpus: 0
kind: KIND_GPU
}
default_model_filename: "model.graphdef"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
max_batch_size: 1
input [
{
name: "input"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
output [
{
name: "output"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "no_name_platform"
platform: "tensorflow_savedmodel"
version_policy {
latest {
num_versions: 1
}
}
max_batch_size: 1
input {
name: "input"
data_type: TYPE_FP32
dims: 16
}
output {
name: "output"
data_type: TYPE_FP32
dims: 16
}
instance_group {
name: "no_name_platform"
count: 1
gpus: 0
kind: KIND_GPU
}
default_model_filename: "model.savedmodel"
7 changes: 7 additions & 0 deletions src/servables/tensorrt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ cc_library(
alwayslink = 1,
)

filegroup(
name = "tensorrt_testdata",
srcs = glob(
["testdata/**/*"]),
)

cc_test(
name = "plan_bundle_test",
srcs = ["plan_bundle_test.cc"],
Expand All @@ -96,6 +102,7 @@ cc_test(
"-lnvonnxparser_runtime"
],
data = [
":tensorrt_testdata"
],
deps = [
":plan_bundle",
Expand Down
5 changes: 5 additions & 0 deletions src/servables/tensorrt/plan_bundle_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ TEST_F(PlanBundleTest, ModelConfigSanity)

// Standard testing...
ValidateAll(kTensorRTPlanPlatform, init_func);

// Sanity tests with autofill and not providing the platform.
ValidateOne(
"inference_server/src/servables/tensorrt/testdata/autofill_sanity",
true /* autofill */, std::string() /* platform */, init_func);
}

}}} // namespace nvidia::inferenceserver::test
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
max_batch_size: 1
input [
{
name: "input"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
output [
{
name: "output"
data_type: TYPE_FP32
dims: [ 16 ]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "no_name_platform"
platform: "tensorrt_plan"
version_policy {
latest {
num_versions: 1
}
}
max_batch_size: 1
input {
name: "input"
data_type: TYPE_FP32
dims: 16
}
output {
name: "output"
data_type: TYPE_FP32
dims: 16
}
instance_group {
name: "no_name_platform"
count: 1
gpus: 0
kind: KIND_GPU
}
default_model_filename: "model.plan"
26 changes: 19 additions & 7 deletions src/test/model_config_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ namespace nvidia { namespace inferenceserver { namespace test {

bool
ModelConfigTestBase::ValidateInit(
const std::string& path, bool autofill, BundleInitFunc init_func,
const std::string& model_path, bool autofill, BundleInitFunc init_func,
std::string* result)
{
result->clear();

ModelConfig config;
tensorflow::Status status = GetNormalizedModelConfig(path, autofill, &config);
tensorflow::Status status =
GetNormalizedModelConfig(model_path, autofill, &config);
if (!status.ok()) {
result->append(status.ToString());
return false;
Expand All @@ -55,7 +56,10 @@ ModelConfigTestBase::ValidateInit(
return false;
}

status = init_func(path, config);
// ModelConfig unit tests assume model version "1"
const std::string version_path = tensorflow::io::JoinPath(model_path, "1");

status = init_func(version_path, config);
if (!status.ok()) {
result->append(status.ToString());
return false;
Expand All @@ -73,6 +77,11 @@ ModelConfigTestBase::ValidateAll(
ValidateOne(
"inference_server/src/test/testdata/model_config_sanity",
false /* autofill */, platform, init_func);

// Sanity tests with autofill and no platform.
ValidateOne(
"inference_server/src/test/testdata/autofill_sanity", true /* autofill */,
std::string() /* platform */, init_func);
}

void
Expand Down Expand Up @@ -110,7 +119,7 @@ ModelConfigTestBase::ValidateOne(
}

LOG_INFO << "Testing " << model_name;
std::string actual;
std::string actual, truncated_actual;
ValidateInit(model_path, autofill, init_func, &actual);

std::ifstream expected_file(expected_path);
Expand All @@ -119,10 +128,13 @@ ModelConfigTestBase::ValidateOne(
(std::istreambuf_iterator<char>()));

if (expected.size() < actual.size()) {
actual = actual.substr(0, expected.size());
truncated_actual = actual.substr(0, expected.size());
} else {
truncated_actual = actual;
}
EXPECT_TRUE(expected == actual);
if (expected != actual) {

EXPECT_TRUE(expected == truncated_actual);
if (expected != truncated_actual) {
LOG_ERROR << "Expected:" << std::endl << expected;
LOG_ERROR << "Actual:" << std::endl << actual;
}
Expand Down
Loading

0 comments on commit 73e62fe

Please sign in to comment.