SlideShare a Scribd company logo
Serving models
from AWS Lambda
Alexey Grigorev
01.08.2019
AWS Lambda
Messages from SQS
How about python&ML stuff?
pip install -r requirements.txt -t build
cp index.py build
cd build && zip -r ../build.zip & cd ..
specify output folder
this is sent to aws
How about python&ML stuff?
aws lambda update-function-code 
--function-name ${FUNCTION_NAME} 
--s3-bucket ${S3_BUCKET} 
--s3-key ${ZIP_FILE}
Problems: Mac
Use Docker!
Problem: AWS Lambda Limits
● Limits:
○ 128MB - 3GB of RAM
○ 512MB storage in /tmp
○ Package size 50MB zipped / 250MB unzipped
https://docs.aws.amazon.com/lambda/latest/dg/limits.html
AWS Lambda Limits
$ du -sh * | sort -k 2
28K bin
56M build.zip
392K imagehash
32K ImageHash-4.0.dist-info
80M numpy
88K numpy-1.17.0.dist-info
6.8M PIL
48K Pillow-5.4.1.dist-info
32K __pycache__
28K PyWavelets-1.0.3.dist-info
8.4M pywt
88M scipy
148K scipy-1.3.0.dist-info
28K six-1.12.0.dist-info
32K six.py
More than 50MB
Solution: rm things
32M May 16 10:50 index-index-hasher.zip
It scalez!
Image index
https://tech.olx.com/detecting-image-duplicates-at-olx-scale-7f59e4b6aef4
s3
ObjectCreated:Put
ES
hashes
Image index
ingestor
What if we could use it for serving image models?
pip install numpy pillow tensorflow==1.7.0 -b build
size: 354M
I’ll just
deploy TF
to lambda
How to cut down the size of TF?
!!!
Yay!
original size 354M
striping SOs in tensorflow
striping SOs in numpy
stripped size 177M
compressed size 43M
Keras models in Lambda
● Convert Keras to TF
● Save the model to s3
● During lambda startup
○ Download the model from s3
○ Put to /tmp
○ Load the model
○ Don’t delete from /tmp - new lambdas startup will be faster
Keras → TF
Load Keras model
Convert to TF and save
Loading on startup
Loading on startup
Serve!
https://github.com/keras-team/keras-applications/blob/master/keras_applications/inception_resnet_v2.py#L38
https://github.com/keras-team/keras-applications/blob/master/keras_applications/imagenet_utils.py#L18
https://github.com/keras-team/keras-preprocessing/blob/master/keras_preprocessing/image/utils.py#L78
Demo
Demo: First request
Demo: Consequent requests
More RAM
● 1152MB: 50 sec load, 4 sec inference
● 1344MB: 43 sec load, 3.2 sec inference
● 1536MB: 30 sec load, 3 sec inference
Price
● 1024MB:
○ (4sec) 40 * 0.000001667
○ = 0.00006668 USD
○ 1 mln images: 66 USD
● 1344MB:
○ 1 mln images: 66 USD
● 1536MB:
○ 1 mln images: 75 USD
https://aws.amazon.com/lambda/pricing/

More Related Content

PDF
Large-Scale Training with GPUs at Facebook
PDF
How to deploy machine learning models in the Cloud
PDF
running Tensorflow in Production
PPTX
AI Pipeline Optimization using Kubeflow
PDF
Smokey and the Multi-Armed Bandit Featuring BERT Reynolds Updated
PDF
Horovod - Distributed TensorFlow Made Easy
PDF
Efficient Image Processing with Halide
PPTX
Promise of a better future by Rahul Goma Phulore and Pooja Akshantal, Thought...
Large-Scale Training with GPUs at Facebook
How to deploy machine learning models in the Cloud
running Tensorflow in Production
AI Pipeline Optimization using Kubeflow
Smokey and the Multi-Armed Bandit Featuring BERT Reynolds Updated
Horovod - Distributed TensorFlow Made Easy
Efficient Image Processing with Halide
Promise of a better future by Rahul Goma Phulore and Pooja Akshantal, Thought...

What's hot (17)

PDF
A Journey From Objective C to Swift - Chromeinfotech
ODP
Objectivec vs swift
PPTX
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
PPTX
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
PDF
MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
PDF
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
PDF
Building Serverless Machine Learning models in the Cloud
PDF
TinyML as-a-Service
PDF
PipelineAI Continuous Machine Learning and AI - Rework Deep Learning Summit -...
PPTX
Swift vs Objective-C
PDF
Google APAC Machine Learning Expert Day
PDF
Javantura v4 - Java and lambdas and streams - are they better than for loops ...
PPT
Adobe Session on Flash Online Conference #12
PDF
Introducing Kubeflow (w. Special Guests Tensorflow and Apache Spark)
PPT
GPU_based Searching
PDF
PipelineAI Real-Time Machine Learning - Global Artificial Intelligence Confer...
PDF
Lambda - Building On-prem GPU Training Infrastructure
A Journey From Objective C to Swift - Chromeinfotech
Objectivec vs swift
From Hours to Minutes: The Journey of Optimizing Mask-RCNN and BERT Using MXNet
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Building Serverless Machine Learning models in the Cloud
TinyML as-a-Service
PipelineAI Continuous Machine Learning and AI - Rework Deep Learning Summit -...
Swift vs Objective-C
Google APAC Machine Learning Expert Day
Javantura v4 - Java and lambdas and streams - are they better than for loops ...
Adobe Session on Flash Online Conference #12
Introducing Kubeflow (w. Special Guests Tensorflow and Apache Spark)
GPU_based Searching
PipelineAI Real-Time Machine Learning - Global Artificial Intelligence Confer...
Lambda - Building On-prem GPU Training Infrastructure
Ad

