All Products
Search
Document Center

Platform For AI:PyTorch processor

Last Updated:Aug 31, 2026

EAS provides a built-in PyTorch processor that deploys models in the standard PyTorch TorchScript format as online services. This topic describes how to deploy and call a PyTorch model service.

PyTorch processor versions

PyTorch supports multiple versions, including GPU and CPU versions. The following table lists the processor name for each version.

Processor name PyTorch version Supports GPU
pytorch_cpu_1.6 Pytorch 1.6 No
pytorch_cpu_1.7 Pytorch 1.7 No
pytorch_cpu_1.9 Pytorch 1.9 No
pytorch_cpu_1.10 Pytorch 1.10 No
pytorch_gpu_1.6 Pytorch 1.6 Yes
pytorch_gpu_1.7 Pytorch 1.7 Yes
pytorch_gpu_1.9 Pytorch 1.9 Yes
pytorch_gpu_1.10 Pytorch 1.10 Yes

Step 1: Deploy a service

When you deploy a PyTorch model service by using the eascmd client, set the processor configuration parameter to one of the preceding supported PyTorch processor names. The following example shows the service configuration file.

{
  "name": "pytorch_resnet_example",
  "model_path": "http://examplebucket.oss-cn-shanghai.aliyuncs.com/models/resnet18.pt",
  "processor": "pytorch_cpu_1.6",
  "metadata": {
    "cpu": 1,
    "instance": 1,
    "memory": 1000
  }
}

For information about how to deploy a service by using the client tool, see Service deployment: EASCMD & DSW.

You can also deploy a PyTorch model service in the console. For more information, see Service deployment: Console.

Step 2: Call the service

PyTorch services use ProtoBuf, not plain text, for input and output. Therefore, you cannot use the online debugging feature in the console.

EAS provides software development kits (SDKs) in multiple versions. The SDKs encapsulate request and response data and provide built-in direct connection and fault tolerance. We recommend that you use an SDK to build and send requests. The following example shows an inference request.

#!/usr/bin/env python

from eas_prediction import PredictClient
from eas_prediction import TorchRequest

if __name__ == '__main__':
    client = PredictClient('http://182848887922****.cn-shanghai.pai-eas.aliyuncs.com', 'pytorch_gpu_wl')
    client.init()

    req = TorchRequest()
    req.add_feed(0, [1, 3, 224, 224], TorchRequest.DT_FLOAT, [1] * 150528)
    # req.add_fetch(0)
    for x in range(0, 10):
        resp = client.predict(req)
        print(resp.get_tensor_shape(0))

For information about the parameter settings in the code and how to call the service, see Use the Python SDK.

You can also construct service requests on your own. For more information, see PyTorch processor.

Request format

The PyTorch processor uses the ProtoBuf format for input and output. When you send requests by using an SDK, the SDK encapsulates the requests, so you only need to build requests by using the functions that the SDK provides. To construct service requests on your own, generate the related code based on the following .proto definition. For more information, see Construct a request for a TensorFlow service.

syntax = "proto3";

package pytorch.eas;
option cc_enable_arenas = true;

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];

}


message PredictRequest {

  // Input tensors.
  repeated ArrayProto inputs = 1;

  // Output filter.
  repeated int32 output_filter = 2;
}

// Response for PredictRequest on successful run.
message PredictResponse {
  // Output tensors.
  repeated ArrayProto outputs = 1;
}