ml in production(flask, tornado), describe it in swagger stateless service. ... docker is an...

18
ML in production FunTech February 2019 [email protected] — Mark Andreev

Upload: others

Post on 05-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

ML in productionFunTech February 2019

[email protected] — Mark Andreev

Page 2: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Agenda

● About production

● Actuality of prediction

● From notebook to microservice

● Scale up your solution

● Monitoring & automatic problem solving

● Conclusion

2

https://clck.ru/FATUR

Page 3: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Main problems of productionTime● Actuality of prediction

Data● Inconstancy of data● Difference between train / evaluation sets

Model● Model sharing● Model maintaining: regularly predict / re-train

24/7 without engineer● Automatic monitoring● Automatic problem solving

3

Page 4: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Actuality of prediction

Offline prediction (~3+ hour)Churn prediction, User-Item recommendations

4

Big data

Page 5: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Actuality of prediction

Offline prediction (~3+ hour)Churn prediction, User-Item recommendations

5

Big data

Queue

Online prediction (~5 minute)Classify photo, Rate announcement ads

Page 6: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Actuality of prediction

Offline prediction (~3+ hour)Churn prediction, User-Item recommendations

6

Big data

Queue

Session

Online prediction (~5 minute)Classify photo, Rate announcement ads

Realtime prediction (~300ms)Search results, Ads recommendations{Strong timeout SLA}

Page 7: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Inconstancy of data

Schema validationFormat validation using XML/Json schema

7

Page 8: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Inconstancy of data

Schema validationFormat validation using XML/Json schema

8

Data validationRange validation. Test using hypotheses

Page 9: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Inconstancy of data

Schema validationFormat validation using XML/Json schema

9

Data validationRange validation. Test using hypotheses

Distribution validationDescriptive statistics

Page 10: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Difference between train / evaluation sets

Train / Evaluation Time GapTime between train set and evaluation set

10

Page 11: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Difference between train / evaluation sets

Train / Evaluation Time GapTime between train set and evaluation set

11

Feature extraction pipeline Pipelines must be the same

fit

predict

Page 12: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Difference between train / evaluation sets

Train / Evaluation Time GapTime between train set and evaluation set

12

Feature extraction pipeline Pipelines must be the same

Features distributionFeatures distribution should be the same

fit

predict

Page 13: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

How to share models

Frozen dependenciesPython packages, System libraries

TestsUnit tests, Integration tests, Exploration tests (hypothesis), Tests with data

13

− solution.ipynb− requirements.txt

− solution.py− test_solution.py− requirements.txt− Dockerfile

Public interfaceExpose your interface using REST (Flask, Tornado), describe it in Swagger

Stateless service

Page 14: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Stateless service

Extract state from serviceDocker is an immutable container, extract the state outside

Freeze service stateSave all dependencies and sub-dependencies

14

− solution.py− web.py− config.json

Immutable data

Public interfaceAllow external connection only through public interfaces

Scale up your serviceStateless allows us to linearly scale our solution

Mutable data

Page 15: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Scaling up using orchestration

15

From pets to cattle

Page 16: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Regular offline prediction

16

Luigi by- Data pipeline framework- More stable- Scheduler is not included

Airflow by - Data pipeline framework- More flexible- More testable- Pretty dashboard

Page 17: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Monitoring & automatic problem solving

17

Client Request ML Service

Client Response Request-id

Metrics

Errors

Request-idLogs

Save your historyUse Logs, Metrics, Errors saving, Tracing for problem capturing and detection

Visualize your data through dashboardsExplicit is better than implicit. Visualize your key indicators

Graceful degradation.Try to solve your problems automatically using spare models

Prometheus

Page 18: ML in production(Flask, Tornado), describe it in Swagger Stateless service. ... Docker is an immutable container, extract the state outside Freeze service state Save all dependencies

Conclusion

● Check your inputs

● Containerize your solution

● Use Microservices Architecture

● Monitoring tools is your best friends

● Solve your problems automatically