From 6feff757961587cbd42896c8923dcf7402ec9ed0 Mon Sep 17 00:00:00 2001 From: Elias Bermudez Date: Fri, 29 Sep 2023 10:10:22 -0700 Subject: [PATCH] Update grpc request parameters to use only strings in PA --- src/c++/library/common.h | 11 ++----- src/c++/library/grpc_client.cc | 18 ++++++----- .../client_backend/client_backend.h | 8 ++--- .../triton/triton_client_backend.cc | 10 ++---- src/c++/perf_analyzer/command_line_parser.cc | 17 ++-------- .../perf_analyzer/test_command_line_parser.cc | 31 ++----------------- 6 files changed, 26 insertions(+), 69 deletions(-) diff --git a/src/c++/library/common.h b/src/c++/library/common.h index 9337a12e0..9cf99c478 100644 --- a/src/c++/library/common.h +++ b/src/c++/library/common.h @@ -154,15 +154,10 @@ class InferenceServerClient { InferStat infer_stat_; }; -enum RequestParameterType { STRING = 0, INT = 1, BOOL = 2 }; -/// -/// Structure to hold Request parameter data for Inference Request. -/// struct RequestParameter { - std::string str_value; - int64_t int_value; - bool bool_value; - RequestParameterType type; + std::string name; + std::string value; + std::string type; }; //============================================================================== diff --git a/src/c++/library/grpc_client.cc b/src/c++/library/grpc_client.cc index 36fdead87..cc3a9a85f 100644 --- a/src/c++/library/grpc_client.cc +++ b/src/c++/library/grpc_client.cc @@ -35,6 +35,7 @@ #include #include #include +#include #include "common.h" @@ -1410,15 +1411,18 @@ InferenceServerGrpcClient::PreRunProcessing( for (auto& param : options.request_parameters) { - if (param.second.type == RequestParameterType::STRING) { + if (param.second.type == "string") { (*infer_request_.mutable_parameters())[param.first].set_string_param( - param.second.str_value); - } else if (param.second.type == RequestParameterType::INT) { + param.second.value); + } else if (param.second.type == "int") { (*infer_request_.mutable_parameters())[param.first].set_int64_param( - param.second.int_value); - } else if (param.second.type == RequestParameterType::BOOL) { - (*infer_request_.mutable_parameters())[param.first].set_bool_param( - param.second.bool_value); + std::stoi(param.second.value)); + } else if (param.second.type == "bool") { + bool val = false; + if (param.second.value == "true") { + val = true; + } + (*infer_request_.mutable_parameters())[param.first].set_bool_param(val); } } diff --git a/src/c++/perf_analyzer/client_backend/client_backend.h b/src/c++/perf_analyzer/client_backend/client_backend.h index 3070afaa2..870ea3dd5 100644 --- a/src/c++/perf_analyzer/client_backend/client_backend.h +++ b/src/c++/perf_analyzer/client_backend/client_backend.h @@ -192,15 +192,13 @@ struct ModelStatistics { uint64_t cache_miss_time_ns_; }; -enum RequestParameterType { STRING = 0, INT = 1, BOOL = 2 }; /// /// Structure to hold Request parameter data for Inference Request. /// struct RequestParameter { - std::string str_value; - int64_t int_value; - bool bool_value; - RequestParameterType type; + std::string name; + std::string value; + std::string type; }; //============================================================================== diff --git a/src/c++/perf_analyzer/client_backend/triton/triton_client_backend.cc b/src/c++/perf_analyzer/client_backend/triton/triton_client_backend.cc index 7672a22ba..70de5f52b 100644 --- a/src/c++/perf_analyzer/client_backend/triton/triton_client_backend.cc +++ b/src/c++/perf_analyzer/client_backend/triton/triton_client_backend.cc @@ -593,13 +593,9 @@ TritonClientBackend::ParseInferOptionsToTriton( for (auto& map_entry : options.request_parameters_) { auto rp = tc::RequestParameter(); - rp.str_value = map_entry.second.str_value; - rp.int_value = map_entry.second.int_value; - rp.bool_value = map_entry.second.bool_value; - uint64_t val = - static_cast::type>( - map_entry.second.type); - rp.type = static_cast(val); + rp.name = map_entry.second.name; + rp.value = map_entry.second.value; + rp.type = map_entry.second.type; triton_options->request_parameters[map_entry.first] = rp; } } diff --git a/src/c++/perf_analyzer/command_line_parser.cc b/src/c++/perf_analyzer/command_line_parser.cc index d4ec474b8..b6b2194d6 100644 --- a/src/c++/perf_analyzer/command_line_parser.cc +++ b/src/c++/perf_analyzer/command_line_parser.cc @@ -1602,20 +1602,9 @@ CLParser::ParseCommandLine(int argc, char** argv) std::string type{values[2]}; cb::RequestParameter param; - if (type == "bool") { - param.type = cb::RequestParameterType::BOOL; - param.bool_value = value == "true" ? true : false; - } else if (type == "int") { - param.type = cb::RequestParameterType::INT; - param.int_value = std::stoll(value); - } else if (type == "string") { - param.type = cb::RequestParameterType::STRING; - param.str_value = value; - } else { - Usage( - "Failed to parse --request-parameter. Unsupported type: '" + - type + "'."); - } + param.name = name; + param.value = value; + param.type = type; params_->request_parameters[name] = param; break; } diff --git a/src/c++/perf_analyzer/test_command_line_parser.cc b/src/c++/perf_analyzer/test_command_line_parser.cc index 0a802e3f1..bb65f4dc5 100644 --- a/src/c++/perf_analyzer/test_command_line_parser.cc +++ b/src/c++/perf_analyzer/test_command_line_parser.cc @@ -195,14 +195,8 @@ CHECK_PARAMS(PAParamsPtr act, PAParamsPtr exp) exp_param != exp->request_parameters.end(), "Unexpected parameter: ", act_param.first); + CHECK(act_param.second.value == exp_param->second.value); CHECK(act_param.second.type == exp_param->second.type); - if (act_param.second.type == cb::RequestParameterType::STRING) { - CHECK(act_param.second.str_value == exp_param->second.str_value); - } else if (act_param.second.type == cb::RequestParameterType::INT) { - CHECK(act_param.second.int_value == exp_param->second.int_value); - } else if (act_param.second.type == cb::RequestParameterType::BOOL) { - CHECK(act_param.second.bool_value == exp_param->second.bool_value); - } } } @@ -1393,8 +1387,8 @@ TEST_CASE("Testing Command Line Parser") CHECK(!parser.UsageCalled()); cb::RequestParameter param; - param.int_value = 256; - param.type = cb::RequestParameterType::INT; + param.value = "256"; + param.type = "int"; exp->request_parameters["max_tokens"] = param; } @@ -1420,25 +1414,6 @@ TEST_CASE("Testing Command Line Parser") check_params = false; } - - SUBCASE("unsupported type") - { - args.push_back(option_name); - args.push_back("max_tokens:256:hello"); - - int argc = args.size(); - char* argv[argc]; - std::copy(args.begin(), args.end(), argv); - - REQUIRE_NOTHROW(act = parser.Parse(argc, argv)); - CHECK(parser.UsageCalled()); - - expected_msg = - CreateUsageMessage(option_name, "Unsupported type: 'hello'."); - CHECK_STRING("Usage Message", parser.GetUsageMessage(), expected_msg); - - check_params = false; - } } SUBCASE("Option : --latency-threshold")