Skip to Content

Train Execution of ML Model (Postman)

test
0 %
Train Execution of ML Model (Postman)
Details

Train Execution of ML Model (Postman)

Requires Customer/Partner License
October 11, 2021
Created by
October 10, 2021
Train execution a ML model in SAP AI Core with help of Postman client.

You will learn

  • How to create execution configuration for SAP AI Core
  • How to observe execution on SAP AI Core
QR code


Step 1: API to list available scenarios

Scenarios refers to the use case. It is created by an identifier within the workflows (YAML files, see screenshots below) that you synced with GitHub in previous tutorial. For all workflows of same use case, write the same scenario id.

scenario definition inside worflows

COLLECTIONS > GET List scenario

Endpoint

GET
{{apiurl}}/v2/lm/scenarios

HEADER

KEY VALUE
AI-Resource-Group tutorial

SEND

Response

list scenarios

In the RESPONSE, you should see id : text-clf-tutorial

Log on to answer question
Step 2: API to register train dataset as artifact

Every data entity (dataset, model weights) in SAP AI Core is considered artifact.

Previously you uploaded your data to AWS S3 and connected S3 to SAP AI Core.

Now you will specifically point to that dataset in S3.

COLLECTIONS > POST Create artifact

Endpoint

POST
{{apiurl}}/v2/lm/artifacts

Header

KEY VALUE
AI-Resource-Group tutorial

Body

{
  "name": "tutorial-train-data",
  "kind": "dataset",
  "url": "ai://default/data",
  "description": "Text Classification Dataset",
  "scenarioId": "text-clf-tutorial"
}

IMPORTANT: DO NOT end url in the Body with forward slash.

SEND

artifact create

RESPONSE

{
    "id": "aefde425-231f-44a0-9abf-9228fc1b24c9",
    "message": "Artifact acknowledged",
    "url": "ai://default/data/"
}

Log on to answer question
Step 3: Create training configuration

The training configuration specifies
- the input as artifactId
- the workflows to use with scenarioId and executableId (name mentioned in the training workflow).

executable id in workflow
Key Where to get value from
artifactId from RESPONSE of API call GET List artifacts

Make the API call.

COLLECTIONS > POST Create execution configuration

Endpoint

POST
{{apiurl}}/v2/lm/executions

HEADER

KEY VALUE
AI-Resource-Group tutorial

BODY

(change the highlighted line)

{
  "name": "dev-tutorial-training-configuration",
  "executableId": "text-clf-train-tutorial",
  "scenarioId": "text-clf-tutorial",
  "versionId": "0.0.1",
  "parameterBindings": [],
  "inputArtifactBindings": [
      {
      "key": "text-data",
      "artifactId": "aefde425-231f-44a0-9abf-9228fc1b24c9"
    }
  ]
}

Response

{
    'id': '1a10f5fd-27ed-486a-8f6e-4eed061b65d1',
    'message': 'Configuration created'
}    
 response of configuration creation

IMPORTANT: This id from response needs to be added in the Postman Environment Variable.

VARIABLE CURRENT VALUE (example value)
configurationid 1a10f5fd-27ed-486a-8f6e-4eed061b65d1
set configurationId to env
Log on to answer question
Step 4: Start training execution

After creating configuration for the execution, it is very simple to create an execution.

COLLECTIONS > POST Start execution

Endpoint

POST
{{apiurl}}/v2/lm/configurations/{{configurationid}}/executions

Header

Key Value
AI-Resource-Group tutorial
start execution png

Response

{'id': ec4e592e024c22e3',
 'message': 'Execution scheduled',
 'status': <Status.UNKNOWN: 'UNKNOWN'>}

(If the response results in 404, read the Deprecation Notice below )

response of execution

IMPORTANT: This id from response needs to be added in the Postman Environment Variable.

VARIABLE CURRENT VALUE (example value)
executionid ec4e592e024c22e3
set configurationId to env

Deprecation Notice

If the previous call to create training execution does not work try with following endpoint, header, body as follows.

ENDPOINT

POST
{{apiurl}}/v2/lm/configurations

HEADER

KEY VALUE
AI-Resource-Group tutorial

BODY

Change configurationId below

{
  "configurationId": "1a10f5fd-27ed-486a-8f6e-4eed061b65d1"
}
Log on to answer question
Step 5: API to Observe Training Status

Since the training of the model takes some time, periodically check on the status.

Let’s poll the status of the training and wait until it goes into one of the state - COMPLETED or DEAD.

COLLECTIONS > GET Get execution

HEADER

Key Value
AI-Resource-Group tutorial
training status

IMPORTANT: Training the model takes time. Retry sending the request in intervals of 1 min.

NOTE In the same response you will get outputArtifacts > id deployment of the serving model. These artifacts represents the data (model weights).

training status
Which kind of configuration is required for training with SAP AI Core ?
×
Step 6: Store training metrics

SAP AI Core, maintains a persistent data related to each execution (model training). This data is custom decided and can be anything.

COLLECTIONS > metrics > PATCH > Update/create metric resources (add/modify value of existing ones) against some execution

Endpoint

PATCH
{{apiurl}}/v2/lm/metrics

Header

KEY VALUE
AI-Resource-Group tutorial
Content-Type application/merge-patch+json

Body

(example body, manually generated)

{
  "executionId": "ec4e592e024c22e3",
  "metrics": [
    {
      "name": "Error Rate",
      "value": 0.98,
      "timestamp": "2021-06-28T07:50:24.589Z",
      "step": 2,
      "labels": [
        {
          "name": "group",
          "value": "tree-82"
        },
        {
            "name": "metrics.ai.sap.com/Artifact.name",
            "value": "text-model-tutorial"
        }
      ]
    }
  ],
  "tags": [
    {
      "name": "Artifact Group",
      "value": "RFC-1"
    }
  ],
  "customInfo": [
    {
      "name": "Confusion Matrix",
      "value": "[{'Predicted': 'False',  'Actual': 'False','value': 34},{'Predicted': 'False','Actual': 'True',  'value': 124}, {'Predicted': 'True','Actual': 'False','value': 165},{  'Predicted': 'True','Actual': 'True','value': 36}]"
    }
  ]
}

SEND

Response

204 :
(No Response)

reponse of patch metrics
Log on to answer question
Step 7: Retrive training metrics
  1. Using SAP BTP Cockpit.

    SAP BTP metrics
  2. Using Postman API Call.

Endpoint

GET
{{apiurl}}/v2/lm/metrics?executionIds=ec4e592e024c22e3

Params

Key Value
executionId ec4e592e024c22e3

Header

KEY VALUE
AI-Resource-Group tutorial

SEND

Response

response of get metrics
Log on to answer question

Next Steps

Back to top