ModelArts Service

ModelArts is a one-stop development platform for AI developers. With distributed training, automated model building, and model deployment, ModelArts helps AI developers quickly build models and efficiently manage the AI development lifecycle.

Devenv Instance

List Devenv Instances

This interface is used to query devenv instances list. Devenv.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

for instance in conn.modelartsv1.devenv_instances(de_type="Notebook"):
    print(instance)

Create Devenv Instance

This interface is used to create a devenv instance with parameters. Devenv.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

attrs = {
    "name": "notebook-d115",
    "flavor": "modelarts.vm.cpu.2u",
    "spec": {
        "storage": {
            "location": {
                "path": "/test-bucket/notebooks/",
            },
            "type": "obs",
        }
    },
    "profile_id": "Multi-Engine 1.0 (python3)-cpu",
}

devenv_instance = conn.modelartsv1.create_devenv_instance(**attrs)
print(devenv_instance)

Get Devenv Instance

This interface is used to get a devenv instance by ID or an instance of class. Devenv.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

instance_id = "notebook_id"
response = conn.modelartsv1.get_devenv_instance(instance_id)
print(response)

Find Devenv Instance

This interface is used to find a devenv instance by id or name. Devenv.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

name_or_id = "notebook-1234"
response = conn.modelartsv1.find_devenv_instance(
    name_or_id, ignore_missing=False
)
print(response)

Start Devenv Instance

This interface is used to start a devenv instance by id or an instance of class. Devenv.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

instance_id = "notebook_id"
response = conn.modelartsv1.start_devenv_instance(instance_id)
print(response)

Stop Devenv Instance

This interface is used to stop a devenv instance by id or an instance of class. Devenv.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

instance_id = "notebook_id"
response = conn.modelartsv1.stop_devenv_instance(instance_id)
print(response)

Delete Devenv Instance

This interface is used to delete a devenv instance by ID or an instance of class. Devenv.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

instance_id = "devenv_instance_id"
conn.modelartsv1.delete_devenv_instance(instance_id, ignore_missing=False)

ModelArts Service

List Services

This interface is used to query modelarts services list. Service.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

for service in conn.modelartsv1.services():
    print(service)

Create Service

This interface is used to create a modelarts service with parameters. Service.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

attrs = {
    "service_name": "mnist",
    "description": "mnist service",
    "infer_type": "real-time",
    "config": [
        {
            "model_id": "xxxmodel-idxxx",
            "weight": "70",
            "specification": "modelarts.vm.cpu.2u",
            "instance_count": 1,
            "envs": {
                "model_name": "mxnet-model-1",
                "load_epoch": "0",
            },
        },
        {
            "model_id": "xxxxxx",
            "weight": "30",
            "specification": "modelarts.vm.cpu.2u",
            "instance_count": 1,
        },
    ],
}

service = conn.modelartsv1.create_service(**attrs)
print(service)

Get Service

This interface is used to get a service by ID or an instance of class. Service.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

service_id = "fb923e36-a239-40f1-ba62-116a50f53f56"
response = conn.modelartsv1.get_service(service_id)
print(response)

Find Service

This interface is used to find a service by Id or name. Service.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

name_or_id = "test-service"
response = conn.modelartsv1.find_service(name_or_id, ignore_missing=False)
print(response)

Start Service

This interface is used to start a Service by Id or an instance of class. Service.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

name_or_id = "test-service"
service = conn.modelartsv1.find_service(name_or_id)

response = conn.modelartsv1.start_service(service)
print(response)

Stop Service

This interface is used to stop a service by Id or an instance of class. Service.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

name_or_id = "test-service"
service = conn.modelartsv1.find_service(name_or_id)

response = conn.modelartsv1.stop_service(service)
print(response)

Delete Service

This interface is used to delete a service by Id or an instance of class. Service.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

name_or_id = "test-service"
service = conn.modelartsv1.find_service(name_or_id, ignore_missing=False)

conn.modelartsv1.delete_service(service)

