Skip to Content

Create Training and Serving Docker Images (Client SDK)

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

Create Training and Serving Docker Images (Client SDK)

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

You will learn

  • How to build Docker images for python code
  • How to upload Docker image to docker hub.
  • How set workflows to train and serve your ML model with SAP AI Core
  • How to set computing hardware resources, GPUs for your ML model
QR code


Step 1: Create ML code and Docker files

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

Create files (download links 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: Convert python code to Docker image

Connect your Docker Desktop to the Docker account.

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

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

docker login

Navigate to place where you have stored your ML code files.

directory

Navigate inside train directory on terminal.

cd train

Build docker image using the following command to build docker image for training the model. (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 images to Docker repository

Execute the following on terminal (change highlighted line).

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

Similarly push your serving docker image.

Execute the following on terminal (change highlighted line).

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

Visit https://hub.docker.com, Inside the repository text-clf-train you will see you Docker image with the tag representing the version.

docker uploads
Log on to answer question
Step 4: Create workflow files

Workflows instructs SAP AI Core,
- how to execute the Docker images (orchestrate)
- what inputs to provide(datasets)
- what outputs to generate.

(Further read ArgoWorkflows )

Create a folder workflows locally and create the following file (download links below) as depicted in the image below.

Download Files

File Link
training_workflow_tutorial.yaml Download
serving_workflow_tutorial.yaml Download
workflows folder
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 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 information to workflow

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: Check workflow sync status with SAP AI API Client SDK

Warning Ensure you have properly set up files/aic_service_key.json and ai_api_client previously.

Execute the following python code on your Jupyter notebook cell

app_name = "aicore-test-app"

ai_api_client.rest_client.get(
    path=f"/admin/applications/{app_name}/status"
)

Example Output

{
    'health_status': 'Healthy',
    'message': 'successfully synced (all tasks run)',
    'reconciled_at': '2021-09-21T11:10:10Z',
    'source': {'path': 'workflows',
     'repourl': 'https://GitHub.com/John/aicore-test',
     'revision': '87f3f1c2cedb686235e8cfe395266d651ffb44b1'},
    'sync_finished_at': '2021-09-20T11:10:10Z',
    'sync_ressources_status': [
     {'kind': 'ServingTemplate',
      'message': 'servingtemplate.ai.sap.com/text-clf-infer-tutorial created',
      'name': 'text-clf-infer-tutorial',
      'status': 'Synced'},
     {'kind': 'WorkflowTemplate',
      'message': 'workflowtemplate.argoproj.io/text-clf-train-tutorial created',
      'name': 'text-clf-train-tutorial',
      'status': 'Synced'}],
    'sync_started_at': '2021-09-20T11:10:10Z',
    'sync_status': 'Synced'}

Summary: what was achieved.

  • 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
If you need more computing hardware resources for your use case, where you will specify that?
×

Next Steps

Back to top