Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Tensorflow Serving Tfrt Regressor Test

From Leeroopedia
Knowledge Sources
Domains Testing, Regression, TFRT
Last Updated 2026-02-13 00:00 GMT

Overview

Test suite validating the TFRT-based regressor servable, which handles regression inference using the TFRT runtime.

Description

This test file validates the TFRT regressor implementation which uses the TFRT execution engine for regression inference. The TfrtRegressorTest fixture initializes a TFRT runtime with 4 inter-op threads, sets up a ServerCore with saved_model_half_plus_two_cpu model using TfrtSavedModelSourceAdapterConfig, and uses RunRegress via TfrtSavedModelServable.

Key areas tested include:

  • Basic regression with single and multiple examples
  • Regression with context features
  • Empty input and example list validation
  • Invalid function name, input size, output size, input name, output name handling
  • Session run failures
  • Unexpected output tensor number, shape, size, and type

Usage

Run these tests to validate changes to the TFRT regressor, TFRT servable interface, or TFRT-based regression pipeline.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/servables/tensorflow/tfrt_regressor_test.cc
  • Lines: 1-570

Test Fixture

class TfrtRegressorTest : public ::testing::Test {
 public:
  static void SetUpTestSuite() {
    tfrt_stub::SetGlobalRuntime(
        tfrt_stub::Runtime::Create(/*num_inter_op_threads=*/4));
  }
  void SetUp() override {
    // Creates ServerCore with TfrtSavedModelSourceAdapterConfig
    // and saved_model_half_plus_two_cpu model
  }
 protected:
  absl::Status CallRegress(ServerCore* server_core,
                           const RegressionRequest& request,
                           RegressionResponse* response) {
    ServableHandle<Servable> servable;
    TF_RETURN_IF_ERROR(GetSavedModelServableHandle(server_core, &servable));
    return RunRegress(run_options, kTestModelVersion,
        &(down_cast<TfrtSavedModelServable*>(servable.get()))->saved_model(),
        request, response);
  }
  static std::unique_ptr<ServerCore> server_core_;
  RegressionRequest request_;
};

Build Target

bazel test //tensorflow_serving/servables/tensorflow:tfrt_regressor_test

Test Coverage

Key Test Cases

Test Name Category Description
Basic Integration Tests basic regression with multiple examples
BasicWithContext Integration Tests regression with context features
EmptyExampleList Validation Tests error on empty example list
EmptyExampleListWithContext Validation Tests error on empty example list with context
EmptyInput Validation Tests error on empty input
InvalidFunctionName Error Handling Tests error on non-existent function name
InvalidFunctionUnmatchedInputSize Error Handling Tests error on mismatched input count
InvalidFunctionUnmatchedOutputSize Error Handling Tests error on mismatched output count
InvalidFunctionInvalidInputName Error Handling Tests error on invalid input tensor name
InvalidFunctionInvalidOutputName Error Handling Tests error on invalid output tensor name
RunsFails Error Handling Tests handling of TFRT run failures
UnexpectedOutputTensorNumber Validation Tests error on unexpected number of output tensors
UnexpectedOutputTensorShape Validation Tests error on unexpected output tensor shape
UnexpectedOutputTensorSize Validation Tests error on unexpected output tensor size
UnexpectedOutputTensorType Validation Tests error on unexpected output tensor type

Usage Examples

Test Pattern

TEST_F(TfrtRegressorTest, Basic) {
  auto request = test_util::CreateProto<RegressionRequest>(
      "model_spec {"
      "  name: \"test_model\""
      "  signature_name: \"regress_x_to_y\""
      "}"
      "input { example_list { examples { features { ... } } } }");
  RegressionResponse response;
  TF_ASSERT_OK(CallRegress(server_core_.get(), request, &response));
  // Validate regression value: 0.5 * x + 2
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment