Skip to content

Loosen model interface checks #1621

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 24 additions & 6 deletions tensorflow_serving/servables/tensorflow/predict_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,25 @@ std::set<string> SetDifference(std::set<string> set_a, std::set<string> set_b) {

Status VerifyRequestInputsSize(const SignatureDef& signature,
const PredictRequest& request) {
if (request.inputs().size() != signature.inputs().size()) {
if (request.inputs().size() >= signature.inputs().size()) {
const std::set<string> request_inputs = GetMapKeys(request.inputs());
const std::set<string> signature_inputs = GetMapKeys(signature.inputs());
const std::set<string> missing =
SetDifference(signature_inputs, request_inputs);
if (!missing.empty()) {
const std::set<string> sent_extra =
SetDifference(request_inputs, signature_inputs);
return tensorflow::Status(
tensorflow::error::INVALID_ARGUMENT,
absl::StrCat(
"input size does not match signature: ", request.inputs().size(),
"!=", signature.inputs().size(), " len({",
absl::StrJoin(request_inputs, ","), "}) != len({",
absl::StrJoin(signature_inputs, ","), "}). Sent extra: {",
absl::StrJoin(sent_extra, ","), "}. Missing but required: {",
absl::StrJoin(missing, ","), "}."));
}
} else {
const std::set<string> request_inputs = GetMapKeys(request.inputs());
const std::set<string> signature_inputs = GetMapKeys(signature.inputs());
const std::set<string> sent_extra =
Expand Down Expand Up @@ -93,10 +111,10 @@ Status PreProcessPrediction(const SignatureDef& signature,
std::vector<string>* output_tensor_aliases) {
TF_RETURN_IF_ERROR(VerifySignature(signature));
TF_RETURN_IF_ERROR(VerifyRequestInputsSize(signature, request));
for (auto& input : request.inputs()) {
for (auto& input : signature.inputs()) {
const string& alias = input.first;
auto iter = signature.inputs().find(alias);
if (iter == signature.inputs().end()) {
auto iter = request.inputs().find(alias);
if (iter == request.inputs().end()) {
return tensorflow::Status(
tensorflow::error::INVALID_ARGUMENT,
strings::StrCat("input tensor alias not found in signature: ", alias,
Expand All @@ -105,11 +123,11 @@ Status PreProcessPrediction(const SignatureDef& signature,
"}."));
}
Tensor tensor;
if (!tensor.FromProto(input.second)) {
if (!tensor.FromProto(iter->second)) {
return tensorflow::Status(tensorflow::error::INVALID_ARGUMENT,
"tensor parsing error: " + alias);
}
inputs->emplace_back(std::make_pair(iter->second.name(), tensor));
inputs->emplace_back(std::make_pair(input.second.name(), tensor));
}

// Prepare run target.
Expand Down
7 changes: 3 additions & 4 deletions tensorflow_serving/util/json_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,6 @@ Status AddInstanceItem(const rapidjson::Value& item, const string& name,
::google::protobuf::Map<string, int>* size_map,
::google::protobuf::Map<string, TensorShapeProto>* shape_map,
::google::protobuf::Map<string, TensorProto>* tensor_map) {
if (!tensorinfo_map.count(name)) {
return errors::InvalidArgument("JSON object: does not have named input: ",
name);
}
int size = 0;
const auto dtype = tensorinfo_map.at(name).dtype();
auto* tensor = &(*tensor_map)[name];
Expand Down Expand Up @@ -545,6 +541,9 @@ Status FillTensorMapFromInstancesList(
std::set<string> object_keys;
for (const auto& kv : elem.GetObject()) {
const string& name = kv.name.GetString();
if (!tensorinfo_map.count(name)) {
continue;
}
object_keys.insert(name);
const auto status = AddInstanceItem(kv.value, name, tensorinfo_map,
&size_map, &shape_map, tensor_map);
Expand Down