0% found this document useful (0 votes)
2 views11 pages

Unit II - Lecture Notes

kkkkkkkkkkkkkk

Uploaded by

kirthigaaiml
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Unit II - Lecture Notes

kkkkkkkkkkkkkk

Uploaded by

kirthigaaiml
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MLOps FOR CONTAINERS AND EDGE DEVICES

Containerization in MLOps

Containerization is the process of bundling an application (ML Model) and its dependencies, libraries,
and configuration files into a self-contained unit that can run across different operating environment.
On the other hand, orchestration is the process of managing multiple containers across different
machines and environments. It is achieved by automating and managing workflows and pipeline
infrastructure with collaborative and simple interfaces.

Why is Containerization important for MLOps?

Containerization helps in managing end-to-end machine learning pipelines in production, thus help in
meeting MLOps goals. Containerization is an important MLOps concept that supports development,
deployment, and maintenance of machine learning applications. It enables the delivery of reliable,
scalable, and efficient machine learning solutions.

A container can run on any machine that has a compatible container runtime environment like Docker.
Containers are isolated from each other and from the host system, which means they have their own file
system, network, memory, and CPU resources. This ensures that the application runs consistently and
reliably across different environments, such as development, testing, and production. In other words,
containerization helps in achieving virtualization.

Containerization is important for MLOps as it helps achieving environment independence. It supports


MLOps best practices by streamlining the ML lifecycle, from data collection and preprocessing, to
model development and experimentation, to model deployment and monitoring. Containerization helps
ML practitioners to:

 Isolate and standardize the environment for each machine learning project.

 Reproduce and share the results of machine learning experiments.

 Automate and orchest standardize the workflow of machine learning pipelines.

 Optimize the resource utilization and performance of machine learning applications.

One of the main challenges of MLOps is to ensure that the ML models can be reproduced, validated,
and deployed in a scalable and robust way. This requires managing the complex dependencies and
configurations of the ML stack, such as libraries, frameworks, tools, data sources, and hardware.
Containerization can help solve this problem by encapsulating the ML models and their dependencies
into portable and standardized containers that can be easily deployed on any platform that supports
containers. This reduces the risk of compatibility issues, configuration errors, and performance
degradation.

What is an Edge Device?

Edge devices are pieces of equipment that serve to transmit data between the local network and the
cloud. They are able to translate between the protocols, or languages, used by local devices into the
protocols used by the cloud where the data will be further processed. Local devices use protocols like
Bluetooth, wi-fi, Zigbee, and NFC while the cloud uses protocols like AMQP, MQTT, CoAP, and
HTTP. In order for IoT data to move between the cloud and local devices, an edge device—like a smart
gateway—translates, sorts, and securely transfers information between the two sources.

Without an edge device, these types of data would be incompatible and unable to reach cloud services
for deep analysis. The Machine Metrics Edge is one security-conscious example of this technology. It
can be configured as an Edge Pro to support up to 50 machines over a network, or installed near, and
powered by, a single machine as an Edge.

Types of Edge Devices

There are many different types of edge devices. These devices use IoT or industrial IoT to transmit data
to the cloud or perform functions directly at the edge. Edge devices also transmit data across the internet.

There are two types of edge devices – traditional and intelligent edge. Traditional edge devices transfer
data over a secure network with little or no processing capability. Intelligent edge devices are smart
devices that can perform edge computing tasks near the data source for industrial automation.

Traditional Edge Devices

Traditional edge devices include:

 Edge Routers: Edge routers connect multiple packet transmission networks. They manage data
traffic to an IP address so multiple devices can operate using a single internet connection. For
a Local Area Network (LAN), a router is responsible for several devices within a specific
geography.
 WAN Devices: Wide Area Network (WAN) devices extend over large areas and can even be
global. WAN devices allow organizations to work seamlessly across the enterprise regardless
of location.
 Routing Switches: Routing switches are used in situations like industrial IoT. They can perform
