AI开发平台MODELARTS-更新服务配置:示例代码

时间:2024-11-08 17:12:25

示例代码

在ModelArts notebook平台,Session鉴权无需输入鉴权参数;其它平台的Session鉴权请参考Session鉴权

  • 方式1:根据部署在线服务生成的服务对象进行更新服务配置
     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) 
    
  • 方式2:根据查询服务对象列表返回的服务对象进行更新服务配置
     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) 
    
support.huaweicloud.com/sdkreference-modelarts/modelarts_04_0207.html