top of page
  • Arash Heidarian

Toward MLOps - Part 3: DevOps and MLOps Dynamic Duo (CI/CD/CT)

Updated: Nov 27, 2023



Table of contents


Introduction

In part 1 and part 2 of "Toward MLOps" series, I explained the significance of ETL, DataOps, and Feature Stores. This post further explores the practical application of Continuous Training (CT), Continuous Integration (CI), and Continuous Deployment (CD) within the process of data science projects. In a previous post titled "MLOps .vs. DevOps," I briefly outlined the distinctions between MLOps and DevOps, shedding light on the varied applications of Development, Testing, and Production stages in both domains. This post however expands on the necessity of integrating both MLOps and DevOps methodologies, illustrating how these two concepts can work in tandem to establish a robust and comprehensive architectural framework.


Bridging MLOps and DevOps

Continuous Training (CT) in MLOps and the Development (Dev), Testing (Test), and Production (Prod) stages in MLOps can be integrated with Continuous Integration and Continuous Deployment (CI/CD) in DevOps to streamline the end-to-end process of developing and deploying machine learning models. Here's an overview of how they work side by side:



Figure 1. Dev Test Prod in DevOps and MLOps

CT in MLOps

  • In MLOps, Continuous Training involves the iterative and automated process of updating and improving machine learning models as new data becomes available.

  • Data scientists develop and train models using the latest datasets, and the training process is automated to ensure models are always up-to-date and optimized.


Dev, Test, Prod Stages in MLOps

  • Dev involves the creation and initial testing of machine learning models. Data scientists experiment, prototype, and iterate on models in this stage.

  • Test includes rigorous evaluation of models to ensure their accuracy, robustness, and reliability. It involves various testing environments and datasets to simulate real-world conditions.

  • Prod is the deployment stage where the finalized model is integrated into the operational system for real-world use.

Integration with CI/CD in DevOps

Continuous Integration (CI):

  • Data scientists commit their code, including model development and training scripts, to a version control system (e.g., Git).

  • Automated CI pipelines trigger, running tests, and integrating code changes into a shared repository. This ensures that changes do not break the existing functionality of the models.

Continuous Deployment (CD):

  • Once the models pass CI tests, the CD pipeline automates the deployment process.

  • Deployed models move through different environments (Dev, Test, Prod) with automated testing at each stage.

  • CD ensures that models are deployed consistently and reliably across different environments.


Collaboration of MLOps & DevOps

  • Data scientists work in collaboration with DevOps engineers to define CI/CD pipelines that encompass both code and model artifacts.

  • CT and the MLOps stages align with the CI/CD pipeline, allowing for a unified workflow where model training, evaluation, and deployment are part of the automated development and deployment process.\


Monitoring and Feedback Loop

  • Continuous monitoring of deployed models in production is crucial. DevOps practices, such as monitoring and logging, are extended to include model performance metrics.

  • Feedback loops are established, allowing data scientists to receive insights into model performance in real-world scenarios. This feedback informs further iterations and updates.


Versioning 

Versioning in MLOps and code versioning in DevOps share common principles, but they address different aspects of the development process. Let's explore the distinctions.


Figure 2. Versioning through CI/CD/CT process

Model Versioning in MLOps

In MLOps versioning involves tracking and managing different iterations or versions of machine learning models and/or datasets. 

Components: Model accuracy, hyperparameters, dataset used for model training, and any other artifacts crucial for reproducing a specific model plays a role in model versioning. 

Significance

  • Reproducibility: Ensures the ability to reproduce and replicate model training and results at any given point in time.

  • Model Auditing: Facilitates auditing, model comparisons, and rollback capabilities, essential for debugging and performance analysis.

Repository & Tools: Dedicated repositories or artifact storage solutions (e.g. Datalakes) may be used for storing large model files and associated metadata. Cloud platforms like AWS, GCP and Azure are equipped with model versioning tools where all metadata and details about different versions of models are visible, and it is easy to make comparisons and make decisions. Continuous Training : Code model training can get  automated via schedule, or detected changes/drafts/updates in dataset.

Deployment: Successfully build and registered models are evaluated in the Test environment first. If the objectives (model accuracy, performance,...) are in acceptable range, MLOps engineer can approve the new version to be moved for deployment in prod. 


Code Versioning in DevOps

Code versioning in DevOps involves tracking changes to source code and associated files.These are the scripts developed by data scientists for data preparation, model training, and model evaluation. Any change in codes may or may not lead to any change in model version necessarily. When the script change impacts the model accuracy for instance, we act on model versioning at MLOps level. However at code level, every single change should be tracked. 

Components: Source code files, scripts, configuration files, and documentation.

Significance

  • Collaboration: Enables collaboration among development teams by managing changes, resolving conflicts, and maintaining a consistent codebase.

  • Traceability: Provides a detailed history of code changes, aiding in debugging, accountability, and understanding the evolution of the software.

