MLOps: Automated Machine Learning Model using DevOps

Anshraj Shrivastava
6 min readJun 27, 2020

--

https://www.c-sharpcorner.com/UploadFile/BlogImages/11122019223851PM/image1.png

Machine Learning Operations (MLOps) is based on DevOps principles and practices that increase the efficiency of workflows. For example, continuous integration, delivery, and deployment. MLOps applies these principles to the machine learning process, with the goal of:

  • Faster experimentation and development of models
  • Faster deployment of models into production
  • Quality assurance

Task:

Aim: Developing an Automated Environment so that whenever the developer pushes a machine learning code on Github, this will train it and predict its accuracy. Also, Tweak it to get the desired accuracy.

Technologies used: Github, Jenkins, Docker, RHEL-8, TensorFlow, DeepLearning.

Pre-requisites:

  1. RHEL-8 with Docker, Jenkins, and Python3.6 installed.
  2. Github account
  3. Jenkins with Git plugin, Github plugin, SCM plugin.

Initial steps:

  1. Created a repository on Github.
  2. Github repository will be containing: The main program, tweaker program, sending mail program, and an accuracy file.
  3. Create an image for training Our Model.

Docker Image using Dockerfile:

Make a directory and create a file name “Dockerfile” without quotes. And write as shown below:

Dockerfile

Now to build this image write following command on terminal:

#  docker build -t mlops_setup:v3 /mlops/

The complete Automated Environment will be done by 6 Jobs in Jenkins.

Job #1: Developer’s Code Fetch

Whenever Developer push to the Github repository then Jenkins will fetch the code from it and store it in the local directory.

This job would be triggered automatically whenever there is a push on the Github Dev branch.

Job #2: Launch Container and Deploy

By looking at the code or program file, this will divide code into groups i.e based on its type( CNN, sklearn, etc) and will automatically start its training in a container of the image that we build above.

This job would be triggered automatically whenever the Job1 is completed successfully.

Job #3: Test

This job will find the accuracy achieved by the model.

This job would be triggered automatically whenever the Job2 is completed successfully.

Job #4: Accuracy Check

This will check if accuracy was less than 90% then it would tweak the model as well as send a mail to the developer too.

Tweaking of the model would be done by the next job.

This job would be triggered automatically whenever the Job3 is completed successfully.

Job #5: Model tweaking

This will tweak the model and re-train it and checks accuracy again.

When the desired accuracy is achieved it will notify by sending a mail to the developer.

Job #6: Monitor Containers

This will keep an eye on the container and if in a case due to some reason the container stops it will re-launch it again.

Screenshots:

  1. Create a Github Repository.
https://github.com/rajansh87/MLOps_Task3

2. Create a list view mlops for this task inside which all my jobs would be running, inside this a job called “Job1_DownloadFromGithub” as a freestyle project in Jenkins.

3. Give Source for the code from Github. So it will clone the repository to Jenkins workspace.

4. Build triggers are used to start this job, and here I used Poll SCM and gave that at every minute there will be a trigger for this job.

5. This job will execute this code that consists:

It will copy everything from workspace to a directory called “/task3” at location “/root/”.

6. Create Job2_divideingrp as a freestyle project in Jenkins.

7. Build triggers are used to start this job, and here this job will be triggered only after the stable built of Job1.

8. This job will execute this code that consists:

Checks if the code belongs to the CNN category and launches a container. Also, mounts the volume as the directory where our cloned data is present to its “/root/task3/”.

9. Create Job3_trainNpredict as a freestyle project in Jenkins.

10. Add Build triggers as “build after other projects are built” as Job2.

11. This will execute/train the model.

12. Create Job4_accuracyCheck as a freestyle project in Jenkins.

13. It will be triggered after Job3 is completed.

14. It will send a mail to a developer using a mail.py file. This mail.py file code is downloaded from geeksforgeeks.com for sending mail using python.

15. Create Job5_retrain as a freestyle project in Jenkins.

16. It will be triggered after Job4 is completed.

17. This will start the tweaker program of the model.

18. Create Job6_failure_check as a freestyle project in Jenkins.

19. It will be triggered after Job2 is completed.

20. This will search for whether the container is running or not. else launch a new container.

21. And All is done and your Automated Environment is ready this is the final view.

Build Pipeline View

22. Received mail:

So, Now Everything is ready and whenever the developer will push some code on Github repository it will start the automated MLOps system with testing and notification to the developer.

--

--

No responses yet