Help Center/ ModelArts/ SDK Reference/ Service Management/ Updating Service Configurations
Updated on 2024-03-21 GMT+08:00

Updating Service Configurations

You can use the API to update the configurations of a service object.

Sample Code

In ModelArts notebook, you do not need to enter authentication parameters for session authentication. For details about session authentication of other development environments, see Session Authentication.

  • Method 1: Update the configurations of a service based on the service object created in Deploying a Real-Time Service.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    from modelarts.session import Session
    from modelarts.model import Predictor
    from modelarts.config.model_config import ServiceConfig
    
    session = Session()
    predictor_instance = Predictor(session, service_id="your_service_id")
    configs = [ServiceConfig(weight="100", instance_count=1, specification="modelarts.vm.cpu.2u",model_id="your_model_id")]
    service_config = predictor_instance.update_service_config(description="description",
                                                                  status="running",
                                                                  configs=configs) 
    
  • Method 2: Update the configurations of a service based on the service object returned in Obtaining Service Objects.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    from modelarts.session import Session
    from modelarts.model import Predictor
    from modelarts.config.model_config import ServiceConfig
    
    session = Session()
    predictor_object_list = Predictor.get_service_object_list(session)
    predictor_instance = predictor_object_list[0]                  
    configs = [ServiceConfig(weight="100", instance_count=1, specification="modelarts.vm.cpu.2u",model_id="your_model_id")]
    predictor_config = predictor_instance.update_service_config(description="description",
                                                                    status="running",
                                                                    configs=configs) 
    

Parameters

Table 1 Parameters for deploying predictor

Parameter

Mandatory

Type

Description

description

No

String

Service description, which contains a maximum of 100 characters. If this parameter is not set, the service description is not updated.

status

No

String

Service status. The value can be running or stopped. If this parameter is not set, the service status is not changed. status and configs cannot be modified at the same time. If both parameters exist, modify only the status parameter.

configs

No

predictor configs and transformer configs

Service configurations. If this parameter is not set, the service is not updated. For details about how to generate configs, see Deploying a Real-Time Service.

The restrictions on updating service configurations are as follows:

  • The specified status cannot be the same as the current service status.
  • If the service status is deploying, stopping, or deleting, status cannot be set to running or configs is not allowed to configure.
  • If the service status is waiting, status cannot be set to running.
  • If the service status is concerning, status cannot be set to running.
Table 2 configs parameters of predictor

Parameter

Mandatory

Type

Description

model_id

Yes

String

Model ID. You can obtain the value by calling the API described in Obtaining Models or from the ModelArts management console.

weight

Yes

Integer

Weight of traffic allocated to a model. This parameter is mandatory only when infer_type is set to real-time. The sum of multiple weights must be equal to 100. If multiple model versions are configured in a real-time service and different traffic weights are set, ModelArts continuously accesses the prediction API of the service and forwards prediction requests to the model instances of the corresponding versions based on the weights.

specification

Yes

String

Resource flavor. Currently, modelarts.vm.cpu.2u, modelarts.vm.gpu.p4 (you must apply for it), and modelarts.vm.ai1.a310 (you must apply for it) are available. To use a flavor that requires permission, submit a service ticket on HUAWEI CLOUD and ModelArts O&M engineers will grant you the permission.

instance_count

Yes

Integer

Number of instances deployed in a model. The maximum number of instances is 5. To use more instances, submit a service ticket.

envs

No

Map<String, String>

(Optional) Environment variable key-value pair required for running a model. By default, this parameter is left blank.

Table 3 configs parameters of transformer

Parameter

Mandatory

Type

Description

model_id

Yes

String

Model ID. You can obtain the value by calling the API described in Obtaining Models or from the ModelArts management console.

specification

Yes

String

Resource flavor. Currently, modelarts.vm.cpu.2u and modelarts.vm.gpu.p4 are available.

instance_count

Yes

Integer

Number of instances deployed in a model. The maximum number of instances is 5. To use more instances, submit a service ticket.

envs

No

Map<String, String>

(Optional) Environment variable key-value pair required for running a model. By default, this parameter is left blank.

src_path

Yes

String

OBS path of the input data of a batch job

dest_path

Yes

String

OBS path of the output data of a batch job

req_uri

Yes

String

Inference API called in batch tasks. You must select an API URL from the config.json file of the model for inference.

mapping_type

Yes

String

Mapping type of the input data. The value can be file or csv.

  • If you select file, each inference request corresponds to a file in the input data path. When this mode is used, req_uri of a model can have only one input parameter and the type of this parameter is file.
  • If you select csv, each inference request corresponds to a row of data in the CSV file. When this mode is used, the files in the input data path can only be in CSV format and mapping_rule needs to be configured to map the index of each parameter in the inference request body to the CSV file.

mapping_rule

No

Map

Mapping between input parameters and CSV data. This parameter is mandatory only when mapping_type is set to csv. The mapping rule is similar to the definition of the input parameters in the config.json file. You only need to configure the index parameters under each parameter of the string, number, integer, or boolean type, and the value of this parameter to the values of the index parameters in the CSV file to send an inference request. Use commas (,) to separate multiple pieces of CSV data. The values of the index parameters start from 0. If the value of the index parameter is -1, ignore this parameter.

Table 4 update_service_config response parameters

Parameter

Mandatory

Type

Description

error_code

Yes

String

Error code when the API call fails.

This parameter is not included when the API call succeeds.

error_msg

Yes

String

Error message when the API call fails.

This parameter is not included when the API call succeeds.