Deploying Machine Learning Models in the Cloud
Take a look at versioning, inference pipelines, inference model optimization, and standard requirements for services.
Join the DZone community and get the full member experience.Join For Free
for software development, there are many methodologies, patterns, and techniques to build, deploy, and run applications. devops is the state of the art methodology that describes a software engineering culture with a holistic view of software development and operation.
for data science, there is a lot of information on how machine and deep learning models can be built. the operational aspects seem to still be evolving. i'm currently trying to understand better how to deploy models in the cloud and how to use them efficiently in applications. below are some of my findings so far.
in the simplest case, models provided by data scientists and models extended by developers can be wrapped in docker containers and accessed via rest apis. the docker containers can be run, for example, on kubernetes or on serverless platforms like openwhisk . when building flask-based web applications, the models could even be packaged and run in the same container.
while this works for prototypes and quick evaluations, there are several other aspects you need to take into account when deploying models to production environments.
as for other services and apis, multiple versions need to be handled. at a minimum, it should be possible to roll out new models via blue-green deployments. furthermore, traffic management functionality like canary deployments and a/b testing is often required for sophisticated production applications.
in order to run inferences, applications have to provide the input in a certain format as expected by the models. in some cases, this means that the data needs to be formatted first. for example, in a visual recognition scenario, the application might have to convert a jpg image into a json structure. vise versa, the output of the model might not have the format the application requires.
additionally, sometimes it's more efficient to do batch invocations rather than causing network traffic for every single request. sometimes multiple models are invoked at the same time and the responses are sent together back to the applications.
so rather than deploying only the core model, inference pipelines should be deployed and made available as service.
inference model optimizations
i blogged about how to deploy models to edge devices via tensorflow lite and tensorflow.js . in both cases, models need to be optimized in terms of model size, memory usage, battery usage, etc. to achieve this, one method is to remove dropouts from the graph. dropouts are used during training to prevent overfitting models. at runtime, when running predictions, they are not needed.
another method to optimize models is quantization. weights in graphs are often defined via floats. when using integers instead, however, the sizes of the models are reduced significantly while the accuracy is only affected minimally or not at all.
similarly to optimizations for mobile devices, optimizations are done before deploying models to the cloud.
standard requirements for services
as for other services, authentication and authorization need to be handled. in order to make models accessible to multiple applications and developers, api management is desirable.
rest apis are not the only way to expose models. maybe other protocols like grpc or messaging based systems are better options for specific scenarios.
services that run inferences need to be scalable and there needs to be monitoring functionality. in summary, services that run inferences have the same requirements as all other services.
there are several frameworks to deploy models in the cloud. in the best case, a framework should fulfill all requirements above and the framework should be serverless so that people can focus on the business logic rather than infrastructure. below are a couple of frameworks and offerings that you might want to check out.
watson studio supports not only the training of models but also deployments of models. these models can have different versions and can be invoked via rest apis:
seldon is an open source platform for deploying machine learning models on kubernetes. it supports libraries like tensorflow and sklearn and rest and grpc apis. it can be used well together with the fabric for deep learning . i like especially the capability to do what i call inference pipelines above.
tensorflow serving is a flexible, high-performance serving system for machine learning models with built-in support for tensorflow models. it seems to be pretty powerful but when i tried it last year, it wasn't that easy. i'm sure it has improved a lot since then. for example, since recently tensorflow serving also supports rest and not only grpc.
pipelineai is a real-time enterprise ai platform and looks very promising. i've watched some of the great videos , which describe not only pipelineai but also deployment strategies and concepts in general. models are packaged in docker containers and can be run on kubernetes. while that part is open source, i'm not sure yet about other pipelineai components which do the model optimizations and visualization.
again, i'm only learning this topic myself currently, but maybe this article creates some awareness for the deployment requirements and options.
Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.