Deploy ML apps in minutes
Anand Chitipothu
rorodata
Slide 2
Slide 2 text
Who is speaking?
Anand Chitipothu
@anandology
• Building a data science platform at
@rorodata
• Advanced programming courses at
@pipalacademy
• Worked at Strand Life Sciences and
Internet Archive
Slide 3
Slide 3 text
The problem
How to expose a function as an API for others to use?
Slide 4
Slide 4 text
Welcome to Firefly
Deploying functions made easy!
Slide 5
Slide 5 text
Code
Write your function:
# sq.py
def square(n):
return n*n
Slide 6
Slide 6 text
Run
Start web service:
$ firefly sq.square
[INFO] Starting gunicorn 19.7.1
[INFO] Listening at: http://127.0.0.1:8000
...
Slide 7
Slide 7 text
Use
And use it with a client.
>>> from firefly.client import Client
>>> client = Client("http://127.0.0.1:8000")
>>> client.square(n=4)
16
Slide 8
Slide 8 text
Behind the scenes, it is a RESTful API.
$ curl -d '{"n": 4}' http://127.0.0.1:8000/square
16
And supports any JSON-friendly datatype.
Slide 9
Slide 9 text
More practical example
Deploying a machine learning model.
# model.py
import pickle
model = pickle.load('model.pkl')
def predict(features):
result = model.predict(features])
return int(result[0])
Slide 10
Slide 10 text
Run the server using:
$ firefly model.predict
...
And use it in the client:
>>> remote_model = Client("http://localhost:8080/")
>>> remote_model.predict(features=[5.9, 3, 5.1, 1.8]))
2
Slide 11
Slide 11 text
It's open source!
https://github.com/rorodata/firefly
To install:
pip install firefly-python
Slide 12
Slide 12 text
How to deploy it in the cloud?
We have a heroku-like platform for you.
http://rorodata.com/
Slide 13
Slide 13 text
Specify services
The services are specified in the roro.yml file.
# roro.yml
project: credit-risk
runtime: python3
services:
- name: default
function: predict.predict
- name: credit-grade
function: credit_grade.get_credit_grade
The platform allows deploying Python functions as APIs.
Slide 14
Slide 14 text
Deploy!
Run deploy command to deploy the project.
$ roro deploy
Deploying credit-risk: version 2
Building the docker image...
starting services...
Done.
Services:
default: https://credit-risk.rorocloud.io/
credit-grade: https://credit-risk--credit-grade.rorocloud.io/
Slide 15
Slide 15 text
Run scripts and notebooks.
$ roro run --size C64 train.py
Created new job b42c12a0
$ roro run --gpu train.py
Created new job b42c12a0
$ roro run:notebook
Created new job 60984179
Jupyter notebook is available at:
https://60984179.rorocloud.io/?token=LNRZDpHdPhGLzf00
The jupyter notebook server can be stopped using:
roro stop 60984179
Slide 16
Slide 16 text
Can I deploy it to my own server?
Oh, we have a lite version of the platform rorolite and that is
open-source.
https://github.com/rorodata/rorolite
Slide 17
Slide 17 text
The services are specified in the rorolite.yml file.
# rorolite.yml
host: 1.2.3.4
user: root
services:
- name: api
function: predict.predict
port: 8000
- name: webapp
command: gunicorn -b 0.0.0.0:8080 webapp:app
port: 8080
It also allows deploying Python functions as APIs.
Slide 18
Slide 18 text
And deploy!
$ rorolite deploy
Deploying project version 7...
...
Services are live at:
api -- http://1.2.3.4:8000/
webapp -- http://1.2.3.4:8080/
Slide 19
Slide 19 text
Look at logs:
$ rorolite logs api
2017-10-25 04:13:12 firefly [INFO] Starting Firefly...
2017-10-25 04:15:12 predict function called
Slide 20
Slide 20 text
Summary
• Firefly - functions as service (open-source)
• rorodata platform - cloud platform (PaaS)
• rorolite - lite version of the platform (open-source)