没有合适的资源?快使用搜索试试~ 我知道了~
首页机器学习模型部署的两种方式
资源详情
资源推荐
There are two very different ways to
deploy ML models, here’sboth
If an ML model makes a prediction in Jupyter, is anyone around to
hear it?
Probably not. Deploying models is the key to making them useful.
It’s not only if you’re building product, in which case deployment is a
necessity — it also applies if you’re generating reports for
management. Ten years ago it was unthinkable that execs wouldn’t
question assumptions and plug their own numbers into an Excel
sheet to see what changed. Today, a PDF of impenetrable matplotlib
figures might impress junior VPs, but could well fuel ML skepticism
in the eyes of experienced C-suite execs.
Don’thelpbringabouttheendoftheAIhypecycle!
And so, deployment of ML models became the hot topic, simply
because there aren’t that many people who know how to do it; seeing
that you need both data science and engineering skills. As I recently
discovered, there are two really divergent ways to deploy models: the
traditional way, and a more recent option that, I will be honest, blew
my mind.
In this article, I’ll provide you with a straightforward yet best-
practices template for both kinds of deployment. As always, for the
kinaesthetic learner, feel free to skip straight to the code here, which I
actually deployed here if you want to test it out. I know not everybody
likes to jump around when reading; it looks like this:
Tom Grek
F
o
ll
ow
Nov 25, 2018
·
9 min read
How to deploy an MLmodel
If you come from an analyst background, you may not grok web-app
architecture, so let me illustrate that first. Apologies if this is
oversimplification and man-splaining! But I have seen enough “ML
model deployments” that are really just XGBoost wrapped in Flask,
that I know it’s a real problem.
The user (on the left here) is using a browser that runs only
Javascript, HTML, and CSS. That’s the frontend. It can make calls to
a backend server to get results, which it then maybe processes and
displays. The backend server should respond ASAP to the frontend’s
requests; but the backend may need to talk to databases, third party
APIs, and microservices. The backend may also produce slow jobs —
such as ML jobs — at the request of the user, which it should put into a
queue. (Bear in mind that usually that the user usually has to
authenticate itself somehow).
I didn’t train the model for long; it’s not the point of thisarticle!
Now, let’s talk distributed web app architecture.
In general, we want to run as many backend instances as possible, for
scalability. That’s why there are bubbles coming out of ‘server’ in the
diagram above; they represent ‘more of these’. So, each instance has
to remain stateless: finish handling the HTTP request and exit. Don’t
keep anything in memory between requests, because aclient’sfirst
requestmightgotooneserver,andasubsequentrequestto
another.
It’s bad if we have a long running endpoint: it would tie up one of our
servers (say… doing some ML task), leaving it unable to handle other
users’ requests. We need to keep the web server responsive and have
it hand off long running tasks, with some kind of shared persistence
so that when the user checks progress or requests the result, any
server can report. Also, jobs, and parts-of-jobs, should be able to be
done in parallel by as many workers as there are resources for.
Theanswerisafirstin,firstout(FIFO)queue. The backend
simply enqueues jobs. Workers pick and process jobs out of the
queue, performing training or inference, and storing models or
predictions to the database when done.
With the library MLQ, the following is literally all you need for a
backend web server — an endpoint to enqueue a job, an endpoint to
check the progress of a job, and an endpoint to serve up a job’s result
if the job has finished.
Commonly, the frontend might be built with JS and/or React, and the
backend with Python (and Django or Flask) or NodeJS (and Express).
剩余10页未读,继续阅读
tox33
- 粉丝: 64
- 资源: 304
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功