<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bhagat Khemchandani on Medium]]></title>
        <description><![CDATA[Stories by Bhagat Khemchandani on Medium]]></description>
        <link>https://medium.com/@bhagatk?source=rss-f5d3bfd2b38a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7ZDLtCC_fm-IBL3i</url>
            <title>Stories by Bhagat Khemchandani on Medium</title>
            <link>https://medium.com/@bhagatk?source=rss-f5d3bfd2b38a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 18:14:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bhagatk/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[MLOps — Dataset versioning using DVC and the use of EFS]]></title>
            <link>https://bhagatk.medium.com/mlops-dataset-versioning-using-dvc-and-the-use-of-efs-a340556f412?source=rss-f5d3bfd2b38a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a340556f412</guid>
            <category><![CDATA[kubeflow-pipelines]]></category>
            <category><![CDATA[dvc]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[dataset-versioning]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Bhagat Khemchandani]]></dc:creator>
            <pubDate>Wed, 27 Apr 2022 04:46:03 GMT</pubDate>
            <atom:updated>2022-04-27T04:46:40.822Z</atom:updated>
            <content:encoded><![CDATA[<h3>MLOps — Dataset versioning using DVC and EFS in Kubeflow Pipelines</h3><h3>Background</h3><p>Machine Learning (ML) models often require large datasets of text documents or images that are used throughout the ML models development cycle: training, validation, and testing. Like source code, these datasets together with the information on how they are used for development need to be tracked and versioned to <strong>ensure reproducibility of the ML models</strong> and <strong>consistency</strong> of ML workflows across teams.</p><p>A common practice is to store the dataset on AWS S3/HDFS, sometimes with sub-folders for different versions.<br>This is not an effective approach (<strong>data is not immutable</strong>) and not one that has the consistency to be shared across different teams.</p><p>Instead, datasets are better tracked if versioned in the same way as source code, where a version <strong>unambiguously</strong> refers to the same data and one can always access the particular version of data that has been used to develop an ML model, therefore allowing to reproduce it.</p><p>This is where DVC comes in, enabling sharing and version control of large datasets and model files used by data science teams.</p><h3>DVC in a nutshell</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*TFu6YQQDG26jtm6VLikBxQ.png" /><figcaption><a href="https://christophergs.com/machine%20learning/2019/05/13/first-impressions-of-dvc/">Source</a></figcaption></figure><p>DVC (Data Version Control) is an open-source application for machine learning data and model version control. <strong>Think Git for data</strong>: the DVC syntax and workflow patterns are very similar to Git, making it intuitive to incorporate into existing repositories. <a href="https://dvc.org/features">Its features</a> go beyond data and model versioning and include pipeline support or experiment tracking.</p><p>Let us now dive into how DVC is used in Kubeflow pipelines. Read more about DVC <a href="https://dvc.org/doc/start">here</a></p><h3>Repository structure</h3><p>In order to use the MLOps platform in a consistent fashion, each repository must contain :</p><blockquote>- data (contains all data points versioned using DVC. This folder is not present when you clone the repository but created when you pull data). This is managed by DVC.<br>- data.dvc (metadata file managed by DVC about the data folder)<br>- data-split (contains reference lists of subsets of the data e.g. training set for the 6.4K data subset or testing set for 100K data. The data itself is stored in the data folder)</blockquote><h3>Fetching datasets and Sharing them across pipeline stages</h3><p>Before we trigger model training, we need to provision the datasets. This is done by a dedicated <em>dataset preparation </em>stage in kubeflow pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7xG4QwqUGYWGcrVkeDvo6Q.png" /><figcaption>Prepare Dataset stage</figcaption></figure><p>This stage clones the GitHub repository pulls the dataset using <em>dvc pull, </em>and makes it available for the training stage. <br>However, there is a catch, each stage/container in a pipeline may run on any of the nodes in the Kubeflow/Kubernetes cluster. This poses the challenge of sharing data across containers/nodes.</p><h4>Amazon Elastic File System to the rescue</h4><p>EFS enables us to build applications that need shared access to file data. EFS is (and always has been) simple and serverless: you simply create a file system, attach it to any number of EC2 instances, <a href="https://aws.amazon.com/blogs/aws/new-a-shared-file-system-for-your-lambda-functions/">Lambda functions</a>, or <a href="https://aws.amazon.com/premiumsupport/knowledge-center/ecs-fargate-mount-efs-containers-tasks/">containers</a>, and go about your work. EFS is a highly durable, scalable, and consistent file system.</p><p>It is for the above reasons I decided to leverage EFS for sharing data across containers.</p><p>As you can see in the above diagram, we are mounting volume in the first stage of the pipeline. This finds/creates a <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/">K8s PVC</a> and later mounts it on data preparation and training containers.</p><p>Snippet to create/find a PVC in kubeflow pipeline</p><pre>vop = dsl.VolumeOp(<br>    name=f&quot;data-sharing-pvc&quot;,<br>    resource_name=f&quot;data-sharing-pvc&quot;,<br>    storage_class=&quot;&quot;,<br>    size=&quot;10Gi&quot;,<br>    modes=dsl.VOLUME_MODE_RWM,<br>).set_display_name(&quot;Mount Volume&quot;)</pre><p>Snippet to mount the above volume on any container/stage</p><pre>prepare_data = dsl.ContainerOp(<br>    name=&quot;preparedata&quot;,<br>    image=,<br>    arguments=[<br>        &quot;data&quot;,<br>        data_repository,<br>        data_repository_git_sha,<br>        data_directory,<br>        data_split_directory,<br>        data_split_name,<br>    ],<br>    <strong>pvolumes={&quot;/mnt&quot;: vop.volume},</strong><br>).set_display_name(&quot;Prepare Dataset&quot;)</pre><p>This mounts the EFS Volume at /mnt on the <em>dataset preparation</em> container</p><h4><strong>Points to note when using EFS</strong></h4><ul><li>Amazon EFS lifecycle management automatically manages cost-effective file storage for your file systems</li><li>You can use <em>Bursting Throughput</em> or <em>Provisioned Throughput </em>based on your requirements, data size, average file size e.t.c.</li><li>Overall throughput generally increases as the average I/O size increases</li><li>More <a href="https://docs.aws.amazon.com/efs/latest/ug/performance-tips.html">here</a></li></ul><h3>Conclusion</h3><p>DVC is a tool of choice for us as the training data is large files/binary files. This will be different for different use cases.</p><p>If you seek further implementation details, or need help with infrastructure setup, or have feedback to make this story better - feel free to post questions/comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a340556f412" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MLOps — Part IV Pipelines orchestrator and SSO setup]]></title>
            <link>https://bhagatk.medium.com/mlops-part-iv-pipelines-orchestrator-and-sso-setup-71ba1cc0366f?source=rss-f5d3bfd2b38a------2</link>
            <guid isPermaLink="false">https://medium.com/p/71ba1cc0366f</guid>
            <category><![CDATA[sso]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[mlops-platform]]></category>
            <category><![CDATA[mlops-solution]]></category>
            <dc:creator><![CDATA[Bhagat Khemchandani]]></dc:creator>
            <pubDate>Sat, 05 Feb 2022 15:50:26 GMT</pubDate>
            <atom:updated>2022-05-09T11:53:08.630Z</atom:updated>
            <content:encoded><![CDATA[<h3>MLOps — Part IV Pipelines orchestrator and SSO setup</h3><p>In this part, let&#39;s explore some ways of smoothly integrating Kubeflow pipelines with your existing systems.</p><h4>Orchestrator</h4><p>You might be wondering why do we need this when Kubeflow is an orchestrator itself. <br>Based on some challenges discussed in <a href="https://bhagatk.medium.com/mlops-for-automated-training-evaluation-deployment-and-monitoring-ddd6b9dbf4">Part I</a> and <a href="https://bhagatk.medium.com/mlops-for-automated-training-evaluation-deployment-and-monitoring-part-ii-a053d9824b1a">Part II</a>, we had set the following goals to define the success of this solution.</p><p>Firstly, data scientists should not need to learn about Kubeflow or develop pipelines themselves, their focus should be on Model development.</p><p>Next, Machine learning pipelines/ workflows should be standardized to ensure consistency amongst the teams in terms of data preparation, model training, evaluation, deployment.</p><p>Lastly, while Kubeflow is a tool of choice at present, in the future we might want to switch to a better alternative (should there be one) or even go hybrid with multiple tools.</p><p>It is because of the above goals that an orchestrator is put in place. The purpose of this orchestrator is to expose APIs to trigger different workflows and</p><p>APIs like /train, /deploy, and /evaluate have been defined which accept parameters like a git repository, gitsha, dataset version, env variables, train and test split which are then forwarded to kubeflow</p><p>All the kubeflow specific implementations are abstracted out by this service. It uses <a href="https://www.kubeflow.org/docs/components/pipelines/sdk/connect-api/">kfp-client</a> to interact with the cluster. It goes without saying that a cookie is required to be passed with the kubeflow API requests. Take a look at <a href="https://bhagatk.medium.com/logging-in-to-kubeflow-programmatically-21419678d810">Logging in to Kubeflow</a> to get the cookie programmatically.</p><p>We also use MLFlow as our tracking server, so it is the responsibility of this orchestrator to log workflow parameters on MLFlow.</p><h3>SSO setup</h3><p>Most organizations use LDAP servers to handle authentication/membership. My organization is no different and uses AzureAD for this purpose.</p><p>In order to leverage the existing setup, we decided to integrate AzureAD with AWS Cognito for user authentication and authorization.</p><p><a href="https://aws.amazon.com/cognito/">AWS Cognito</a> scales to millions of users and supports sign-in with social identity providers, such as Facebook, Google, and Amazon, and enterprise identity providers via SAML 2.0.</p><p>Kubeflow uses Dex as a federated OpenID connection provider and can be integrated with Cognito to provide authentication and identity services.\</p><p>Here is the OIDC Flow involving Kubeflow, Dex, Istio gateway and the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*7T-uiWDD-m4mrp56-CbtBw.png" /></figure><p>In order to authenticate the kubeflow users with AzureAD. I have -</p><ol><li>Created Cognito User Pool</li><li>Created Azure AD User Group to handle group membership.</li><li>Set up SAML Provider between Cognito and AzureAD</li><li>Setup AWS ALB (pointing to istio-gateway service) as an HTTPS endpoint, as Cognito supports HTTPS redirect_urls only</li><li>Created App Client in Cognito</li><li>Patched kubeflow-Dex to act as Cognito Client using Cognito connector</li><li>Patched kubeflow oidc-authservice with the new dex url.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLUAScOibujhFIjybIbVGA.png" /></figure><p><strong>Domain isolation using Namespaces/Profiles</strong></p><p>For Isolation Kubernetes uses Namespaces. A Profile is a unique configuration for a user, which determines their access privileges and is defined by the Administrator.</p><p>Kubeflow multi-user isolation is configured by Kubeflow administrators. Administrators configure Kubeflow User Profiles/Bindings for each user. After the configuration is created and applied, a user can only access the Kubeflow components that the Administrator has configured for them. The configuration limits unauthorized users from viewing or accidentally deleting artifacts.</p><p>As mentioned earlier, the purpose of this series is not to go into too much detail, but to give you an overall idea of how you can design a working solution by using some out-of-the-box tools along with some in-house engineering.<br>Feel free to post any questions/suggestions in the comments section.</p><p>If you want to learn more about the Login workflow in kubeflow refer -</p><p>i.) <a href="https://www.arrikto.com/blog/kubeflow/news/kubeflow-authentication-with-istio-dex/">https://www.arrikto.com/blog/kubeflow/news/kubeflow-authentication-with-istio-dex/</a></p><p>ii.) <a href="https://github.com/ajmyyra/ambassador-auth-oidc">https://github.com/ajmyyra/ambassador-auth-oidc</a></p><p>Continue reading <a href="https://bhagatk.medium.com/mlops-dataset-versioning-using-dvc-and-the-use-of-efs-a340556f412">Part V</a> to learn about Dataset versioning using DVC and EFS in Kubeflow Pipelines</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71ba1cc0366f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MLOps - Part III Kubeflow Pipelines]]></title>
            <link>https://bhagatk.medium.com/kubeflow-pipelines-cd27a4db5d26?source=rss-f5d3bfd2b38a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd27a4db5d26</guid>
            <category><![CDATA[kubeflow-pipelines]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[mlops-platform]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Bhagat Khemchandani]]></dc:creator>
            <pubDate>Tue, 28 Dec 2021 11:54:30 GMT</pubDate>
            <atom:updated>2022-02-05T15:51:18.103Z</atom:updated>
            <content:encoded><![CDATA[<p>A <em>pipeline</em> is a description of a machine learning (ML) workflow, including all of the <a href="https://www.kubeflow.org/docs/components/pipelines/concepts/component/">components</a> in the workflow and how the components relate to each other in the form of a <a href="https://www.kubeflow.org/docs/components/pipelines/concepts/graph/">graph</a>.</p><p>In this Part III of the <a href="https://bhagatk.medium.com/mlops-for-automated-training-evaluation-deployment-and-monitoring-ddd6b9dbf4">series</a> I am going to walk you through the components we need for an ML pipeline, how we standardized them and designed reusable workflows for multiple teams.</p><h3>Use cases</h3><ol><li>Training/Experimentation with training script, input dataset, and fixed hyperparameters</li><li>Deployment of a model, updating an existing deployment with a newer model</li><li>Evaluation/Validation of model(s) trained in above use case(1), or a pre-trained model</li><li>Hyperparameter Tuning</li><li>Incremental Learning</li><li>Model Monitoring</li></ol><p>Let us take a look into some of these use cases and understand the components involved.</p><p><strong>First use case - Model Training</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*reQs050eOruqoiQJscaLRg.png" /><figcaption>Pipeline for model training</figcaption></figure><p><strong>Training steps</strong> (as seen in the figure )</p><ul><li>Provision training datasets and training script</li><li>Provisioning the infrastructure with desired configurations, e.g. env. variables, hyperparameters</li><li>Train the model and log metrics, params to a tracking server e.g. MLFlow</li></ul><p>As you can see there are three components that may vary across experiments <strong>-</strong><br>- Input Datasets<br>- Training script<br>- Hyperparameters</p><p>In order to make the training workflows reproducible and consistent across runs, we needed to lock in on the above components. So, we decided to version control the datasets using <a href="https://dvc.org/">DVC</a> instead of the usual S3/File systems, whereas training scripts and hyperparameters are versioned using <a href="https://git-scm.com/">Git</a>.</p><p>At the same time, we do not want Data scientists to provision the datasets, code themselves. Hence it is imperative to automate the data and code provisioning stages in the pipeline itself.</p><p><strong>Second use case — Model Deployment</strong></p><p>Seamless model deployment is really crucial for fast feedback and this is a stage that has nothing to do with a Data scientist. Simply put, model deployment is a stage where the model binary has to be loaded in memory by a supporting framework, with desired libraries installed and exposed as an API, all this without the need for manual efforts.</p><p>Typically a model deployment needs -</p><ol><li>Model(s) files — Model serialised to .bin, .pkl or .zip files and stored on file system/S3 etc..</li><li>Wrapper — The code to load the model in memory and invoke its predict functions by providing data in the format it expects</li><li>Additional Modules — These modules/python files are used by wrapper code, for eg. manipulate dataframe, load model, and other utilities</li><li>Packages — These are standard libraries used by the wrapper. E.g. transformers, torch, NumPy, etc</li></ol><p>We have designed the deployment pipeline in such a way that the above four components are picked up automatically and baked into an executable artifact, which is then deployed as a <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">REST API</a> to be consumed by other services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ox54GbEguGxxzE0Uj4mdhQ.png" /><figcaption>Model Deployment Pipeline</figcaption></figure><ol><li>Clone the repository containing deployment descriptor and the above-mentioned artifacts</li><li>Assembly — This stage assembles the wrapper, modules, python packages, and the trained model in a deployment package</li><li>Build Model Image — This stage picks up the deployment package from above, stitches everything together, and bakes a docker image that can be run anywhere, and exposes standard rest endpoints to trigger inference on the model.</li><li>Deploy Model — This stage uses Kubeflow KFServe to deploy the model docker image as an inference service and exposes the model as a service over the Load Balancer automatically</li></ol><p>More use cases - I prefer not to make this an exhaustive story so the remaining use cases will have to be detailed in a separate one.</p><p><strong>Pipelines are generic<br></strong>The idea is to define generic, configurable, and reusable pipelines and have them run by data scientists by providing different parameters e.g. Training repo GitSHA, dataset GitSHA for DVC checkout, train dataset, test dataset hyperparameters e.t.c.</p><p>Also, each of the stages in this pipeline is run by Kubernetes pods, and docker images specific to each stage have been created. For example, a docker image to clone datasets from DVC, another one to run the training script e.t.c</p><p>While I understand this is too much information in too little content, I feel it is important to give an idea about the overall ecosystem and not go into too much depth.</p><p>Feel free to provide feedback/ask questions in the comments below, and help me make this more informative.</p><p>In the <a href="https://bhagatk.medium.com/mlops-part-iv-pipelines-orchestrator-and-sso-setup-71ba1cc0366f">next part</a>, I will take you through the Orchestrator for Kubeflow Pipelines, Authentication(SSO) setup for Kubeflow, and bring together Istio, Dex, and Cognito.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd27a4db5d26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MLOps for Automated Training, Evaluation, Deployment and Monitoring — Part II]]></title>
            <link>https://bhagatk.medium.com/mlops-for-automated-training-evaluation-deployment-and-monitoring-part-ii-a053d9824b1a?source=rss-f5d3bfd2b38a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a053d9824b1a</guid>
            <category><![CDATA[kubeflow-pipelines]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[continuous-training]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Bhagat Khemchandani]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 09:05:57 GMT</pubDate>
            <atom:updated>2022-03-27T10:57:22.152Z</atom:updated>
            <content:encoded><![CDATA[<h3>MLOps for Automated Training, Evaluation, Deployment and Monitoring — Part II</h3><p>Now that we understand the need for MLOps from <a href="https://bhagatk.medium.com/mlops-for-automated-training-evaluation-deployment-and-monitoring-ddd6b9dbf4">Part I </a>of this series, let’s dive into the architecture, high-level design, and services involved to realize the solution</p><p>Let us now look into -<br>i. ML orchestration tool which does the heavy lifting of training/evaluation, deployment of models, followed by <br>ii. Helper services on top of ML Orchestration Tool which helps standardize the data science workflows at my organization</p><h4><strong>i. Machine Learning Orchestration Tools</strong></h4><p>We evaluated a number of tools and frameworks used across the industry</p><ul><li><a href="https://airflow.apache.org/"><strong>Apache Airflow</strong></a><br>Airflow is a <strong>generic task orchestration platform</strong>. Use Airflow if you want the most full-featured, mature tool and you can dedicate time to learning how it works, setting it up, and maintaining it. Also, if you need a mature, broad ecosystem that can run a variety of different tasks.</li><li><a href="https://www.kubeflow.org/"><strong>KubeFlow</strong></a><br>Kubeflow <strong>focuses specifically on machine learning tasks</strong>, such as experiment tracking, hyperparameter tuning, and model deployment, and more out-of-the-box patterns for machine learning solutions.<br><a href="https://www.kubeflow.org/docs/pipelines/overview/pipelines-overview/">Kubeflow Pipelines</a> is a separate component of Kubeflow that focuses on model deployment and CI/CD and can be used independently of Kubeflow’s other features. Kubeflow relies on Kubernetes and is likely more interesting to you if you’ve already adopted that.</li><li><a href="https://mlflow.org/"><strong>MLFlow</strong></a><strong><br></strong>If you care more about <strong>tracking experiments or tracking and deploying models</strong> using MLFlow’s predefined patterns than about finding a tool that can adapt to your existing custom workflows.</li><li><a href="https://aws.amazon.com/sagemaker/"><strong>AWS Sagemaker</strong></a><strong><br></strong>Amazon’s SageMaker is <strong>fully managed</strong>, ‘<em>optimized</em>’ for ML, and comes with lots of integrated tools such as notebook servers, Auto-ML, and monitoring <strong>within the AWS ecosystem</strong>.<br>Managed and integrated does not mean easy to use though. SageMaker pipelines look almost identical to Kubeflow’s but their definitions require lots more detail (like everything on AWS) and do very little to simplify deployment for scientists.</li></ul><p>While all of these tools have different focus points and different strengths, no tool can serve as a silver bullet. <strong>We might end up using a combination of these tools based on their capabilities.</strong></p><p>As a starting point, we have selected <strong>Kubeflow </strong>as our tool of choice for the reasons stated below.</p><ul><li>Kubeflow allows us to keep the entire application <strong>portable</strong> between cloud providers</li><li>Given we are already using Kubernetes to orchestrate workflows, Kubeflow comes out as a natural choice</li><li>The UI is very responsive. Status changes update in real-time. I can terminate a pipeline and see that it worked almost immediately</li><li>One key benefit would be the direct integration of containers and the UI. I can click on a stage in my pipeline and view the container logs</li><li>With Kubeflow, each pipeline step is isolated in its own container, which drastically improves the developer experience</li><li>Data scientists have easy access<strong> </strong>to the full compute power of the cluster from their notebooks</li><li>It’s also possible to <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/amazon-sagemaker-components-for-kubeflow-pipelines.html">run SageMaker jobs via Kubeflow components</a>, allowing us to benefit from SageMaker’s tools while sticking to the Kubeflow framework.</li><li>It’s a very flexible and extensible framework due to it relying on Kubernetes to manage all code execution, resource management, and networking.</li></ul><p><strong>Note: Kubeflow lets you customize everything, which always comes at the expense of simplicity.</strong></p><h3>ii. Helper Services on top of Kubeflow</h3><p>Remember our missions from Part I: Take the <strong>workload away from data scientists </strong>and<strong> </strong>Establish <strong>common practices with reproducibility.</strong></p><p>Imagine if all the data scientists need to learn about Kubeflow and all the details needed to develop pipelines, and let&#39;s not forget these ML orchestrator tools might change from time to time or complement one another. This is a lot of work for Data scientists and is not related to Data science at all.</p><p>Also, these orchestration tools do not prescribe how the model development pipelines should look like. If we do not standardize the use of Kubeflow pipelines/ workflows, there will be a lack of consistency amongst the teams in terms of data preparation, model training, evaluation, deployment. This will very soon become a maintenance nightmare.</p><p><strong>Helper services to the Rescue<br></strong>To resolve the above two issues we decompose the pipeline execution in two parts —</p><ol><li>Define generic yet standard pipelines in kubeflow using <a href="https://kubeflow-pipelines.readthedocs.io/en/latest/source/kfp.html">kfp</a>.</li><li>Design a Frontend application and a model registry service that allows data scientists to trigger the above pipelines with <strong>zero knowledge of kubeflow. </strong>Think of a service that accepts parameters like — model git repository, gitsha, dataset repository(DVC), dataset-gitsha, hyperparameters, and many more, and uses them to trigger a pipeline on Kubeflow.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfJc6M-9ylZtjUzype3bmA.png" /></figure><p>This makes the model training/evaluation/deployment process as simple as ordering a pizza online. Provide a few values and submit the job.</p><p>At the time of writing this, a lot of machine learning teams in my organization are waiting to get onboarded on the platform and start using it for their day-to-day experimentation, training, and deployment.</p><p>Intrigued? Please read <a href="https://bhagatk.medium.com/kubeflow-pipelines-cd27a4db5d26">Part III - Kubeflow Pipelines</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a053d9824b1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MLOps for Automated Training, Evaluation, Deployment and Monitoring]]></title>
            <link>https://bhagatk.medium.com/mlops-for-automated-training-evaluation-deployment-and-monitoring-ddd6b9dbf4?source=rss-f5d3bfd2b38a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddd6b9dbf4</guid>
            <category><![CDATA[continuous-training]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[kubeflow-pipelines]]></category>
            <dc:creator><![CDATA[Bhagat Khemchandani]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 09:03:06 GMT</pubDate>
            <atom:updated>2022-04-27T04:47:16.692Z</atom:updated>
            <content:encoded><![CDATA[<p>This is Part I of the series illustrating how I automated the training, evaluation, and deployment of machine learning models for one of my clients and developed a fully functional framework around Kubeflow and MLOps</p><p>Part I - Here I will take you through the problem statement, need of MLOps, and <em>10000-foot view </em>of the project goal and the Model lifecycle</p><p><a href="https://medium.com/@bhagatk/mlops-for-automated-training-evaluation-deployment-and-monitoring-part-ii-a053d9824b1a">Part II</a> - This one focuses on the architecture, high-level design, and services involved to realize the solution</p><p><a href="https://bhagatk.medium.com/kubeflow-pipelines-cd27a4db5d26">Part III</a> - Covers Kubeflow Pipelines - Training &amp; Validation Pipeline, Evaluation of Pre-Trained models, Deployment of a trained model</p><p><a href="https://bhagatk.medium.com/mlops-part-iv-pipelines-orchestrator-and-sso-setup-71ba1cc0366f">Part IV</a> - Orchestrator for Kubeflow Pipelines, Authentication(SSO) setup with Kubeflow, Istio, Dex, and Cognito</p><p><a href="https://bhagatk.medium.com/mlops-dataset-versioning-using-dvc-and-the-use-of-efs-a340556f412">Part V </a>- Dataset versioning using DVC, Using EFS for sharing datasets across stages</p><p>Part VI - Automated model deployment using Kserve/Helmcharts for serving models and packaging models on the fly</p><p>Part VII - Carbon Footprint/Emissions monitoring with Kubernetes, Newrelic, and using MLFlow for tracking model training params, metrics</p><h4>Problem Statement</h4><p>Machine Learning (ML) models built by data scientists represent a small fraction of the components that comprise an enterprise production deployment workflow.​​​​​​​ To operationalize ML models, data scientists are required to work closely with multiple other teams such as business, engineering, and operations. This represents organizational challenges in terms of communication, collaboration, and coordination.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*3tktmlzx5gHsFYFhNcHKfA.png" /><figcaption><em>Fig 1: Only a small fraction of real-world ML systems are composed of the ML code, as shown by the small box in the middle.​ The required surrounding infrastructure is vast and complex.</em></figcaption></figure><h4>MLOps</h4><p>MLOps, or machine learning operations, are the infrastructure, methods, and practices used to streamline the machine learning life cycle from model design and data preparation to monitoring of model in production.</p><p>MLOps took many principles from DevOps. Both DevOps and MLOps <strong>encourage and facilitate collaboration between people</strong> who develop (software engineers and data scientists), people who manage infrastructure, and other stakeholders. Both emphasize process automation in continuous development so that speed and efficiency are maximized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9YF-IHyDQ4sBJpTRCHLEg.png" /></figure><p>Unlike traditional Software development, Machine Learning is not only influenced by changes in its code. <strong>Data</strong> is the other critical input that’ll need to be managed, as will <strong>parameters</strong>, metadata, logs, and finally, the <strong>model</strong>.</p><p>In addition to solving an organizational challenge, MLOps is addressing a technical one: how to make the <strong>process reproducible and auditable</strong>. By using similar tools and by following common workflows, teams can more easily automate the delivery of an end-to-end ML system ensuring its reproducibility. This, in turn, increases the trust in the ML model predictions and facilitate its audit.</p><p>I don’t intend to describe MLOps in depth. There are plenty of resources on the web. Some references are -</p><p><a href="https://martinfowler.com/articles/cd4ml.html">Continuous Delivery for Machine Learning</a> <br><a href="https://learning.oreilly.com/library/view/introducing-mlops/9781492083283/">Introduction to MLOps by O’Reilly media</a>.<br><a href="https://martinfowler.com/articles/cd4ml.html">https://martinfowler.com/articles/cd4ml.html</a></p><p>You can also aim for an online <strong>specialization course</strong>: <a href="https://www.deeplearning.ai/program/machine-learning-engineering-for-production-mlops/">Machine Learning Engineering for Production (MLOps) Specialization</a></p><h4>Project Mission</h4><p>At the risk of oversimplification, the mission of my project was to</p><ul><li>Take the <strong>workload away from data scientists</strong> to operationalize Machine Learning (automatic model training, deployment, etc.)​</li><li>Establish <strong>common practices </strong>with <strong>reproducibility</strong> of model training and robustness by design​</li><li>Automate most of the infrastructure and builds required during the Model Development lifecycle</li></ul><h4>Use case Overview</h4><p>As with any project, data scientist teams work to accomplish a task e.g. Extract authors from research papers, find references, citations from manuscripts, etc. For any task, there are multiple model architectures to be evaluated, and the most suited model based on objectives and metrics is deployed later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVg61buhZFn4Xo0N4k9AYg.png" /><figcaption>Use cases</figcaption></figure><p>The figure above illustrates the lifecycle of model development, deployment, and maintenance. It is the responsibility of MLOps to facilitate the Tools, Pipelines, and underlying infrastructure in order to make the End-to-End process seamless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XWZIgEhS_0NVQIezwU_iVA.png" /><figcaption>A Pipeline to realise the use case</figcaption></figure><p>If this gets you intrigued, read through <a href="https://bhagatk.medium.com/mlops-for-automated-training-evaluation-deployment-and-monitoring-part-ii-a053d9824b1a">Part II</a> that focuses on the architecture, high-level design, and services involved to realize the solution</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddd6b9dbf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging in to Kubeflow programmatically]]></title>
            <link>https://bhagatk.medium.com/logging-in-to-kubeflow-programmatically-21419678d810?source=rss-f5d3bfd2b38a------2</link>
            <guid isPermaLink="false">https://medium.com/p/21419678d810</guid>
            <category><![CDATA[kubeflow-pipelines]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[dex]]></category>
            <category><![CDATA[kubeflow]]></category>
            <dc:creator><![CDATA[Bhagat Khemchandani]]></dc:creator>
            <pubDate>Thu, 16 Sep 2021 05:42:57 GMT</pubDate>
            <atom:updated>2021-09-16T05:42:57.497Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I have been working with <a href="https://www.kubeflow.org/">Kubeflow</a> pipelines for orchestrating machine learning workflows. This involves setting up kubeflow on a Kubernetes cluster and defining pipelines.</p><p>Out of the box, kubeflow comes with Dex OpenID Connect Identity (OIDC) for authenticating users. You need to be logged in to Dex before interacting with Kubeflow APIs.</p><p>As for my use case, it was a requirement to interact with kubeflow programmatically, and invoke pipelines as desired.</p><p>Although logging in to Kubeflow from browser is really straightforward, it is slightly complicated when it comes to logging in programmatically as it involves several redirections in the authentication flow.</p><p>Here are the steps to login using curl</p><pre>1) CLUSTER_IP=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath=&#39;{.spec.clusterIP}&#39;)<br><br>2) curl -v http://${CLUSTER_IP}<br>Response:<br>&gt;&gt; &lt;a href=&quot;/dex/auth?client_id=kubeflow-oidc-authservice&amp;amp;redirect_uri=%2Flogin%2Foidc&amp;amp;response_type=code&amp;amp;scope=profile+email+groups+openid&amp;amp;state=STATE_VALUE&quot;&gt;Found&lt;/a&gt;.<br><br>STATE=STATE_VALUE<br><br>3) curl -v &quot;http://${CLUSTER_IP}/dex/auth?client_id=kubeflow-oidc-authservice&amp;redirect_uri=%2Flogin%2Foidc&amp;response_type=code&amp;scope=profile+email+groups+openid&amp;amp;state=${STATE}&quot;<br>Response:<br>&gt;&gt; &lt;a href=&quot;/dex/auth/local?req=REQ_VALUE&quot;&gt;Found&lt;/a&gt;<br><br>REQ=REQ_VALUE</pre><pre>4) curl -v &quot;http://${CLUSTER_IP}/dex/auth/local?req=${REQ}&quot; -H &#39;Content-Type: application/x-www-form-urlencoded&#39; --data &#39;login=admin%40kubeflow.org&amp;password=12341234&#39;<br><br>5) curl -v &quot;http://${CLUSTER_IP}/dex/approval?req=${REQ}&quot;<br><br>Response:<br>&gt;&gt; &lt;a href=&quot;/login/oidc?code=CODE_VALUE&amp;amp;state=STATE_VALUE&quot;&gt;See Other&lt;/a&gt;.<br><br>CODE=CODE_VALUE<br><br>6) curl -v &quot;http://${CLUSTER_IP}/login/oidc?code=${CODE}&amp;amp;state=${STATE}&quot;<br><br>Response:<br>&gt;&gt; set-cookie authservice_session=SESSION<br><br>SESSION=SESSION</pre><p>Login using python code<br>Here we are using requests package which follows redirections, hence we need to call 2 API explicitly, which involves 4 redirections under the hood</p><pre>import requests as requests<br>import re<br><br><br>response = requests.get(f&quot;http://{CLUSTER_IP}&quot;)<br>response_text = response.text</pre><pre>//Extract the request token REQ_VALUE as done in step 3req_token = re.search(&#39;req=(.+)&quot;&gt;&#39;, response_text).group(1)</pre><pre>creds={&#39;login&#39;:&#39;user@example.com&#39;,&#39;password&#39;:&#39;12341234&#39;}<br>response = requests.post(f&quot;http://{CLUSTER_IP}/dex/auth/local?req={req_token}&quot;,data=creds,headers={&#39;Content-Type&#39;: &#39;application/x-www-form-urlencoded&#39;})</pre><pre>// Cookie was set in the last redirection, hence we need to fetch that from response.history<br>cookie = &quot;authservice_session=&quot;+response.history[2].cookies.get(&#39;authservice_session&#39;)<br>print(cookie)<br>// This is the desired cookie</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21419678d810" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>