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

fix: Validate request correlation ID data type #425

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 0 additions & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ constexpr uint64_t NANOS_PER_SECOND = 1000000000;
constexpr uint64_t NANOS_PER_MILLIS = 1000000;
constexpr int MAX_GRPC_MESSAGE_SIZE = INT32_MAX;
constexpr uint64_t SEQUENCE_IDLE_DEFAULT_MICROSECONDS = 1000 * 1000;
constexpr size_t STRING_CORRELATION_ID_MAX_LENGTH_BYTES = 128;
constexpr size_t CUDA_IPC_STRUCT_SIZE = 64;

#ifdef TRITON_ENABLE_METRICS
Expand Down
60 changes: 59 additions & 1 deletion src/infer_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1228,11 +1228,16 @@ InferenceRequest::Normalize()
}
}
}

if (model_config.has_sequence_batching()) {
RETURN_IF_ERROR(ValidateOverrideInputs());
}

return Status::Success;
}

Status
InferenceRequest::ValidateRequestInputs()
InferenceRequest::ValidateRequestInputs() const
{
const inference::ModelConfig& model_config = model_raw_->Config();
if ((original_inputs_.size() > (size_t)model_config.input_size()) ||
Expand Down Expand Up @@ -1404,6 +1409,59 @@ InferenceRequest::ValidateBytesInputs(
return Status::Success;
}

Status
InferenceRequest::ValidateOverrideInputs() const
rmccorm4 marked this conversation as resolved.
Show resolved Hide resolved
{
const inference::ModelConfig& model_config = model_raw_->Config();
const std::string& model_name = ModelName();
std::string correlation_id_tensor_name;
inference::DataType correlation_id_datatype;

RETURN_IF_ERROR(GetTypedSequenceControlProperties(
model_config.sequence_batching(), model_config.name(),
inference::ModelSequenceBatching::Control::CONTROL_SEQUENCE_CORRID,
false /* required */, &correlation_id_tensor_name,
&correlation_id_datatype));

// Make sure request correlation ID type matches model configuration.
if (!correlation_id_tensor_name.empty()) {
const auto& correlation_id = CorrelationId();
bool dtypes_match = true;
std::string request_corrid_datatype;
if ((correlation_id.Type() ==
InferenceRequest::SequenceId::DataType::STRING) &&
(correlation_id_datatype != inference::DataType::TYPE_STRING)) {
dtypes_match = false;
request_corrid_datatype = triton::common::DataTypeToProtocolString(
inference::DataType::TYPE_STRING);
} else if (
(correlation_id.Type() ==
InferenceRequest::SequenceId::DataType::UINT64) &&
((correlation_id_datatype != inference::DataType::TYPE_UINT64) &&
(correlation_id_datatype != inference::DataType::TYPE_INT64) &&
(correlation_id_datatype != inference::DataType::TYPE_UINT32) &&
(correlation_id_datatype != inference::DataType::TYPE_INT32))) {
dtypes_match = false;
request_corrid_datatype = triton::common::DataTypeToProtocolString(
inference::DataType::TYPE_UINT64);
}

if (!dtypes_match) {
return Status(
Status::Code::INVALID_ARG,
LogRequest() + "sequence batching control '" +
correlation_id_tensor_name + "' data-type is '" +
request_corrid_datatype + "', but model '" + model_name +
"' expects '" +
std::string(triton::common::DataTypeToProtocolString(
correlation_id_datatype)) +
"'");
}
}

return Status::Success;
}

#ifdef TRITON_ENABLE_STATS

void
Expand Down
4 changes: 3 additions & 1 deletion src/infer_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,15 @@ class InferenceRequest {
Status Normalize();

// Helper for validating Inputs
Status ValidateRequestInputs();
Status ValidateRequestInputs() const;

Status ValidateBytesInputs(
const std::string& input_id, const Input& input,
const std::string& model_name,
TRITONSERVER_MemoryType* buffer_memory_type) const;

Status ValidateOverrideInputs() const;

// Helpers for pending request metrics
void IncrementPendingRequestCount();
void DecrementPendingRequestCount();
Expand Down
6 changes: 3 additions & 3 deletions src/sequence_batch_scheduler/sequence_batch_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1343,9 +1343,9 @@ SequenceBatch::SetControlTensors(
auto& seq_corr_id = seq_slot_corrid_override_;
size_t size_p = triton::common::GetDataTypeByteSize(seq_corr_id->DType());
if (seq_corr_id->DType() == inference::DataType::TYPE_STRING) {
// 4 bytes for length of string plus pre-defined max string correlation id
// length in bytes
size_p = 4 + triton::core::STRING_CORRELATION_ID_MAX_LENGTH_BYTES;
// 4 bytes for length of string plus string correlation id length in
// bytes.
size_p = 4 + corrid.StringValue().length();
}

TRITONSERVER_MemoryType memory_type;
Expand Down
Loading