Skip to Content

Create Training and Serving Docker Images (Postman)

test
0 %
Create Training and Serving Docker Images (Postman)
Details

Create Training and Serving Docker Images (Postman)

Requires Customer/Partner License
October 11, 2021
Created by
October 10, 2021
Learn to build Docker images and orchestrate their execution with for SAP AI Core.

You will learn

  • Build Docker images and host on Docker Repository
  • Write ML Pipeline via Workflows.
QR code


Step 1: Create ML Code and Dockerfile

Docker will be used to store python code in form of containers (portable environments).

Create following files (download link below) as-it-is. Resulting directory structure may look like following:

folder structure

File Links

Training Scripts

train/ Download Link
Dockerfile Download
evaluate_scikit.py Download
requirements.txt Download
train_scikit.py Download

Inference/ Serving Scripts

infer/ Download Link
Dockerfile Download
infer_scikit.py Download
requirements.txt Download
Log on to answer question
Step 2: Build Docker image
  1. Execute following line on terminal, to connect to you Docker account.
    Edit the highlighted line

    docker login docker.io -u <your-dockerhub-username>
    

  2. Type your password (nothing will appear on screen: just type your password and press enter)

    docker login
  3. Navigate to place where you have stored the code files.

    directory
  4. Navigate inside train

    cd train
    
  5. Build Docker image (change the highlighted line).

    docker build -t <your-dockerhub-username>/text-clf-train:0.0.1 .
    
    docker build train

Similarly navigate inside infer folder and execute the following command to build docker image for serving the model.:

docker build -t <your-dockerhub-username>/text-clf-serve:0.0.1 .
docker build infer
Log on to answer question
Step 3: Upload Docker image to Docker repository

Push your local docker image to Docker Hub cloud.

Execute the following on you terminal. (change the highlighted line)

docker push docker.io/<your-dockerhub-username>/text-clf-train:0.0.1

(sample image if previously uploaded)

docker push

Similarly push your serving docker image. (change the highlighted line).

docker push docker.io/<your-dockerhub-username>/text-clf-serve:0.0.1

Visit https://hub.docker.com, inside the repository text-clf-serve you will see you uploads.

docker uploads
Log on to answer question
Step 4: Create Workflow Files

Workflows will instruct SAP AI Core
- how to execute the docker images
- what inputs to provide(datasets)
- what outputs it gives.

(Further read ArgoWorkflows )

Create a folder workflows inside to your cloned local GitHub folder.

Create the following file (download links below) as depicted in the image

Download Files

File Link
training_workflow_tutorial.yaml Download
serving_workflow_tutorial.yaml Download
workflow GitHub local
Log on to answer question
Step 5: Choose computing hardware resources

Inside YAML files from previous step find the line

  ...
  ai.sap.com/resourcePlan: starter
  ...

The starter is the computing resource plan is used in this tutorial. Below is the list of other available plans offered by SAP AI Core.

resourcePlan ID GPUs CPU cores Memory (Gb)
Train-L 1 V100 GPU 5 47
Infer-S 1 T4 GPU 3 10
Infer-M 1 T4 GPU 7 25
Infer-L 1 T4 GPU 15 55
Starter 1 2.5
Basic 3 10
Basic.8x 31 115
Log on to answer question
Step 6: Add Docker details to workflows

Edit the following lines (highlighted) in each workflow file (YAML).

  • training_workflow_tutorial.yaml
    ...
    spec:
    	...
    	container:
    	image: "<your_docker_repo_url>/<your_username_in_docker_repo>/text-clf-train:0.0.1"
    	...
    

train docker image yaml

  • serving_workflow_tutorial.yaml
    ...
    spec:
    	...
    	template:
    		...
    		spec:
    			predictor
    				...
    				containers:
    					image: "<your_docker_repo_url>/<your_username_in_docker_repo>/text-clf-serve:0.0.1"
    ...
    

train docker image yaml

Log on to answer question
Step 7: Upload workflows to GitHub repository
  1. Copy the workflows folder (from previous step) to your cloned local GitHub folder. Ensure your files are placed as per image below

    workflow GitHub local
  2. Open GitHub Desktop.

  3. Type the commit message workflows added. And click on Commit to main button.

    GitHub commit
  4. Click on Push origin.

    GitHub push

Now SAP AI Core will automatically sync workflows from your GitHub through the Applications.

IMPORTANT: The SAP AI Core syncs in interval of 3 minutes.

Log on to answer question
Step 8: API to check workflow sync status

IMPORTANT: WAIT ATLEAST 3 MINS before sync is done.

Check the sync status of your workflows with postman.

ADD POSTMAN Environment Variable

Key Value
appName aicore-test-app
add environment variable

COLLECTIONS > admin > applications > GET get application status

Endpoint

GET
{{apiurl}}/v2/admin/applications/{{appName}}/status

SEND

RESPONSE

(if 404, See troubleshooting below.)

{
    "healthStatus": "Healthy",
    "message": "successfully synced (all tasks run)",
    "reconciledAt": "2021-09-27T03:16:41Z",
    "source": {
        "path": "workflows",
        "repoURL": "https://github.com/john/aicore-test",
        "revision": "8505d9235fc19f672096e22354a934e429dad9a3"
    },
    "syncFinishedAt": "2021-09-27T03:16:41Z",
    "syncRessourcesStatus": [
        {
            "kind": "WorkflowTemplate",
            "message": "workflowtemplate.argoproj.io/text-clf-train-tutorial configured",
            "name": "text-clf-train-tutorial",
            "status": "Synced"
        }
    ],
    "syncStartedAt": "2021-09-27T03:16:40Z",
    "syncStatus": "Synced"
}
get app status

Troubleshooting

  1. "message": "KeyError : 'operationState'"

    Your repository folder is empty from last sync. Wait for 3 minutes after uploading something to GitHub.

  2. "message": "Error retrieving status for application aicore-test-app"

    Unable to reach out application(SAP AI Core) named aicore-test-app, check if you have registered the GitHub directory as application.

Log on to answer question
Step 9: Summary

A small recap of what has been done so far.

  • The training and serving docker images are pushed to the docker repository
  • The training and serving workflows(*templates*) are uploaded to the GitHub repository.
AIF Setup
Navigate to Authorization Tab in Postman. Select the Type which will be going to use `token` from environment variable.
×

Next Steps

Back to top