many of the same functions as a router but also allow connections across different devices.
 Firewalls: Firewalls monitor all network traffic for security. They contain rules-based
functionality and can be configured to block data traffic deemed harmful by the rule set.
 Multiplexers: Multiplexers merge data from multiple data sources over a single signal. They’re
integrated access devices (IAD) that help automation systems and advanced IoT networks
perform efficiently.

Intelligent Edge Devices

Intelligent edge devices are used in advanced IoT and industrial IoT to connect the entire system's
onboard processing or analytics capabilities. This functionality enables smart factories and IIoT
platforms to facilitate advanced automation and analytics.
Intelligent edge devices include:

 Sensors: Sensors measure a condition or event, trigger action, and route data to the next
destination. Sensor types are almost limitless and include GPS, motion, optical, temperature,
humidity, vibration, and more.
 Actuators: Actuators act as the physical connectivity bridge between electronic devices like
sensors and the physical movement required on a machine. Actuators take the sensor signals
and instructions from intelligent edge devices and trigger actions using electric, air, or hydraulic
power.
 IoT Gateways: IoT gateways connect multiple sensors and other devices to cloud computing
platforms for analytics, computing, processing, and storage.
 M2M Devices: M2M devices connect equipment or machines to transfer data and facilitate
automation.
Together, traditional and intelligent edge devices can be used in a platform to connect assets and
machinery.

How Does an Edge Device Work?

An edge device works by being near the source of the data it manages. Devices like embedded or added
sensors act as the device layer, acquiring data and sending it to the edge computing device or a cloud
computing platform.

If the data is informational or transactional, the device may send it directly to the cloud for storage. Or,
based on parameters, it may send it to an edge device for processing and instructions and then forward
the instructions to an actuator to trigger a response. Devices in M2M systems can be linked to perform
tasks sent from an edge computing device or an edge network.

In large connected systems, data flow may be controlled by a router. Using extended access to devices
within a system, a combination of sensors, actuators, routers, switches, and edge computing devices can
be controlled and accessed locally or over WAN to provide visibility and the capability to act over long
distances.

What is edge MLOps?

Edge machine learning operations (MLOps) is the set of practices and techniques used to automate and
unify the various parts of machine learning (ML), system development (dev), and system operation
(ops) for edge deployments. Such activities include data collection, processing, model training,
deployment, application development, application/model monitoring, and maintenance. Edge MLOps
follows many of the same principles of MLOps but with a focus on edge computing.

Team effort
In most cases, implementing an edge MLOPs framework is not the work of a single person. It involves
the cooperation of several teams. These teams can include some of the following experts:

 Data scientists - analyse raw data to find patterns and trends, create algorithms and data models
to predict outcomes (which can include machine learning)
 Data engineers - build systems to collect, manage, and transform raw data into useful
information for data scientists, ML researchers/engineers, and business analysts
 ML researchers - similar to data scientists, they work with data and build mathematical models
to meet various business or academic needs
 ML engineers - build systems to train, test, and deploy ML models in a repeatable and robust
manner
 Software developers - create computer applications and underlying systems to perform specific
tasks for users
 Operations specialists - oversee the daily operation of network equipment and software
maintenance
 Business analysts - form business insights and market opportunities by analyzing data

Edge AI lifecycle

The edge AI lifecycle consists of the steps required to collect data, clean that data, extract required
features, train one or more ML models, test the model, deploy the model, and perform necessary
maintenance. Note that these steps do not include some of the larger project processes of identifying
business needs and creating the application around the model. In edge MLOps we can automate many
of these steps to make the flow through this process easier and without human intervention.

Principles

Edge MLOps is built on three main principles: version control, automation, and governance.

 Version control

