Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve input mismatch error for inference requests (DLIS-6165) #330

Merged
merged 25 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 63 additions & 23 deletions src/infer_request.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -1001,28 +1001,7 @@ InferenceRequest::Normalize()
}
// Make sure that the request is providing the number of inputs
// as is expected by the model.
if ((original_inputs_.size() > (size_t)model_config.input_size()) ||
(original_inputs_.size() < model_raw_->RequiredInputCount())) {
// If no input is marked as optional, then use exact match error message
// for consistency / backward compatibility
if ((size_t)model_config.input_size() == model_raw_->RequiredInputCount()) {
return Status(
Status::Code::INVALID_ARG,
LogRequest() + "expected " +
std::to_string(model_config.input_size()) + " inputs but got " +
std::to_string(original_inputs_.size()) + " inputs for model '" +
ModelName() + "'");
} else {
return Status(
Status::Code::INVALID_ARG,
LogRequest() + "expected number of inputs between " +
std::to_string(model_raw_->RequiredInputCount()) + " and " +
std::to_string(model_config.input_size()) + " but got " +
std::to_string(original_inputs_.size()) + " inputs for model '" +
ModelName() + "'");
}
}

RETURN_IF_ERROR(ValidateRequestInputs());
// Determine the batch size and shape of each input.
if (model_config.max_batch_size() == 0) {
// Model does not support Triton-style batching so set as
Expand Down Expand Up @@ -1195,6 +1174,67 @@ InferenceRequest::Normalize()
return Status::Success;
}

Status
InferenceRequest::ValidateRequestInputs()
{
const inference::ModelConfig& model_config = model_raw_->Config();
if ((original_inputs_.size() > (size_t)model_config.input_size()) ||
(original_inputs_.size() < model_raw_->RequiredInputCount())) {
// If no input is marked as optional, then use exact match error message
// for consistency / backward compatibility
std::string missing_required_input_string = "[";
std::string original_input_string = "[";

for (size_t i = 0; i < (size_t)model_config.input_size(); ++i) {
const inference::ModelInput& input = model_config.input(i);
if ((!input.optional()) &&
(original_inputs_.find(input.name()) == original_inputs_.end())) {
missing_required_input_string =
missing_required_input_string + "'" + input.name() + "'" + ",";
}
}
// Removes the extra ","
missing_required_input_string.pop_back();
missing_required_input_string = missing_required_input_string + "]";

for (const auto& pair : original_inputs_) {
original_input_string =
original_input_string + "'" + pair.first + "'" + ",";
}
// Removes the extra ","
original_input_string.pop_back();
original_input_string = original_input_string + "]";
if (original_inputs_.size() == 0) {
original_input_string = "[]";
}
if ((size_t)model_config.input_size() == model_raw_->RequiredInputCount()) {
// This is response ONLY when there are no optional parameters in the
// model
return Status(
Status::Code::INVALID_ARG,
LogRequest() + "expected " +
std::to_string(model_config.input_size()) + " inputs but got " +
std::to_string(original_inputs_.size()) + " inputs for model '" +
ModelName() + "'. Got input(s) " + original_input_string +
", but missing required input(s) " +
missing_required_input_string +
". Please provide all required input(s).");
} else {
return Status(
Status::Code::INVALID_ARG,
LogRequest() + "expected number of inputs between " +
std::to_string(model_raw_->RequiredInputCount()) + " and " +
std::to_string(model_config.input_size()) + " but got " +
std::to_string(original_inputs_.size()) + " inputs for model '" +
ModelName() + "'. Got input(s) " + original_input_string +
", but missing required input(s) " +
missing_required_input_string +
". Please provide all required input(s).");
}
}
return Status::Success;
}

#ifdef TRITON_ENABLE_STATS
void
InferenceRequest::ReportStatistics(
Expand Down
5 changes: 4 additions & 1 deletion src/infer_request.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -744,6 +744,9 @@ class InferenceRequest {

Status Normalize();

// Helper for validating Inputs
Status ValidateRequestInputs();

// Helpers for pending request metrics
void IncrementPendingRequestCount();
void DecrementPendingRequestCount();
Expand Down
Loading