All Products
Search
Document Center

Platform For AI:TensorFlow processor

Last Updated:Mar 05, 2026

Elastic Algorithm Service (EAS) menyediakan TensorFlow processor bawaan untuk menerapkan model TensorFlow dalam format SavedModel standar sebagai layanan online. Topik ini menjelaskan cara menerapkan dan memanggil layanan model tersebut.

Informasi latar belakang

Jika model Anda berupa model Keras atau Checkpoint, Anda harus mengonversinya terlebih dahulu ke format SavedModel sebelum dapat menerapkannya. Untuk informasi selengkapnya, lihat Ekspor model TensorFlow dalam format SavedModel. Model yang telah dioptimalkan oleh PAI-Blade dapat dijalankan secara langsung.

Versi TensorFlow processor

TensorFlow tersedia dalam beberapa versi yang mendukung perangkat CPU maupun GPU. Jika tidak memiliki kebutuhan bisnis khusus, gunakan versi terbaru saat menerapkan layanan. Versi TensorFlow yang lebih baru menawarkan performa lebih baik dan kompatibilitas maju dengan fitur-fitur dari versi sebelumnya. Tabel berikut mencantumkan nama processor untuk setiap versi TensorFlow.

Processor name

TensorFlow version

GPU support

tensorflow_cpu_1.12

TensorFlow 1.12

No

tensorflow_cpu_1.14

TensorFlow 1.14

No

tensorflow_cpu_1.15

TensorFlow 1.15

No

tensorflow_cpu_2.3

TensorFlow 2.3

No

tensorflow_cpu_2.4

TensorFlow 2.4

No

tensorflow_cpu_2.7

TensorFlow 2.7

No

tensorflow_gpu_1.12

TensorFlow 1.12

Yes

tensorflow_gpu_1.14

TensorFlow 1.14

Yes

tensorflow_gpu_1.15

TensorFlow 1.15

Yes

tensorflow_gpu_2.4

TensorFlow 2.4

Yes

tensorflow_gpu_2.7

TensorFlow 2.7

Yes

Langkah 1: Terapkan layanan

  1. Opsional: Konfigurasikan file permintaan untuk warm-up.

    Saat beberapa model TensorFlow dipanggil pertama kali, file dan parameter terkaitnya harus dimuat ke dalam memori. Proses ini bisa memakan waktu lama dan menyebabkan waktu respons (RT) tinggi pada beberapa permintaan awal. Bahkan, hal ini dapat menyebabkan error seperti 408 (request timed out) atau 450 (permintaan dibuang karena antrian penuh). Untuk mencegah jitter layanan selama pembaruan bergulir (rolling updates), Anda dapat menambahkan parameter untuk melakukan warm-up model selama penerapan layanan. Hal ini memastikan bahwa instans layanan hanya menerima traffic setelah proses warm-up selesai. Untuk informasi selengkapnya, lihat Konfigurasi Lanjutan: Warm-up layanan model.

  2. Terapkan layanan.

    Saat menggunakan client EASCMD untuk menerapkan layanan model TensorFlow, atur parameter processor type ke nama processor yang sesuai. Berikut adalah contoh file konfigurasi.

    {
      "name": "tf_serving_test",
      "model_path": "http://examplebucket.oss-cn-shanghai.aliyuncs.com/models/model.tar.gz",
      "processor": "tensorflow_cpu_1.15",
      "warm_up_data_path":"oss://path/to/warm_up_test.bin", // Jalur file permintaan untuk warm-up model.    
      "metadata": {
        "instance": 1,
        "cpu": 1,
        "memory": 4000
      }
    }

    Untuk informasi selengkapnya tentang penerapan layanan menggunakan client, lihat Penerapan Layanan: EASCMD & DSW.

    Anda juga dapat menerapkan layanan model TensorFlow melalui konsol. Untuk informasi selengkapnya, lihat Penerapan Layanan: Konsol.

  3. Setelah layanan TensorFlow diterapkan, buka halaman Elastic Algorithm Service (EAS). Temukan layanan yang ingin Anda panggil, lalu klik View Invocation Information pada kolom Service Method. Aksi ini akan menampilkan titik akhir layanan dan token untuk otentikasi.

Langkah 2: Panggil layanan

Karena layanan TensorFlow menggunakan format protobuf untuk input dan output, bukan teks biasa, Anda tidak dapat menggunakan fitur debugging online. Fitur debugging online hanya mendukung data teks biasa.