Repository & Tools: Git is a popular version control system used in DevOps for tracking changes, branching, merging, and collaborating on code. Common branching strategies include feature branches, release branches, and main branches, each serving specific purposes in the development lifecycle.Continuous Integration: Code changes trigger automated build and test processes through CI/CD pipelines.

Deployment: Successful code changes are deployed through CD pipelines to different environments (Dev, Test, Prod).


Key Differences

  • Artifacts: In MLOps, the primary artifacts are machine learning models and related files, whereas, in DevOps, the focus is on source code and associated files.

  • Complexity: Model files can be large and complex, requiring specialized versioning solutions, while code versioning typically deals with smaller text-based files.

  • Reproducibility vs. Collaboration: Model versioning heavily emphasizes reproducibility, while code versioning emphasizes collaboration, traceability, and deployment.

  • Tools and Repositories: MLOps may leverage specialized artifact repositories, while DevOps predominantly uses general-purpose version control systems like Git.


Although both MLOps and DevOps employ versioning practices, they cater to different aspects of the development lifecycle, reflecting the specific needs and challenges of machine learning model development and traditional software development, respectively.


Testing 

Testing in MLOps and DevOps shares some common principles, but the nature of the artifacts being tested and the specific challenges in each domain lead to some key differences. Let's explore how testing differs in MLOps and DevOps.



Figure 3. Testing through CI/CD/CT process

Testing in MLOps

1.Data-Centric Testing

  • Challenge: The primary focus in MLOps is on the data used for training and evaluating machine learning models.

  • Testing Aspect: Data quality, consistency, and relevance are crucial. Testing involves validating that the training data is representative of the real-world scenarios the model will encounter.

2.Model Evaluation:

  • Challenge: Machine learning models have unique evaluation metrics based on accuracy, precision, recall, F1 score, etc.

  • Testing Aspect: Model evaluation involves validating that the model performs well on unseen data. Techniques like cross-validation and holdout sets are commonly used.

3.Concept Drift and Adaptability:

  • Challenge: Models need to adapt to changes in data distributions over time (concept drift).

  • Testing Aspect: Continuous monitoring and testing for concept drift to ensure models remain effective as data evolves.


4.Bias and Fairness Testing:

  • Challenge: Ensuring models are fair and unbiased is crucial in ethical machine learning.

  • Testing Aspect: Tests for bias and fairness are conducted to identify and address any disparities in model predictions across different demographic groups.


5.Integration with DataOps:

  • Challenge: Data pipelines and data transformations impact model inputs.

  • Testing Aspect: Ensures that data preprocessing and transformations are consistent and do not introduce errors that could affect model performance.


Testing in DevOps

1.Code-Centric Testing:

  • Challenge: DevOps primarily deals with testing application code and infrastructure scripts.

  • Testing Aspect: Focus on unit testing, integration testing, system testing, and acceptance testing to ensure the reliability and functionality of the software.


2.Continuous Integration (CI) Testing:

  • Challenge: Frequent code changes require rapid and automated testing.

  • Testing Aspect: CI pipelines automatically run tests on each code commit to identify and address integration issues early in the development process.


3.Infrastructure as Code (IaC) Testing:

  • Challenge: Infrastructure changes are often coded (IaC) and need rigorous testing.

  • Testing Aspect: Ensures that changes to infrastructure scripts (e.g., using tools like Terraform) do not introduce vulnerabilities or misconfigurations.

4.Deployment Testing:

  • Challenge: Smooth and reliable deployment processes are critical for continuous delivery.

  • Testing Aspect: CD (Continuous Deployment) pipelines involve testing in staging environments before promoting changes to production, ensuring deployments are error-free.


5.Security and Compliance Testing:

  • Challenge: Ensuring the security and compliance of the software.

  • Testing Aspect: Security testing, vulnerability scanning, and compliance checks are integrated into the CI/CD pipelines to identify and mitigate security risks.



Conclusion

In conclusion, DevOps and MLOps exhibit differences in versioning strategies, development and testing practices, choice of tools, and operational considerations. While DevOps primarily focuses on versioning source code and orchestrating traditional software development lifecycles, MLOps extends this paradigm to versioning machine learning models and managing


Figure 4. MLOps and DevOps sub-processes

The collaboration of both MLOps and DevOps is imperative for effective data science work. DevOps provides the foundation for stable and scalable infrastructure, seamless deployment, and rigorous script testing, while MLOps contributes expertise in managing data pipelines, model versioning, and adapting to the evolving nature of machine learning models. This collaborative approach ensures a comprehensive and efficient end-to-end workflow, aligning development and operations to deliver impactful and reliable data-driven solutions.




22 views

Recent Posts

See All

Σχόλια


bottom of page