In software development, the ability to track code versions and roll back versions is incredibly
important. It goes beyond simply “saving a copy,” as it allows you to create branches to try new features
and merge code from other developers. Tools like git and GitHub provide robust version control
capabilities. While these tools can be used for files and data beyond just code, they are mostly focused
on text-based code. Versioning data can be tricky, as the storage requirements increases with the amount
of data. You likely also want to version various ML pipelines in addition to the training/testing code
and model itself. Edge Impulse offers the ability to version control individual blocks as well as
your entire project and pipeline.

 Automation
Automating anything requires an initial, up-front investment to build the required processes and
software. In cases where you need to use that process multiple times, such automation can pay off in
the long run. Setting up automated tasks is a crucial step in edge MLOps, as it allows your teams to
work on other tasks once the automation is built. Almost anything in the edge AI lifecycle can be
automated, including data collection, data cleaning, model training, and deployment. These often fall
into one of the following categories:

 Continuous collection - Data collection happens continuously or triggered by some event.


 Continuous training - Feature extraction and model training/testing can occur autonomously.
 Continuous integration - Any code changes checked into a repository can trigger a series of unit
and system tests to ensure correct operation before the code is merged into the main application.
 Continuous delivery - Software is created in short cycles and can be reliably released to users
on a continuous basis as needed. Some deployment steps in this stage can be automated.
 Continuous monitoring - Automated tools are used to monitor the performance and security of
an application or system to detect problems early to mitigate risks.

The development teams can decide how such automated processes are triggered. Examples of triggers
include:

 User-requested - the user makes a request to update or rebase line the model
 Time - one or more steps in the lifecycle can be executed on a set schedule, such as once per
day or once per month
 Data changes - the presence of newly collected data can trigger a new lifecycle execution to
clean the data, train a model, and deploy the model
 Code change - a new version of the application might necessitate a new model and thus trigger
any of the collection, cleaning, training, testing, or deployment processes
 Model monitoring - issues with deployed models (such as model drift) might require any or all
of the lifecycle to execute in order to update the model

 Governance

Part of edge MLOps includes ensuring that your data and processes adhere to best practices and
complies with any necessary regulations. Such regulations might include data privacy laws, such
as HIPAA and GDPR. Similar rules are currently being enacted around AI, such as the EU AI act. Be
sure to become familiar with any potential governing regulations around data, privacy, and AI! The
rules can vary by country and specific technology usage (e.g. medical vs. consumer electronics). In
addition to adhering to laws, you should check for fairness and bias in your data and model. Bias can
come in many different forms and greatly impact your resulting model. The popular computer science
phrase garbage in, garbage out applies here: if you train a model on biased data, the model will reflect
that bias. Finally, like with any computer system, you should design and implement best security
practices to ensure:
 Confidentiality to protect sensitive data from unauthorized access
 Integrity to guarantee that data has not been altered
 Availability of data to authorized users when needed
Machine learning can involve lots of (potentially personal) data that you must use and control carefully.
Edge computing devices should also be secured to limit potential intrusion risks. For digging deeper
into security, we recommend checking out CISA’s guides on best practices and Amazon’s ultimate IoT
security best practices guide. Hiring or consulting with a cybersecurity expert is also highly advised.
As a good steward of AI, it is your responsibility to ensure that your systems comply with laws and
regulations, data and models are free from bias, and devices are secured from unauthorized access.

Containers for Managed ML systems

Containers for Managed Machine Learning (ML) systems package model code, dependencies, and
runtimes into standardized, isolated units. They ensure consistency, portability, and reproducibility
across development, training, and production environments.

Popular Container Runtimes & Frameworks

Building robust ML containers requires specific bases designed to leverage accelerated hardware.

 NVIDIA GPU-Optimized Containers: Leverage the NVIDIA Container Toolkit to seamlessly


