Skip to content

Commit

Permalink
Automated Code Change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 691713054
  • Loading branch information
tensorflower-gardener authored and tensorflow-copybara committed Oct 31, 2024
1 parent 581da43 commit e5dffd0
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 140 deletions.
11 changes: 6 additions & 5 deletions tensorflow_serving/servables/tensorflow/multi_inference_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class MultiInferenceTest : public ::testing::Test {
static void TearDownTestSuite() { server_core_.reset(); }

protected:
static Status CreateServerCore(std::unique_ptr<ServerCore>* server_core) {
static absl::Status CreateServerCore(
std::unique_ptr<ServerCore>* server_core) {
ModelServerConfig config;
auto model_config = config.mutable_model_config_list()->add_config();
model_config->set_name(kTestModelName);
Expand Down Expand Up @@ -90,7 +91,7 @@ class MultiInferenceTest : public ::testing::Test {

ServerCore* GetServerCore() { return this->server_core_.get(); }

Status GetInferenceRunner(
absl::Status GetInferenceRunner(
std::unique_ptr<TensorFlowMultiInferenceRunner>* inference_runner) {
ServableHandle<SavedModelBundle> bundle;
ModelSpec model_spec;
Expand All @@ -103,7 +104,7 @@ class MultiInferenceTest : public ::testing::Test {
return absl::OkStatus();
}

Status GetServableHandle(ServableHandle<SavedModelBundle>* bundle) {
absl::Status GetServableHandle(ServableHandle<SavedModelBundle>* bundle) {
ModelSpec model_spec;
model_spec.set_name(kTestModelName);
return GetServerCore()->GetServableHandle(model_spec, bundle);
Expand Down Expand Up @@ -142,8 +143,8 @@ void PopulateTask(const string& signature_name, const string& method_name,
task->set_method_name(method_name);
}

void ExpectStatusError(const Status& status,
const tensorflow::errors::Code expected_code,
void ExpectStatusError(const absl::Status& status,
const absl::StatusCode expected_code,
const string& message_substring) {
EXPECT_EQ(expected_code, status.code());
EXPECT_THAT(status.message(), ::testing::HasSubstr(message_substring));
Expand Down
42 changes: 21 additions & 21 deletions tensorflow_serving/servables/tensorflow/predict_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace tensorflow {
namespace serving {
namespace {

Status VerifySignature(const SignatureDef& signature) {
absl::Status VerifySignature(const SignatureDef& signature) {
if (GetSignatureMethodNameCheckFeature() &&
signature.method_name() != kPredictMethodName &&
signature.method_name() != kClassifyMethodName &&
Expand All @@ -48,8 +48,8 @@ Status VerifySignature(const SignatureDef& signature) {
return absl::OkStatus();
}

Status VerifyRequestInputsSize(const SignatureDef& signature,
const PredictRequest& request) {
absl::Status VerifyRequestInputsSize(const SignatureDef& signature,
const PredictRequest& request) {
if (request.inputs().size() > signature.inputs().size() ||
(request.inputs().size() < signature.inputs().size() &&
signature.defaults().empty())) {
Expand All @@ -59,7 +59,7 @@ Status VerifyRequestInputsSize(const SignatureDef& signature,
SetDifference(request_inputs, signature_inputs);
const std::set<string> missing =
SetDifference(signature_inputs, request_inputs);
return tensorflow::Status(
return absl::Status(
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
absl::StrCat(
"input size does not match signature: ", request.inputs().size(),
Expand All @@ -75,7 +75,7 @@ Status VerifyRequestInputsSize(const SignatureDef& signature,
} // namespace

namespace internal {
Status RunPredict(
absl::Status RunPredict(
const RunOptions& run_options, const MetaGraphDef& meta_graph_def,
const absl::optional<int64_t>& servable_version,
const internal::PredictResponseTensorSerializationOption option,
Expand Down Expand Up @@ -116,11 +116,11 @@ Status RunPredict(
response);
}

Status PreProcessPrediction(const SignatureDef& signature,
const PredictRequest& request,
std::vector<std::pair<string, Tensor>>* inputs,
std::vector<string>* output_tensor_names,
std::vector<string>* output_tensor_aliases) {
absl::Status PreProcessPrediction(
const SignatureDef& signature, const PredictRequest& request,
std::vector<std::pair<string, Tensor>>* inputs,
std::vector<string>* output_tensor_names,
std::vector<string>* output_tensor_aliases) {
TF_RETURN_IF_ERROR(VerifySignature(signature));
TF_RETURN_IF_ERROR(VerifyRequestInputsSize(signature, request));
TF_RETURN_IF_ERROR(
Expand All @@ -133,15 +133,15 @@ Status PreProcessPrediction(const SignatureDef& signature,
for (auto& alias : output_filter) {
auto iter = signature.outputs().find(alias);
if (iter == signature.outputs().end()) {
return tensorflow::Status(
return absl::Status(
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
strings::StrCat("output tensor alias not found in signature: ", alias,
" Outputs expected to be in the set {",
absl::StrJoin(GetMapKeys(signature.outputs()), ","),
"}."));
}
if (seen_outputs.find(alias) != seen_outputs.end()) {
return tensorflow::Status(
return absl::Status(
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
"duplicate output tensor alias: " + alias);
}
Expand All @@ -160,15 +160,15 @@ Status PreProcessPrediction(const SignatureDef& signature,
return absl::OkStatus();
}

Status PostProcessPredictionResult(
absl::Status PostProcessPredictionResult(
const std::vector<string>& output_tensor_aliases,
const std::vector<Tensor>& output_tensors,
const internal::PredictResponseTensorSerializationOption option,
PredictResponse* response) {
// Validate and return output.
if (output_tensors.size() != output_tensor_aliases.size()) {
return tensorflow::Status(
static_cast<tensorflow::errors::Code>(absl::StatusCode::kUnknown),
return absl::Status(
static_cast<absl::StatusCode>(absl::StatusCode::kUnknown),
"Predict internal error");
}
switch (option) {
Expand All @@ -191,12 +191,12 @@ Status PostProcessPredictionResult(

} // namespace internal

Status RunPredict(const RunOptions& run_options,
const MetaGraphDef& meta_graph_def,
const absl::optional<int64_t>& servable_version,
Session* session, const PredictRequest& request,
PredictResponse* response,
const thread::ThreadPoolOptions& thread_pool_options) {
absl::Status RunPredict(const RunOptions& run_options,
const MetaGraphDef& meta_graph_def,
const absl::optional<int64_t>& servable_version,
Session* session, const PredictRequest& request,
PredictResponse* response,
const thread::ThreadPoolOptions& thread_pool_options) {
return internal::RunPredict(
run_options, meta_graph_def, servable_version,
internal::PredictResponseTensorSerializationOption::kAsProtoField,
Expand Down
65 changes: 34 additions & 31 deletions tensorflow_serving/servables/tensorflow/predict_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,42 @@ class FakeSession : public tensorflow::Session {
public:
FakeSession() {}
~FakeSession() override = default;
Status Create(const GraphDef& graph) override {
absl::Status Create(const GraphDef& graph) override {
return errors::Unimplemented("not available in fake");
}
Status Extend(const GraphDef& graph) override {
absl::Status Extend(const GraphDef& graph) override {
return errors::Unimplemented("not available in fake");
}
Status Close() override {
absl::Status Close() override {
return errors::Unimplemented("not available in fake");
}
Status ListDevices(std::vector<DeviceAttributes>* response) override {
absl::Status ListDevices(std::vector<DeviceAttributes>* response) override {
return errors::Unimplemented("not available in fake");
}
Status Run(const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes,
std::vector<Tensor>* outputs) override {
absl::Status Run(const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes,
std::vector<Tensor>* outputs) override {
RunMetadata run_metadata;
return Run(RunOptions(), inputs, output_names, target_nodes, outputs,
&run_metadata);
}
Status Run(const RunOptions& run_options,
const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes,
std::vector<Tensor>* outputs, RunMetadata* run_metadata) override {
absl::Status Run(const RunOptions& run_options,
const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes,
std::vector<Tensor>* outputs,
RunMetadata* run_metadata) override {
return Run(run_options, inputs, output_names, target_nodes, outputs,
run_metadata, thread::ThreadPoolOptions());
}
Status Run(const RunOptions& run_options,
const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes,
std::vector<Tensor>* outputs, RunMetadata* run_metadata,
const thread::ThreadPoolOptions& thread_pool_options) override {
absl::Status Run(
const RunOptions& run_options,
const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes, std::vector<Tensor>* outputs,
RunMetadata* run_metadata,
const thread::ThreadPoolOptions& thread_pool_options) override {
for (const auto& t : inputs) {
outputs->push_back(t.second);
}
Expand Down Expand Up @@ -118,8 +120,8 @@ class PredictImplTest : public ::testing::Test {
}

protected:
static Status CreateServerCore(const string& model_path,
std::unique_ptr<ServerCore>* server_core) {
static absl::Status CreateServerCore(
const string& model_path, std::unique_ptr<ServerCore>* server_core) {
ModelServerConfig config;
auto model_config = config.mutable_model_config_list()->add_config();
model_config->set_name(kTestModelName);
Expand Down Expand Up @@ -152,17 +154,18 @@ class PredictImplTest : public ::testing::Test {
return saved_model_server_core_counter_model_.get();
}

Status GetSavedModelServableHandle(ServerCore* server_core,
ServableHandle<SavedModelBundle>* bundle) {
absl::Status GetSavedModelServableHandle(
ServerCore* server_core, ServableHandle<SavedModelBundle>* bundle) {
ModelSpec model_spec;
model_spec.set_name(kTestModelName);
return server_core->GetServableHandle(model_spec, bundle);
}

Status CallPredict(ServerCore* server_core, const PredictRequest& request,
PredictResponse* response,
const thread::ThreadPoolOptions& thread_pool_options =
thread::ThreadPoolOptions()) {
absl::Status CallPredict(
ServerCore* server_core, const PredictRequest& request,
PredictResponse* response,
const thread::ThreadPoolOptions& thread_pool_options =
thread::ThreadPoolOptions()) {
ServableHandle<SavedModelBundle> bundle;
TF_RETURN_IF_ERROR(GetSavedModelServableHandle(server_core, &bundle));
return RunPredict(GetRunOptions(), bundle->meta_graph_def,
Expand Down Expand Up @@ -238,7 +241,7 @@ TEST_F(PredictImplTest, InputTensorsDontMatchModelSpecInputs) {
tensor_proto2.mutable_tensor_shape()->add_dim()->set_size(1);
(*inputs)["unknown_key2"] = tensor_proto2;

Status status = CallPredict(GetServerCore(), request, &response);
absl::Status status = CallPredict(GetServerCore(), request, &response);
EXPECT_EQ(status.code(),
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument));
EXPECT_THAT(status.message(),
Expand Down Expand Up @@ -283,7 +286,7 @@ TEST_F(PredictImplTest, OutputFiltersDontMatchModelSpecOutputs) {
request.add_output_filter("output_filter");

// Output filter like this doesn't exist.
Status status1 = CallPredict(GetServerCore(), request, &response);
absl::Status status1 = CallPredict(GetServerCore(), request, &response);
EXPECT_EQ(status1.code(),
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument));
EXPECT_THAT(status1.message(),
Expand All @@ -296,7 +299,7 @@ TEST_F(PredictImplTest, OutputFiltersDontMatchModelSpecOutputs) {
request.add_output_filter(kOutputTensorKey);

// Duplicate output filter specified.
Status status2 = CallPredict(GetServerCore(), request, &response);
absl::Status status2 = CallPredict(GetServerCore(), request, &response);
EXPECT_EQ(status2.code(),
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument));
EXPECT_THAT(status2.message(),
Expand All @@ -319,7 +322,7 @@ TEST_F(PredictImplTest, InputTensorsHaveWrongType) {
request.add_output_filter(kOutputTensorKey);

// Input tensors are all wrong.
Status status = CallPredict(GetServerCore(), request, &response);
absl::Status status = CallPredict(GetServerCore(), request, &response);
EXPECT_EQ(status.code(),
static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument));
EXPECT_THAT(status.message(),
Expand Down
40 changes: 20 additions & 20 deletions tensorflow_serving/servables/tensorflow/regressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class SavedModelTensorFlowRegressor : public RegressorInterface {

~SavedModelTensorFlowRegressor() override = default;

Status Regress(const RegressionRequest& request,
RegressionResult* result) override {
absl::Status Regress(const RegressionRequest& request,
RegressionResult* result) override {
TRACELITERAL("SavedModelTensorFlowRegressor::Regress");

string input_tensor_name;
Expand Down Expand Up @@ -99,8 +99,8 @@ class SavedModelRegressor : public RegressorInterface {

~SavedModelRegressor() override = default;

Status Regress(const RegressionRequest& request,
RegressionResult* result) override {
absl::Status Regress(const RegressionRequest& request,
RegressionResult* result) override {
SignatureDef signature;
TF_RETURN_IF_ERROR(GetRegressionSignatureDef(
request.model_spec(), bundle_->meta_graph_def, &signature));
Expand All @@ -118,22 +118,22 @@ class SavedModelRegressor : public RegressorInterface {

} // namespace

Status CreateRegressorFromSavedModelBundle(
absl::Status CreateRegressorFromSavedModelBundle(
const RunOptions& run_options, std::unique_ptr<SavedModelBundle> bundle,
std::unique_ptr<RegressorInterface>* service) {
service->reset(new SavedModelRegressor(run_options, std::move(bundle)));
return absl::OkStatus();
}

Status CreateFlyweightTensorFlowRegressor(
absl::Status CreateFlyweightTensorFlowRegressor(
const RunOptions& run_options, Session* session,
const SignatureDef* signature,
std::unique_ptr<RegressorInterface>* service) {
return CreateFlyweightTensorFlowRegressor(
run_options, session, signature, thread::ThreadPoolOptions(), service);
}

Status CreateFlyweightTensorFlowRegressor(
absl::Status CreateFlyweightTensorFlowRegressor(
const RunOptions& run_options, Session* session,
const SignatureDef* signature,
const thread::ThreadPoolOptions& thread_pool_options,
Expand All @@ -143,9 +143,9 @@ Status CreateFlyweightTensorFlowRegressor(
return absl::OkStatus();
}

Status GetRegressionSignatureDef(const ModelSpec& model_spec,
const MetaGraphDef& meta_graph_def,
SignatureDef* signature) {
absl::Status GetRegressionSignatureDef(const ModelSpec& model_spec,
const MetaGraphDef& meta_graph_def,
SignatureDef* signature) {
const string signature_name = model_spec.signature_name().empty()
? kDefaultServingSignatureDefKey
: model_spec.signature_name();
Expand All @@ -167,9 +167,9 @@ Status GetRegressionSignatureDef(const ModelSpec& model_spec,
return absl::OkStatus();
}

Status PreProcessRegression(const SignatureDef& signature,
string* input_tensor_name,
std::vector<string>* output_tensor_names) {
absl::Status PreProcessRegression(const SignatureDef& signature,
string* input_tensor_name,
std::vector<string>* output_tensor_names) {
if (GetSignatureMethodNameCheckFeature() &&
signature.method_name() != kRegressMethodName) {
return errors::InvalidArgument(strings::StrCat(
Expand Down Expand Up @@ -207,7 +207,7 @@ Status PreProcessRegression(const SignatureDef& signature,
return absl::OkStatus();
}

Status PostProcessRegressionResult(
absl::Status PostProcessRegressionResult(
const SignatureDef& signature, int num_examples,
const std::vector<string>& output_tensor_names,
const std::vector<Tensor>& output_tensors, RegressionResult* result) {
Expand Down Expand Up @@ -266,12 +266,12 @@ Status PostProcessRegressionResult(
return absl::OkStatus();
}

Status RunRegress(const RunOptions& run_options,
const MetaGraphDef& meta_graph_def,
const absl::optional<int64_t>& servable_version,
Session* session, const RegressionRequest& request,
RegressionResponse* response,
const thread::ThreadPoolOptions& thread_pool_options) {
absl::Status RunRegress(const RunOptions& run_options,
const MetaGraphDef& meta_graph_def,
const absl::optional<int64_t>& servable_version,
Session* session, const RegressionRequest& request,
RegressionResponse* response,
const thread::ThreadPoolOptions& thread_pool_options) {
SignatureDef signature;
TF_RETURN_IF_ERROR(GetRegressionSignatureDef(request.model_spec(),
meta_graph_def, &signature));
Expand Down
Loading

0 comments on commit e5dffd0

Please sign in to comment.