SeriesAWS ML Engineer (Associate)8 / 9

Machine Learning Operations with AWS

Section 9 of AWS Certified ML Engineer course from Udemy.

Categories

Introduction#

Practical applications of machine learning require knowledge of Machine Learning Operations (MLOps) - the set of practices supporting model development, testing, integration, release, and infrastructure management. This section reviews the basic principles of MLOps and their relation to various AWS services.

Deployment#

Model Deployment is the process of integrating a trained ML model into a production environment, making it available for inference via other applications or systems.

Optimizing Deployments#

SageMaker AI offers both single and multi-model endpoints for inference. Each endpoint has its own deployment guardrails and may be configured with its own VPC. Endpoints support load balancing through the use of application auto-scaling. Foundation model deployment can be optimized via asynchronous inference (if latency isn’t important) and model compression techniques:

Monitor token counts for LLM deployments - this tends to be the most important driver of cost. If real-time inference is not required, consider batching to improve resource utilization. Note that tensor parallelism shards LLM weights across GPUs, and can thereby yield better memory utilization per container. CloudWatch is very useful for monitoring efficiency and utilization.

Safeguards#

AWS deployment guardrails control shifting traffic to new models via “blue/green deployments”, where the blue : old model and green : new model.

Auto-rollbacks revert changes to the original (blue) fleet upon some trigger condition. Shadow tests compare the performance of a shadow variant with a production variant.

Docker#

Docker is a software application for creating containers - lightweight isolated environments which serve as an alternative to virtualization, but share the same host OS kernel.

SageMaker models are hosted in Docker containers built from images registered with Amazon Elastic Container Registry (ECR). ECR offers pre-built images for many common machine learning model types, including PyTorch and scikit-learn. AWS has multiple services for creating and running containers from images:

Docker

SageMaker permits separate images for training and inference. Training and inference containers have predefined file tree structures. Models are commonly served via flask (Python API framework) and nginx (high-performance HTTP web server).

Instance Types#

How should we select an instance type for model training / inference? Training deep learning models may benefit from the use of a GPU (P3, g4dn). More lightweight instances (C5) are suitable for inference since it tends to be less computationally intensive.

Note that EC2 Spot Instances offer managed training on interruptible spare capacity, and can be much more cost efficient for small projects.

Deployment Methods for Inference#

How can we actually go about deploying a trained model?

There are a few primary types of inference:

AWS offers serverless inference in certain scenarios, which abstracts away infrastructure management from the developer by automatically provisioning and scaling underlying instances.

Inference pipelines chain together a linear sequence of containers to combine pre-processing, prediction generation (actual inference), and post-processing in a modular fashion. This is suitable for both real-time and batch inference workloads.

Model Monitoring#

Metrics to Monitor#

What are the primary types of metrics we should monitor within an ML system? We can broadly group metrics of interest by category.

Performance Baselines and Drift#

Baselines define the expected / reference behavior for a model in production. There are two primary types of baselines:

Accordingly, Data Drift refers to the situation where production input data increasingly differs from the original training dataset over time. Model Quality Drift refers to degradation in model prediction quality over time. Drift monitoring in AWS was previously supported via SageMaker Model Monitor, but now relies on custom-built solutions via open-source tooling (ex: MLFlow).

GenAI Drift#

Given the stochastic and unstructured nature of generative AI output, foundation model evaluation is a bit more tricky. One suitable practice is to maintain a fixed prompt / evaluation dataset and run at fixed intervals. The response is then evaluated via humans / other LLMs, or compared to ground-truth response values (when available). Bedrock Model Evaluations assists with this functionality.

Other Dev Considerations#

CI/CD in AWS#

Continuous Integration / Continuous Delivery (CI/CD) is a collection of software development practices which automates the building, testing, and release of code into production in a structured and consistent fashion.

There are many basic tools pertaining to CI/CD in AWS:

CICD

Note that CI/CD concepts and tools generalize to AI artifacts, which are files pertaining to machine learning projects (e.g., pickled models, prompt templates, etc.). Additionally, Bedrock Knowledge Bases provides a StartIngestionJob sync feature to re-process added, modified, or deleted documents within an updated knowledge base.

EventBridge#

Amazon EventBridge is a service used to schedule Cron jobs (scheduled script execution) and react to event patterns. EventBridge links source events to downstream actions. For example…

EventBridge also supports integration with partner services such as Zendesk and Datadog.

Step Functions#

Amazon Step Functions is a serverless orchestration service which enables developers to construct and run multi-step application workflows involving multiple different AWS services. It can automate many aspects of the machine learning project lifecycle, including training or tuning a model.


(all information obtained from AWS Certified Machine Learning Engineer Associate: Hands On! course on Udemy)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts