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 Classifier Test

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

Overview

Test suite validating the TFRT-based classifier servable, which handles classification inference using the TFRT runtime.

Description

This test file validates the TFRT classifier implementation which uses the TFRT (TensorFlow RunTime) execution engine instead of the traditional TensorFlow session. The TfrtClassifierTest fixture initializes a TFRT runtime with 4 inter-op threads, sets up a ServerCore with the saved_model_half_plus_two_cpu model using TfrtSavedModelSourceAdapterConfig, and obtains ServableHandle<Servable> instances to call Classify.

Key areas tested include:

  • Basic classification with single and multiple examples
  • Classification 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, type, and size

Usage

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

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/servables/tensorflow/tfrt_classifier_test.cc
  • Lines: 1-565

Test Fixture

class TfrtClassifierTest : 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 GetSavedModelServableHandle(
      ServerCore* server_core, ServableHandle<Servable>* servable);
  absl::Status CallClassify(ServerCore* server_core,
                            const ClassificationRequest& request,
                            ClassificationResponse* response);
  static std::unique_ptr<ServerCore> server_core_;
  ClassificationRequest request_;
};

Build Target

bazel test //tensorflow_serving/servables/tensorflow:tfrt_classifier_test

Test Coverage

Key Test Cases

Test Name Category Description
Basic Integration Tests basic classification with multiple examples
BasicWithContext Integration Tests classification 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
UnexpectedOutputTensorType Validation Tests error on unexpected output tensor type
UnexpectedOutputTensorSize Validation Tests error on unexpected output tensor size

Usage Examples

Test Pattern

TEST_F(TfrtClassifierTest, Basic) {
  auto request = test_util::CreateProto<ClassificationRequest>(
      "model_spec {"
      "  name: \"test_model\""
      "  signature_name: \"classify_x_to_y\""
      "}"
      "input { example_list { examples { features { ... } } } }");
  ClassificationResponse response;
  TF_ASSERT_OK(CallClassify(server_core_.get(), request, &response));
  // Validate classification results
}

Related Pages

Page Connections

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