Similar to Serving models from AWS Lambda (20)

PDF
Nils Mohr & Jake Pearce - 100 years of flight data at British Airways. Past, ...
PDF
Onur Salk & Onur Gurdamar - Everything as Code: Creating an application stack...
PDF
Intro to AWS Lambda
PDF
Squeezing Machine Learning into Serverless for Image Recognition - AWS Meetup...
PDF
How Zalando runs Kubernetes clusters at scale on AWS - AWS re:Invent
PDF
Amazed by AWS Series #4
PDF
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
PPTX
Cloud Security with Amazon Web Services
PDF
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
PDF
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
PDF
AWS CDK를 활용한 클라우드 프로그래밍
PDF
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
PPTX
Bitbucket Pipelines - Powered by Kubernetes
PPTX
Aws meetup building_lambda
PPTX
Journey to Microservice architecture via Amazon Lambda
PDF
Deploying, Scaling, and Running Grails on AWS and VPC
PDF
Cloud-Native Integration with Apache Camel on Kubernetes (Copenhagen October ...
PDF
Something About Microservices - AWS & Azure Meetup Munich - 22.05.2018
PDF
Apache Camel v3, Camel K and Camel Quarkus
PDF
CloudFork
Nils Mohr & Jake Pearce - 100 years of flight data at British Airways. Past, ...
Onur Salk & Onur Gurdamar - Everything as Code: Creating an application stack...
Intro to AWS Lambda
Squeezing Machine Learning into Serverless for Image Recognition - AWS Meetup...
How Zalando runs Kubernetes clusters at scale on AWS - AWS re:Invent
Amazed by AWS Series #4
AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Prac...
Cloud Security with Amazon Web Services
AWS reinvent 2019 recap - Riyadh - Containers and Serverless - Paul Maddox
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
AWS CDK를 활용한 클라우드 프로그래밍
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
Bitbucket Pipelines - Powered by Kubernetes
Aws meetup building_lambda
Journey to Microservice architecture via Amazon Lambda
Deploying, Scaling, and Running Grails on AWS and VPC
Cloud-Native Integration with Apache Camel on Kubernetes (Copenhagen October ...
Something About Microservices - AWS & Azure Meetup Munich - 22.05.2018
Apache Camel v3, Camel K and Camel Quarkus
CloudFork
Ad

More from Alexey Grigorev (20)

PDF
MLOps week 1 intro
PDF
Codementor - Data Science at OLX
PDF
Data Monitoring with whylogs
PDF
Data engineering zoomcamp introduction
PDF
AI in Fashion - Size & Fit - Nour Karessli
PDF
AI-Powered Computer Vision Applications in Media Industry - Yulia Pavlova
PDF
ML Zoomcamp 10 - Kubernetes
PDF
Paradoxes in Data Science
PDF
ML Zoomcamp 8 - Neural networks and deep learning
PDF
Algorithmic fairness
PDF
MLOps at OLX
PDF
ML Zoomcamp 6 - Decision Trees and Ensemble Learning
PDF
ML Zoomcamp 5 - Model deployment
PDF
Introduction to Transformers for NLP - Olga Petrova
PDF
ML Zoomcamp 4 - Evaluation Metrics for Classification
PDF
ML Zoomcamp 3 - Machine Learning for Classification
PDF
ML Zoomcamp Week #2 Office Hours
PDF
AMLD2021 - ML in online marketplaces
PDF
ML Zoomcamp 2 - Slides
PDF
ML Zoomcamp 2.1 - Car Price Prediction Project
MLOps week 1 intro
Codementor - Data Science at OLX
Data Monitoring with whylogs
Data engineering zoomcamp introduction
AI in Fashion - Size & Fit - Nour Karessli
AI-Powered Computer Vision Applications in Media Industry - Yulia Pavlova
ML Zoomcamp 10 - Kubernetes
Paradoxes in Data Science
ML Zoomcamp 8 - Neural networks and deep learning
Algorithmic fairness
MLOps at OLX
ML Zoomcamp 6 - Decision Trees and Ensemble Learning
ML Zoomcamp 5 - Model deployment
Introduction to Transformers for NLP - Olga Petrova
ML Zoomcamp 4 - Evaluation Metrics for Classification
ML Zoomcamp 3 - Machine Learning for Classification
ML Zoomcamp Week #2 Office Hours
AMLD2021 - ML in online marketplaces
ML Zoomcamp 2 - Slides
ML Zoomcamp 2.1 - Car Price Prediction Project

Recently uploaded (20)

PDF
Business Analytics and business intelligence.pdf
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PPTX
Database Infoormation System (DBIS).pptx
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
Business Acumen Training GuidePresentation.pptx
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PPTX
Introduction to machine learning and Linear Models
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PDF
Foundation of Data Science unit number two notes
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
1_Introduction to advance data techniques.pptx
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Business Analytics and business intelligence.pdf
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Database Infoormation System (DBIS).pptx
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
Business Acumen Training GuidePresentation.pptx
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Introduction to machine learning and Linear Models
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
climate analysis of Dhaka ,Banglades.pptx
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
Galatica Smart Energy Infrastructure Startup Pitch Deck
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
Foundation of Data Science unit number two notes
.pdf is not working space design for the following data for the following dat...
1_Introduction to advance data techniques.pptx
Introduction-to-Cloud-ComputingFinal.pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx

Serving models from AWS Lambda