ModelArts Model

List Models

This interface is used to query models list. Model.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

for model in conn.modelartsv1.models():
    print(model)

Create Model

This interface is used to create a model with parameters. Model.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

attrs = {
    "model_name": "mnist",
    "model_version": "1.0.0",
    "source_location": "https://models.obs.xxxx.com/mnist",
    "source_job_id": "55",
    "source_job_version": "V100",
    "model_type": "TensorFlow",
    "runtime": "python2.7",
    "description": "mnist model",
    "execution_code": "https://testmodel.obs.xxxx.com/customize_service.py",
    "input_params": [
        {
            "url": "/v1/xxx/image",
            "protocol": "http",
            "method": "post",
            "param_name": "image_url",
            "param_type": "string",
            "min": 0,
            "max": 9,
            "param_desc": "http://test/test.jpeg",
        }
    ],
    "output_params": [
        {
            "url": "/v1/xxx/image",
            "protocol": "http",
            "method": "post",
            "param_name": "face_location",
            "param_type": "box",
            "param_desc": "face_location param value description",
        }
    ],
    "dependencies": [
        {
            "installer": "pip",
            "packages": [
                {
                    "package_name": "numpy",
                    "package_version": "1.5.0",
                    "restraint": "ATLEAST",
                }
            ],
        }
    ],
    "model_algorithm": "object_detection",
    "model_metrics": '{"f1":0.52381,"recall":0.666667,\
        "precision":0.466667,"accuracy":0.625}',
    "apis": [
        {
            "url": "/v1/xxx/image",
            "protocol": "http",
            "method": "post",
            "input_params": {
                "type": "object",
                "properties": {"image_url": {"type": "string"}},
            },
            "output_params": {
                "type": "object",
                "properties": {"face_location": {"type": "box"}},
            },
        }
    ],
}

model = conn.modelartsv1.create_model(**attrs)
print(model)

Get Model

This interface is used to get a model by ID or an instance of class. Model.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

model_id = "model_id"
response = conn.modelartsv1.get_model(model_id)
print(response)

Find Model

This interface is used to find a model by Id or name. Model.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

name_or_id = "mnist-model-1234"
response = conn.modelartsv1.find_model(name_or_id, ignore_missing=False)
print(response)

Delete Model

This interface is used to delete a model by Id or an instance of class. Model.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

name_or_id = "mnist-model-1234"
model = conn.modelartsv1.find_model(name_or_id, ignore_missing=False)

conn.modelartsv1.delete_model(model)

ModelArts Training Job

List Training Jobs

This interface is used to query training jobs list. TrainingJob.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

for training_job in conn.modelartsv1.training_jobs():
    print(training_job)

Create Training Job

This interface is used to create a training job with parameters. TrainingJob.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

attrs = {
    "job_name": "TestModelArtsJob",
    "job_desc": "This is a ModelArts job",
    "workspace_id": "af261af2218841ec960b01ab3cf1a5fa",
    "config": {
        "worker_server_num": 1,
        "app_url": "/usr/app/",
        "boot_file_url": "/usr/app/boot.py",
        "parameter": [
            {
                "label": "learning_rate",
                "value": "0.01",
            },
            {
                "label": "batch_size",
                "value": "32",
            },
        ],
        "dataset_id": "38277e62-9e59-48f4-8d89-c8cf41622c24",
        "dataset_version_id": "2ff0d6ba-c480-45ae-be41-09a8369bfc90",
        "spec_id": 1,
        "engine_id": 1,
        "train_url": "/usr/train/",
        "log_url": "/usr/log/",
    },
}

trainingjob = conn.modelartsv1.create_training_job(**attrs)
print(trainingjob)

Delete Training Job

This interface is used to delete a training job by Id or an instance of class. TrainingJob.

import openstack

openstack.enable_logging(True)
conn = openstack.connect(cloud="otc")

job_id = 123
response = conn.modelartsv1.delete_training_job(job_id)
print(response)