Skip to content

Commit

Permalink
Update grpc request parameters to use only strings in PA
Browse files Browse the repository at this point in the history
  • Loading branch information
debermudez committed Sep 29, 2023
1 parent eb4ca9b commit 6feff75
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 69 deletions.
11 changes: 3 additions & 8 deletions src/c++/library/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

//==============================================================================
Expand Down
18 changes: 11 additions & 7 deletions src/c++/library/grpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <iostream>
#include <mutex>
#include <sstream>
#include <string>

#include "common.h"

Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/c++/perf_analyzer/client_backend/client_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

//==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::underlying_type<cb::RequestParameterType>::type>(
map_entry.second.type);
rp.type = static_cast<tc::RequestParameterType>(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;
}
}
Expand Down
17 changes: 3 additions & 14 deletions src/c++/perf_analyzer/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
31 changes: 3 additions & 28 deletions src/c++/perf_analyzer/test_command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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")
Expand Down

0 comments on commit 6feff75

Please sign in to comment.