expose GPUs inside containers for deep learning frameworks like PyTorch and TensorFlow.
 Base Images: Utilize lean and verified images (e.g., or NVIDIA's ) to reduce container bloat
and security vulnerabilities.
 Serving Containers: Utilize pre-configured, high-performance servers like Triton Inference
Server or TorchServe to efficiently manage concurrent model requests and dynamic batching.

Managed Container Orchestration Services

Instead of manually deploying software containers, managed ML platforms automate scaling,


networking, and cluster infrastructure.

 Cloud-Native Managed MLOps Platforms: Services such as Amazon SageMaker and Vertex
AI (Google Cloud) provide fully managed environments. They provide pre-built deep learning
containers (DLCs) tailored for training and inference, eliminating infrastructure overhead.
 Kubernetes Orchestration: Managed services like Amazon EKS and Google Kubernetes Engine
(GKE) automate the provisioning, updating, and scaling of Kubernetes clusters. They are often
augmented with add-ons like KubeFlow for building end-to-end ML pipelines.
 Serverless Containers: Platforms like AWS Fargate and Azure Container Apps allow you to
deploy ML web endpoints without managing servers. They are ideal for auto-scaling
unpredictable workloads on a pay-per-use basis.
CD for Machine Learning Models

Continuous Delivery and Continuous Deployment (CD) for Machine Learning (ML) is an automated
process within MLOps that packages, tests, and safely releases validated ML models into production
environments without manual intervention. Unlike traditional software CD which only handles code,
ML CD must simultaneously manage code, data changes, and trained model artifacts.

Core Components of ML CD

Implementing a robust CD pipeline for machine learning requires a shifting mindset from traditional
DevOps to MLOps Guide principles.

 Model Registry Integration: The CD pipeline monitors a central model registry (like MLflow
or Google Vertex AI). When a newly trained model is marked as "Approved", it automatically
triggers the deployment sequence.
 Continuous Training (CT): A critical, ML-specific precursor to deployment. The CD system
doesn't just deploy once; it automates retraining schedules or triggers updates based on
performance drops or data drift.
 Infrastructure as Code (IaC): Automates the setup of specialized hardware environments,
ensuring that matching GPU configurations, dependency packages, and underlying container
systems are instantiated identically every time.

Production Deployment Strategies

Because serving live predictions carries risk, the CD pipeline uses staged deployment strategies to
prevent systemic failures:

 Shadow Deployment: The new model runs parallel to the production model. It receives real-
world input and generates predictions, but its outputs are only logged for evaluation and not
sent to the end user.
 Canary Release: The updated model is exposed to a tiny fraction of live user traffic (e.g., 5%).
If its latency and error rates remain stable, traffic is incrementally scaled up to 100%.
 Blue-Green Deployment: Two identical environments run simultaneously. The stable model
runs on "Blue" while the new model is deployed to "Green". Once "Green" passes health
checks, traffic is instantly routed over.

Popular CD Tools for Machine Learning

Teams often stitch together classic DevOps tools with dedicated ML infrastructure to achieve full
automation:
 Orchestration & Workflow: Tools like GitHub Actions, GitLab CI/CD, and Circles automate
the overall event triggers and pipeline steps.
 Data & Model Versioning: Open-source DVC (Data Version Control) maps heavy dataset and
model binaries directly into Git-like developer workflows.
 Cloud Ecosystems: Fully managed environments like Amazon SageMaker (via AWS Code
Pipeline) and Google Vertex AI provide native, compliant, and highly scalable inference
endpoints.

Packaging for ML Models

Packaging an ML model means bundling the trained model, its dependencies, and its runtime
application logic into a single, portable artifact. This ensures your model executes reliably, efficiently,
and identically in development, testing, and production environments.

1. Model Serialization (The Core File)

Before it can be packaged, the model weights and architecture must be serialized into a binary format.

 ONNX: The standard for cross-framework portability. It lets you train in PyTorch and deploy
in environments like C++ without compatibility issues.
 Safe tensors: Developed by Hugging Face, this format is memory-efficient and secure,
preventing arbitrary code execution found in older methods like Pickle.
 TensorFlow Saved Model: The native format for the TensorFlow ecosystem, storing the
computation graph, weights, and serving logic.

2. Environment Dependencies & Logic

The packaging layer encapsulates exactly how the model will be invoked and run.

 Entry Script (e.g., ): Handles preprocessing incoming requests, passing data to the model, and
postprocessing the output.
 Dependency Managers: Captures library versions using file.

3. Packaging Formats

How you deliver the model depends on your infrastructure and latency requirements.
 Containerization (Docker): The industry standard. You bake the model, dependencies, and a
web framework (e.g., FastAPI) into a lightweight Docker container for easy deployment to
Kubernetes or the cloud.
 Model Frameworks (BentoML, MLflow): Tools that streamline packaging by letting you
declare preprocessing, inference, and routing into a single standard bundle.
 Python Packages: Compiling the model and its scripts into a standard package (via ) to be stored
in an artifact repository.

4. Documentation

A complete package includes documentation on how the model should be used.


 Model Cards: Detail the model's intended use, limitations, biases, and evaluation metrics.
 API Definitions: Describe the expected input and output data structures (often documented
using Swagger/open API specs).

Infrastructure as Code for CD of ML Models - Using Cloud Pipelines

Infrastructure as Code (IaC) ensures that the underlying cloud environments supporting your
Machine Learning (ML) Continuous Deployment (CD) pipelines are repeatable, safe, and
scaled automatically. Unlike traditional software systems, an MLOps CD pipeline must deploy
not just code, but also automated data processing engines, model registries, training instances,
and production inference endpoints.

The Architecture: IaC + Cloud Pipelines

To fully automate the continuous deployment of ML models, your IaC configuration (typically
written in HashiCorp Terraform or Pulumi ) must provision three distinct environments
managed by your cloud-native orchestrator:

Core Components to Provision Using IaC

1. Machine Learning Pipelines (Training & Orchestration)


Instead of manually triggering scripts, use IaC to spin up managed serverless pipeline
platforms.

 GCP: Provision Google Cloud Vertex AI Pipelines using the Vertex AI resources block in
Terraform.
 AWS: Build Amazon SageMaker Pipelines to organize data processing and model training
steps into structured workflows.
2. Storage & Model Registry (The Artifact Layer)

Your pipeline needs secure, version-controlled storage to save code containers, dataset
versions, and trained mathematical weights.
 Provision container stores like AWS Elastic Container Registry (ECR) or Google Cloud
Artifact Registry via code.
 Configure cloud storage buckets (Amazon S3 / Google Cloud Storage) with strict version
control enabled to prevent unrecorded data changes.
3. Serving Infrastructure (The Live Endpoint)

The CD pipeline relies on pre-configured, production-ready compute instances optimized for


machine learning serving.

 Use IaC to establish compute clusters like Google Kubernetes Engine (GKE) or Amazon EKS
with Horizontal Pod Autoscaling (HPA) configured for spike traffic.
 Alternatively, deploy serverless frameworks like Google Cloud Run or AWS SageMaker
Serverless Endpoints for lower operational overhead.

Implementing CD Step-by-Step

Step 1: Commit IaC alongside ML Code

Store your cloud infrastructure definitions in the same repository as your model training code
(and). This links infrastructure modifications directly to structural model upgrades

Step 2: Continuous Integration & Validation

Whenever a data scientist pushes code changes or flags new incoming datasets, your cloud
runner (e.g., GitHub Actions or Google Cloud Build) executes checking phases:

 Linting: Scans Python logic and Terraform syntax ().


 Dry Run: Previews environment creation via inside a safe branch.

Step 3: Progressive Deployment (CD)

Once the code passes data quality and unit tests, the main deployment branch takes over:

1. Apply Infrastructure: executes inside the cloud pipeline runner to modify or update endpoints
without system downtime.
2. Trigger retraining: The updated cloud pipeline pulls fresh data, trains the model, and passes
metrics to your registry.
3. Canary Releases: The IaC layout forces traffic-splitting rules, directing only 10% of real users
to the new model endpoint initially to verify operational stability.
Example: Deploying an ML Service Pipeline (Terraform)

You might also like