standardizing deep deployment withmax nick...

36
Standardizing deep learning model deployment with MAX Nick Pentreath Principal Engineer @MLnick

Upload: others

Post on 20-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Standardizing deep learning model deployment with MAX—Nick PentreathPrincipal Engineer

@MLnick

Page 2: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

About

IBM Developer / © 2019 IBM Corporation

– @MLnick on Twitter & Github

– Principal Engineer, IBM CODAIT (Center for Open-Source Data & AI Technologies)

– Machine Learning & AI

– Apache Spark committer & PMC

– Author of Machine Learning with Spark

– Various conferences & meetups

2

Page 3: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

CODAIT

Improving the Enterprise AI Lifecycle in Open Source

Center for Open Source Data & AI Technologies

IBM Developer / © 2019 IBM Corporation 3

CODAIT aims to make AI solutions dramatically easier to create, deploy, and manage in the enterprise.

We contribute to and advocate for the open-source technologies that are foundational to IBM’s AI offerings.

30+ open-source developers!

Page 4: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

The Machine Learning Workflow

IBM Developer / © 2019 IBM Corporation 4

Page 5: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

The workflow spans teams …

IBM Developer / © 2019 IBM Corporation 5

Page 6: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

… and tools …

IBM Developer / © 2019 IBM Corporation 6

Page 7: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

… and is a small (but critical!) piece of the puzzle

*Source: Hidden Technical Debt in Machine Learning SystemsIBM Developer / © 2019 IBM Corporation 7

Page 8: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Machine Learning Deployment

IBM Developer / © 2019 IBM Corporation 8

Page 9: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

What, Where, How?

–What are you deploying?• What is a “model”

–Where are you deploying?• Target environment (cloud, browser, edge)• Batch, streaming, real-time?

–How are you deploying?• “devops” deployment mechanism• Serving framework

We will talk about the what & how

IBM Developer / © 2019 IBM Corporation 9

Page 10: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

What is a “model”?

IBM Developer / © 2019 IBM Corporation 10

Page 11: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Deep Learning doesn’t need feature engineering or data processing …

IBM Developer / © 2019 IBM Corporation 11

right?

Page 12: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Deep learning pipeline?

IBM Developer / © 2019 IBM Corporation 12

Source: https://ai.googleblog.com/2016/03/train-your-own-image-classifier-with.html

beagle: 0.82

Input image Inference Prediction

Page 13: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Deep learning pipeline!

IBM Developer / © 2019 IBM Corporation 13

beagle: 0.82

basset: 0.09

bluetick: 0.07

...

Input image Image pre-processing Prediction

Decode image

Resize

Normalization

Convert types / format

Inference Post-processing

[0.2, 0.3, … ]

(label, prob)

Sort

Label map

PIL, OpenCV, tf.image, …

Custom Python

* Logos trademarks of their respective projects

Page 14: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Pipelines, not Models

– Deploying just the model part of the workflow is not enough

– Entire pipeline must be deployed• Data transforms• Feature extraction & pre-processing• DL / ML model• Prediction transformation

– Even ETL is part of the pipeline!

– Pipelines in frameworks• scikit-learn• Spark ML pipelines• TensorFlow Transform• pipeliner (R)

IBM Developer / © 2019 IBM Corporation 14

Page 15: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Many Challenges

IBM Developer / © 2019 IBM Corporation

– Formats• Each framework does things differently

• Proprietary formats: lock-in, not portable

– Lack of standardization leads to custom solutions and extensions

– Need to manage and bridge many different:• Languages - Python, R, Notebooks, Scala / Java / C • Frameworks – too many to count!• Dependencies• Versions

– Friction between teams• Data scientists & researchers – latest & greatest• Production – stability, control, minimize changes,

performance• Business – metrics, business impact, product

must always work!

* Logos trademarks of their respective projects15

Page 16: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Containers for ML Deployment

IBM Developer / © 2019 IBM Corporation 16

Page 17: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Containers for ML Deployment

– But …• What goes in the container is still the most

important factor• Performance can be highly variable across

language, framework, version• Requires devops knowledge, CI / deployment

pipelines, good practices• Does not solve the issue of standardization• Formats

• APIs exposed

• A serving framework is still required on top

– Container-based deployment has significant benefits• Repeatability• Ease of configuration• Separation of concerns – focus on what, not

how• Allow data scientists & researchers to use their

language / framework of choice• Container frameworks take care of (certain)

