Deploy a service by using a JSON configuration file
In EAS, you can define and deploy an online service by using a configuration file in JSON format.
View the JSON configuration of a deployed service
If you have already deployed a service in the console (including a service deployed with one click from Model Gallery), you do not need to write a JSON file from scratch. A service deployed from Model Gallery is essentially also an EAS service and uses the same JSON configuration structure as a manual JSON deployment. You can directly view and copy the complete JSON configuration of the deployed service and use it as the starting point for subsequent custom deployments.
To view the JSON configuration of a deployed service, follow these steps:
-
Go to the EAS console and open the Inference Service tab.
-
Click the service name of the target service to go to the service details page.
-
Click the Service Configuration tab. The page displays the complete current JSON configuration of the service, which you can view and copy directly.
You can adjust the copied JSON configuration based on Appendix: JSON parameter descriptions in this topic and then use it in the JSON deployment procedure described in Getting Started.
The parameters used to run the service, such as the runtime image, the entry command (command), and the instance type (machine type), are all included in this JSON configuration and can be viewed directly on the Service Configuration tab. The tab displays the complete configuration without additional hidden fields, so you do not need to obtain them separately through other means. You can switch to a custom deployment based on the exported JSON configuration to manage the service in a fine-grained manner.
Getting Started
1. Prepare a JSON configuration file
The key to deploying a service is to create a JSON file that contains all required configurations. If you are a first-time user, the recommended approach is to configure the parameters through Custom Model Deployment > Custom Deployment. The system automatically generates the corresponding JSON content, which you can then modify and extend.
The following example shows the service.json file. For more parameter descriptions, see Appendix: JSON parameter descriptions.
{
"metadata": {
"name": "demo",
"instance": 1,
"workspace_id": "your-workspace-id"
},
"cloud": {
"computing": {
"instances": [
{
"type": "ecs.c7a.large"
}
]
}
},
"containers": [
{
"image": "eas-registry-vpc.cn-hangzhou.cr.aliyuncs.com/pai-eas/python-inference:py39-ubuntu2004",
"script": "python app.py",
"port": 8000
}
]
}
2. Deploy a service by using a JSON file
Log on to the PAI console. Select a region on the top of the page. Then, select the desired workspace and click Enter Elastic Algorithm Service (EAS).
-
On the Inference Service tab, click Deploy Service. Then, in the Custom Model Deployment section, select JSON Deployment.
-
Enter the prepared JSON file and click Deploy. Wait for a period of time. When the service status changes to Running, the service is deployed.
Appendix: JSON parameter descriptions
|
Parameter |
Required |
Description |
|
metadata |
Yes |
The meta information of the service. For more information, see metadata parameter descriptions. |
|
cloud |
No |
The computing resource and virtual private cloud (VPC) configurations. For more information, see cloud parameter descriptions. |
|
containers |
No |
The runtime image configurations. For more information, see containers parameter descriptions. |
|
dockerAuth |
No |
You must configure this parameter when you access a private image repository that requires authentication. The value is the image repository's |
|
networking |
No |
The invocation configurations of the service. For more information, see networking parameter descriptions. |
|
storage |
No |
Used to mount data such as OSS or NAS into the container. For detailed configuration instructions, see Storage mounts. |
|
token |
No |
The authentication token used to access the service. If you do not specify this parameter, the system automatically generates one. |
|
aimaster |
No |
Enables Compute monitoring and fault tolerance for multi-node distributed inference services. |
|
model_path |
Yes |
This parameter is required when you deploy a service by using a processor. model_path and processor_path specify the input data source addresses of the model and the processor respectively. Both parameters support addresses in the following formats:
|
|
oss_endpoint |
No |
The endpoint of OSS, for example, oss-cn-beijing.aliyuncs.com. For other valid values, see Regions and endpoints. Note
By default, you do not need to specify this parameter. The system uses the internal OSS endpoint of the current region to download the model file or the processor file. You must specify this parameter when you access OSS across regions. For example, if you deploy a service in the Hangzhou region and model_path is set to an OSS address in the Beijing region, you must use this parameter to specify the OSS address for public network access in the Beijing region. |
|
model_entry |
No |
The entry file of the model, which can contain any file. If you do not specify this parameter, the file name in model_path is used. The path of the main file is passed to the initialize() function in the processor. |
|
model_config |
No |
The configuration of the model, which supports any text. The value of this parameter is passed as the second argument of the initialize() function in the processor. |
|
processor |
No |
|
|
processor_path |
No |
The path of the processor package. For more information, see the description of the model_path parameter. |
|
processor_entry |
No |
The main file of the processor, for example, libprocessor.so or app.py. This file contains the implementations of the You must specify this parameter when processor_type is set to cpp or python. |
|
processor_mainclass |
No |
The main file of the processor, which is the mainclass in the JAR package. For example, com.aliyun.TestProcessor. You must specify this parameter when processor_type is set to java. |
|
processor_type |
No |
processor: the language in which the processor is implemented. Valid values:
|
|
warm_up_data_path |
No |
The path of the request file used for model warm-up. For more information, see Warm up model services. |
|
runtime.enable_crash_block |
No |
Specifies whether a service instance automatically restarts after it crashes because of an exception in the processor code. Valid values:
|
|
autoscaler |
No |
The horizontal auto-scaling configuration of the model service. For more information about the field descriptions, see autoscaler parameter descriptions. |
|
labels |
No |
Configures labels for the EAS service. The format is |
|
unit.size |
No |
The number of machines on which a single instance is deployed in a distributed inference configuration. Default value: 2. |
|
sinker |
No |
Persistently stores the records of all requests and responses of the service in the big data service MaxCompute or in Simple Log Service (SLS). For more information, see sinker parameter descriptions. |
|
confidential |
No |
By configuring the system trust management service, you can ensure that information such as data, models, and code is securely encrypted during service deployment and invocation, so that a secure and verifiable inference service is implemented. The format is as follows: Note
The secure encryption environment mainly applies to the storage files that you mount. Mount the storage files before you enable this feature.
The parameter settings are described as follows. For a more detailed description, see Confidential inference service.
|
metadata parameter descriptions
Advanced parameters
cloud parameter descriptions
|
Parameter |
Required |
Description |
|
|
computing |
instances |
No |
When you deploy a service by using a public resource group, you must set this parameter, which indicates the list of resource specifications to use. When bidding for an instance type fails or the instance type is out of stock, the next instance type in the configured order is used to create the service.
|
|
disable_spot_protection_period |
No |
This parameter must be set when preemptible instances are used. Valid values:
|
|
|
networking |
vpc_id |
No |
Virtual Private Cloud (VPC) |
|
vswitch_id |
No |
The vSwitch ID. Avoid selecting a vSwitch that overlaps with the PAI control CIDR blocks (10.224.0.0/16, 10.240.0.0/12, and 11.0.0.0/8), which may cause mounting exceptions or task startup failures. |
|
|
security_group_id |
No |
Security group |
|
|
destination_cidrs |
No |
If you are aware of the CIDR block conflict risk but still must use a vSwitch that overlaps with the preceding PAI control CIDR blocks, explicitly set this field to your vSwitch CIDR block (that is, the CIDR of the vSwitch).
Replace |
|
Example:
{
"cloud": {
"computing": {
"instances": [
{
"type": "ecs.c8i.2xlarge",
"spot_price_limit": 1
},
{
"type": "ecs.c8i.xlarge",
"capacity": "20%"
}
],
"disable_spot_protection_period": false
},
"networking": {
"vpc_id": "vpc-bp1oll7xawovg9*****",
"vswitch_id": "vsw-bp1jjgkw51nsca1e****",
"security_group_id": "sg-bp1ej061cnyfn0b*****"
}
}
}
containers parameter descriptions
When you deploy a service by using a custom runtime image, for more information, see Deploy a custom image.
|
Parameter |
Required |
Description |
|
|
image |
Yes |
Required when you deploy by using a runtime image. The address of the runtime image used to deploy the model service. |
|
|
env |
name |
No |
The name of the environment variable when the runtime image runs. |
|
value |
No |
The value of the environment variable when the runtime image runs. |
|
|
command |
One of the two is required |
The entry command of the runtime image. Only a single command is supported; complex scripts such as cd xxx && python app.py are not supported. Specify such a form by using the script parameter below. The command field is suitable for scenarios in which the runtime image does not contain the /bin/sh command. |
|
|
script |
The script executed at the entry of the runtime image. A relatively complex script form can be specified, with multiple lines separated by \n or semicolons. |
||
|
port |
No |
The container port. Important
|
|
|
prepare |
pythonRequirements |
No |
The list of python requirements to install before the instance starts. The runtime image must contain the python and pip commands in the system path. The value is in list format, for example:
|
|
pythonRequirementsPath |
No |
The address of the python requirements.txt file to install before the instance starts. The runtime image must contain the Python and pip commands in the system path. The requirements.txt file can be packaged directly into the runtime image, or mounted into the service instance from external storage, for example:
|
|
networking parameter descriptions
|
Parameter |
Required |
Description |
|
gateway |
No |
The dedicated gateway configured for the EAS service. |
|
gateway_policy |
No |
Rate limiting configuration example:
|
autoscaler parameter descriptions
When you deploy a service by using JSON, you can enable horizontal auto-scaling in autoscaler. For metric selection and threshold configuration, see Horizontal auto scaling.
|
Parameter |
Required |
Description |
|
|
min |
No |
The minimum number of replicas. When the value is |
|
|
max |
No |
The maximum number of replicas. The maximum value is 1000. After the upper limit is reached, scale-out does not continue even if the load keeps increasing. |
|
|
scaleStrategies |
metricName |
Yes |
The metric name. Valid values:
|
|
threshold |
Yes |
The threshold that triggers scaling. The meaning of the value is determined by metricName. Scale-out is triggered after the metric exceeds the threshold and remains above it for longer than the observation window. |
|
|
behavior |
scaleUp.stabilizationWindowSeconds |
No |
The observation window for scale-out decisions. Unit: seconds. Default value: 0. If the metric falls back below the threshold within this window, this scale-out is canceled. This parameter corresponds to Scale-out Starts in in the console. |
|
scaleDown.stabilizationWindowSeconds |
No |
The observation window for scale-in decisions. Unit: seconds. Default value: 300. Scale-in is performed only after the metric remains below the threshold throughout this window. This parameter corresponds to Scale-in Starts in in the console. |
|
The following example sets the QPS threshold per replica to 1.25 and retains the default scaling observation windows:
"autoscaler": {
"min": 1,
"max": 5,
"behavior": {
"scaleUp": {
"stabilizationWindowSeconds": 0
},
"scaleDown": {
"stabilizationWindowSeconds": 300
}
},
"scaleStrategies": [
{
"metricName": "qps1k",
"threshold": 1250
}
]
}
The thresholds in the example are used only to illustrate the format. When you configure multiple metrics, the system separately calculates the target number of replicas required by each metric and takes the maximum. If you have not evaluated the combined behavior, use only one metric.
sinker parameter descriptions
|
Parameter |
Required |
Description |
|
|
type |
No |
The following two storage types are supported:
|
|
|
config |
maxcompute.project |
No |
The name of the MaxCompute project. |
|
maxcompute.table |
No |
The MaxCompute data table. |
|
|
sls.project |
No |
The name of the SLS project. |
|
|
sls.logstore |
No |
The Logstore of SLS. |
|
The configuration example is as follows:
Store to MaxCompute
"sinker": {
"type": "maxcompute",
"config": {
"maxcompute": {
"project": "cl****",
"table": "te****"
}
}
}
Store to Simple Log Service (SLS)
"sinker": {
"type": "sls",
"config": {
"sls": {
"project": "k8s-log-****",
"logstore": "d****"
}
}
}
Appendix: JSON configuration examples
The following is an example of how to configure the preceding parameters in a JSON file:
{
"token": "****M5Mjk0NDZhM2EwYzUzOGE0OGMx****",
"processor": "tensorflow_cpu_1.12",
"model_path": "oss://examplebucket/exampledir/",
"oss_endpoint": "oss-cn-beijing.aliyuncs.com",
"model_entry": "",
"model_config": "",
"processor_path": "",
"processor_entry": "",
"processor_mainclass": "",
"processor_type": "",
"warm_up_data_path": "",
"runtime": {
"enable_crash_block": false
},
"unit": {
"size": 2
},
"sinker": {
"type": "maxcompute",
"config": {
"maxcompute": {
"project": "cl****",
"table": "te****"
}
}
},
"cloud": {
"computing": {
"instances": [
{
"capacity": 800,
"type": "dedicated_resource"
},
{
"capacity": 200,
"type": "ecs.c7.4xlarge",
"spot_price_limit": 3.6
}
],
"disable_spot_protection_period": true
},
"networking": {
"vpc_id": "vpc-bp1oll7xawovg9t8****",
"vswitch_id": "vsw-bp1jjgkw51nsca1e****",
"security_group_id": "sg-bp1ej061cnyfn0b****"
}
},
"autoscaler": {
"min": 2,
"max": 5,
"scaleStrategies": [
{
"metricName": "qps",
"threshold": 10
}
]
},
"storage": [
{
"mount_path": "/data_oss",
"oss": {
"endpoint": "oss-cn-shanghai-internal.aliyuncs.com",
"path": "oss://bucket/path/"
}
}
],
"confidential": {
"trustee_endpoint": "xx",
"decryption_key": "xx"
},
"metadata": {
"name": "test_eascmd",
"resource": "eas-r-9lkbl2jvdm0puv****",
"instance": 1,
"workspace_id": "1405**",
"gpu": 0,
"cpu": 1,
"memory": 2000,
"gpu_memory": 10,
"gpu_core_percentage": 10,
"qos": "",
"cuda": "11.2",
"enable_grpc": false,
"enable_webservice": false,
"rdma": 1,
"rpc": {
"batching": false,
"keepalive": 5000,
"io_threads": 4,
"max_batch_size": 16,
"max_batch_timeout": 50,
"max_queue_size": 64,
"worker_threads": 5,
"rate_limit": 0,
"enable_sigterm": false
},
"rolling_strategy": {
"max_surge": 1,
"max_unavailable": 1
},
"eas.termination_grace_period": 30,
"scheduling": {
"spread": {
"policy": "host"
}
},
"resource_rebalancing": false,
"shm_size": 100
},
"features": {
"eas.aliyun.com/extra-ephemeral-storage": "100Gi",
"eas.aliyun.com/gpu-driver-version": "tesla=550.127.08"
},
"networking": {
"gateway": "gw-m2vkzbpixm7mo****"
},
"containers": [
{
"image": "registry-vpc.cn-shanghai.aliyuncs.com/xxx/yyy:zzz",
"prepare": {
"pythonRequirements": [
"numpy==1.16.4",
"absl-py==0.11.0"
]
},
"command": "python app.py",
"port": 8000
}
],
"dockerAuth": "dGVzdGNhbzoxM*******"
}