MLA 014 Machine Learning Hosting and Serverless Deployment
Machine Learning Guide - A podcast by OCDevel

Categories:
Machine learning model deployment on the cloud is typically handled with solutions like AWS SageMaker for end-to-end training and inference as a REST endpoint, AWS Batch for cost-effective on-demand batch jobs using Docker containers, and AWS Lambda for low-usage, serverless inference without GPU support. Storage and infrastructure options such as AWS EFS are essential for managing large model artifacts, while new tools like Cortex offer open source alternatives with features like cost savings and scale-to-zero for resource management. Links Notes and resources at ocdevel.com/mlg/mla-14 Try a walking desk stay healthy & sharp while you learn & code Cloud Providers for Machine Learning Hosting The major cloud service providers for machine learning hosting are Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure. AWS is widely adopted due to rapid innovation, a large ecosystem, extensive documentation, and ease of integration with other AWS services, despite some features of GCP, such as TPUs, being attractive for specific use cases. Core Machine Learning Hosting Services 1. AWS SageMaker SageMaker is an end-to-end service for training, monitoring, and deploying machine learning models, including REST endpoint deployment for inference. It features auto-scaling, built-in monitoring, and support for Jupyter notebooks, but it incurs at least a 40% cost premium over direct EC2 usage and is always-on, which can be costly for low-traffic applications. AWS SageMaker provides REST endpoint deployment and training analytics. Google Cloud offers GCP Cloud ML with similar functionality. 2. AWS Batch AWS Batch allows one-off batch jobs, typically for resource-intensive ML training or infrequent inference, using Docker containers. Batch supports spot instances for significant cost savings and automatically shuts down resources when jobs complete, reducing always-on costs. Batch jobs can be triggered via CLI, console, or programmatically, and the service does not provide automatic deployment or monitoring functionality like SageMaker. AWS Batch enables Docker-based batch jobs and leverages ECR for container hosting. 3. AWS Lambda AWS Lambda provides serverless deployment for machine learning inference, auto-scaling to meet demand, and incurs costs only during actual usage, but it does not support GPU or Elastic Inference. Lambda functions can utilize attached AWS EFS for storing and loading large model artifacts, which helps manage deployment size and cold start performance. Only models that can perform inference efficiently on CPU within Lambda’s memory and compute limits are suitable for this approach. 4. Elastic Inference and Persistent Storage AWS Elastic Inference enables the attachment of fractional GPU resources to EC2 or SageMaker for inference workloads, driving down costs by avoiding full GPU allocation. AWS EFS (Elastic File System) is used to provide persistent, shared storage for model artifacts, allowing services like Batch and Lambda to efficiently access large files without repeated downloads. AWS EFS allows mounting persistent file systems across services. Model Optimization and Compatibility Model optimizers such as ONNX (Open Neural Network Exchange) and Intel’s OpenVINO can compress and optimize machine learning models for efficient inference, enabling CPU-only deployment with minimal loss of accuracy. ONNX helps convert models to a format that is interoperable across different frameworks and architectures, which supports serverless environments like Lambda. Emerging and Alternative Providers 1. Cortex Cortex is an open source system that orchestrates model training, deployment, and scaling on AWS, including support for spot instances and potential for scale-to-zero, reducing costs during idle periods. Cortex aims to provide SageMaker-like capabilities without the additional premium and with greater flexibility over infrastructure management. 2. Other Providers PaperSpace Gradient and FloydHub are additional providers offering ML model training and deployment services with cost-competitive offerings versus AWS. PaperSpace is highlighted as significantly less expensive than SageMaker and Batch, though AWS integration and ecosystem breadth may still steer users toward AWS-native solutions. Batch and Endpoint Model Deployment Scenarios If model usage is rare (e.g., 1–50 times per day), batch approaches such as AWS Batch are cost-effective, running containerized jobs as needed and then shutting down. For customer-facing applications requiring consistently available models, endpoint-based services like SageMaker, GCP Cloud ML, or Cortex are more appropriate. Orchestration and Advanced Architectures Kubernetes and related tools can be used to orchestrate ML models and complex pipelines at scale, enabling integration of components such as API gateways, serverless functions, and scalable training and inference systems. Tools like KubeFlow leverage Kubernetes for deploying machine learning workloads, but require higher expertise and greater management effort. Summary Table of Linked Services AWS Batch ECR (EC2 Container Registry) AWS SageMaker GCP Cloud ML Cortex PaperSpace Gradient FloydHub