EAS menyediakan kit pengembangan perangkat lunak (SDK) untuk mengenkapsulasi data permintaan dan tanggapan layanan. SDK ini mencakup mekanisme untuk koneksi langsung dan toleransi kesalahan. Kami menyarankan Anda menggunakan SDK untuk membuat dan mengirim permintaan. Prosedurnya sebagai berikut.

  1. Kueri struktur model.

    Untuk model dalam format SavedModel standar, Anda dapat mengirim permintaan kosong ke layanan untuk mengambil informasi struktur model dalam format JSON.

    // Kirim permintaan kosong.
    $ curl 1828488879222***.cn-shanghai.pai-eas.aliyuncs.com/api/predict/mnist_saved_model_example -H 'Authorization: YTg2ZjE0ZjM4ZmE3OTc0NzYxZDMyNmYzMTJjZTQ1***'
    
    // Informasi struktur model yang dikembalikan.
    {
        "inputs": [
            {
                "name": "images",
                "shape": [
                    -1,
                    784
                ],
                "type": "DT_FLOAT"
            }
        ],
        "outputs": [
            {
                "name": "scores",
                "shape": [
                    -1,
                    10
                ],
                "type": "DT_FLOAT"
            }
        ],
        "signature_name": "predict_images"
    }              
    Catatan

    Untuk model dalam format frozen pb, Anda tidak dapat mengambil informasi struktur model.

  2. Kirim permintaan inferensi.

    Kode berikut memberikan contoh cara menggunakan Python SDK untuk mengirim permintaan model.

    #!/usr/bin/env python
    
    from eas_prediction import PredictClient
    from eas_prediction import TFRequest
    
    if __name__ == '__main__':
        client = PredictClient('http://1828488879222***.cn-shanghai.pai-eas.aliyuncs.com', 'mnist_saved_model_example')
        client.set_token('YTg2ZjE0ZjM4ZmE3OTc0NzYxZDMyNmYzMTJjZTQ1****')
        client.init()
    
        req = TFRequest('predict_images')
        req.add_feed('images', [1, 784], TFRequest.DT_FLOAT, [1] * 784)
        for x in range(0, 1000000):
            resp = client.predict(req)
            print(resp)

    Untuk informasi selengkapnya tentang pengaturan parameter dalam kode, lihat Menggunakan Python SDK.

Anda juga dapat membuat permintaan layanan sendiri. Untuk informasi selengkapnya, lihat Format permintaan.

Format permintaan

TensorFlow processor menggunakan format protobuf untuk input dan output. Saat Anda menggunakan SDK untuk mengirim permintaan, SDK akan mengenkapsulasi permintaan tersebut. Anda hanya perlu membuat permintaan menggunakan fungsi yang disediakan oleh SDK. Jika ingin membuat permintaan layanan sendiri, Anda dapat menghasilkan kode yang diperlukan berdasarkan definisi protobuf berikut. Untuk informasi selengkapnya, lihat Buat permintaan layanan TensorFlow.

syntax = "proto3";
option cc_enable_arenas = true;
option java_package = "com.aliyun.openservices.eas.predict.proto";
option java_outer_classname = "PredictProtos";
enum ArrayDataType {
  // Not a legal value for DataType. Used to indicate a DataType field
  // has not been set.
  DT_INVALID = 0;
  // Data types that all computation devices are expected to be
  // capable to support.
  DT_FLOAT = 1;
  DT_DOUBLE = 2;
  DT_INT32 = 3;
  DT_UINT8 = 4;
  DT_INT16 = 5;
  DT_INT8 = 6;
  DT_STRING = 7;
  DT_COMPLEX64 = 8;  // Single-precision complex.
  DT_INT64 = 9;
  DT_BOOL = 10;
  DT_QINT8 = 11;     // Quantized int8.
  DT_QUINT8 = 12;    // Quantized uint8.
  DT_QINT32 = 13;    // Quantized int32.
  DT_BFLOAT16 = 14;  // Float32 truncated to 16 bits.  Only for cast ops.
  DT_QINT16 = 15;    // Quantized int16.
  DT_QUINT16 = 16;   // Quantized uint16.
  DT_UINT16 = 17;
  DT_COMPLEX128 = 18;  // Double-precision complex.
  DT_HALF = 19;
  DT_RESOURCE = 20;
  DT_VARIANT = 21;  // Arbitrary C++ data types.
}
// Dimensions of an array.
message ArrayShape {
  repeated int64 dim = 1 [packed = true];
}
// Protocol buffer representing an array.
message ArrayProto {
  // Data Type.
  ArrayDataType dtype = 1;
  // Shape of the array.
  ArrayShape array_shape = 2;
  // DT_FLOAT.
  repeated float float_val = 3 [packed = true];
  // DT_DOUBLE.
  repeated double double_val = 4 [packed = true];
  // DT_INT32, DT_INT16, DT_INT8, DT_UINT8.
  repeated int32 int_val = 5 [packed = true];
  // DT_STRING.
  repeated bytes string_val = 6;
  // DT_INT64.
  repeated int64 int64_val = 7 [packed = true];
  // DT_BOOL.
  repeated bool bool_val = 8 [packed = true];
}
// PredictRequest specifies which TensorFlow model to run, along with
// how inputs are mapped to tensors and how outputs are filtered before
// returning to user.
message PredictRequest {
  // A named signature to evaluate. If unspecified, the default signature
  // will be used.
  string signature_name = 1;
  // Input tensors.
  // Names of input tensor are alias names. The mapping from aliases to real
  // input tensor names is expected to be stored as named generic signature
  // under the key "inputs" in the model export.
  // Each alias listed in a generic signature named "inputs" should be provided
  // exactly once to run the prediction.
  map<string, ArrayProto> inputs = 2;
  // Output filter.
  // Names specified are alias names. The mapping from aliases to real output
  // tensor names is expected to be stored as named generic signature under
  // the key "outputs" in the model export.
  // Only tensors specified here will be run/fetched and returned, with the
  // exception that when none is specified, all tensors specified in the
  // named signature will be run/fetched and returned.
  repeated string output_filter = 3;
}
// Response for PredictRequest on successful run.
message PredictResponse {
  // Output tensors.
  map<string, ArrayProto> outputs = 1;
}