monitoring, fault tolerance, HA, etc.

IBM Developer / © 2019 IBM Corporation 17

Page 18: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

The Model Asset Exchange

IBM Developer / © 2019 IBM Corporation 18

Page 19: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

19

ModelAsset

eXchange(MAX)

ibm.biz/model-exchange

IBM Developer / © 2019 IBM Corporation

Page 20: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

What is

MAX?

20

- One place for state-of-art open source deep learning models

- Wide variety of domains

- Tested code and IP

- Free and open source

- Both trainable and trained versions

IBM Developer / © 2019 IBM Corporation

Page 21: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

21

BehindtheScenes

Find a state-of-art open source deep learning model specific to domain

Validate license terms

Perform model health check &code clean up

Wrap models in MAX framework and provide REST API

Publish the model as Docker images on Docker Hub

Review and Continuous Integration

IBM Developer / © 2019 IBM Corporation

Page 22: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Deployable Asset on MAX

Data ExpertiseComputeModel

REST API specificationPre Trained ModelI/O processing

Deployable Asset on Model Asset Exchange

MetadataInferenceSwagger Specification

22IBM Developer / © 2019 IBM Corporation

Page 23: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

23

Accessing the Model – REST API

MODELREST API

flask

Request information from model

Send input to model

GET

POST

MAX Model Consumption – REST API

IBM Developer / © 2019 IBM Corporation

Page 24: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

MAX Model Consumption – REST API

24IBM Developer / © 2019 IBM Corporation

Page 25: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

MAX Model Consumption - Python

25

2. Python

ibm.biz/max-notebookIBM Developer / © 2019 IBM Corporation

Page 26: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

26

2. Python

ibm.biz/max-notebookIBM Developer / © 2019 IBM Corporation

Page 27: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

27

- User uses Web UI to send an image to Model API.

- Model API returns object data and Web UI displays detected objects.

3. Web App

IBM Developer / © 2019 IBM Corporation

Page 28: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

28

… and a few others

IBM Developer / © 2019 IBM Corporation

Page 29: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

MAX-Framework MAX-Skeleton

29

- Template repository to create a deployable MAX model.

- Contains all the code scaffolding and imports MAX Framework.

- A pip installable python library.

- Wrapper around Flask

- Abstracts out all basic functionality of the MAX model into MAXApp and MAXApi abstract classes.

github.com/IBM/MAX-Framework github.com/IBM/MAX-SkeletonIBM Developer / © 2019 IBM Corporation

Page 30: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

30

MAX Framework

IBM Developer / © 2019 IBM Corporation

Page 31: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

31

MAX Framework

IBM Developer / © 2019 IBM Corporation

Page 32: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

32

MAX Framework

IBM Developer / © 2019 IBM Corporation

Page 33: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

- Docker

- Python IDE or code editors

- Pre-trained model weights stored in a downloadable location

- List of required python packages

- Input pre-processing code

- Prediction/Inference code

- Output post-processing code

33

Requirements for Wrapping a Model

IBM Developer / © 2019 IBM Corporation

Page 34: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

34

Steps to wrap your own model

Use MAX-Skeleton

• Login to GitHub• Click on `Use

this template`• Clone the new

repository

Update Dockerfile

• Update model file location

• Calculate hash value for model files and update md5sum.txt

Requirements update

• Add required python packages along with version number

Update metadata

• Update REST API metadata

• Update model related metadata

Update scripts

• Add pre-processing, prediction and post-processing code.

Test the model

• Build the docker image

• Run the model server

IBM Developer / © 2019 IBM Corporation

Page 35: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

Thank you!

IBM Developer / © 2019 IBM Corporation

codait.org

twitter.com/Mlnick & twitter.com/ibmcodait

github.com/MLnick

developer.ibm.com

35

- MAX on IBM Developerhttps://ibm.biz/model-exchange

- DAX on IBM Developerhttps://ibm.biz/data-exchange

- Learning pathhttps://ibm.biz/max-learning-path

- Ecosystem statushttps://ibm.biz/max-status

- MAX Frameworkhttps://ibm.biz/max-framework

- MAX Node Redhttps://ibm.biz/max-node-red

Page 36: Standardizing deep deployment withMAX Nick …cognitive-science.info/wp-content/uploads/2019/10/MAX...2019/10/10  · workflow is not enough –Entire pipeline must be deployed •Data

IBM Developer / © 2019 IBM Corporation 36