<?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 Sadik Bakiu on Medium]]></title>
        <description><![CDATA[Stories by Sadik Bakiu on Medium]]></description>
        <link>https://medium.com/@sbakiu?source=rss-a0654b43131a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AZkjTVuXZA4-UxD9ouW4VQ.jpeg</url>
            <title>Stories by Sadik Bakiu on Medium</title>
            <link>https://medium.com/@sbakiu?source=rss-a0654b43131a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:03:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sbakiu/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[A practical guide to A/B Testing in MLOps with Kubernetes and seldon-core]]></title>
            <link>https://medium.com/data-science/a-practical-guide-to-a-b-testing-in-mlops-with-kubernetes-and-seldon-core-e75e91ef91ef?source=rss-a0654b43131a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e75e91ef91ef</guid>
            <category><![CDATA[kubenetes]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ab-testing]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[seldon-core]]></category>
            <dc:creator><![CDATA[Sadik Bakiu]]></dc:creator>
            <pubDate>Tue, 31 May 2022 05:49:37 GMT</pubDate>
            <atom:updated>2022-05-31T05:49:37.175Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Practical Guide to A/B Testing in MLOps with Kubernetes and seldon-core</h3><h4>How to set up a containerized microservice architecture to run A/B tests</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rhATU9M4VsfM7jeo" /><figcaption>Photo by <a href="https://unsplash.com/@madebyjens?utm_source=medium&amp;utm_medium=referral">Jens Lelie</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Many companies are using data to drive their decisions. The aim is to remove uncertainties, guesswork, and gut feeling. A/B testing is a methodology that can be applied to validate a hypothesis and steer the decisions in the right direction.</p><p>In this blog post, I want to show how to create a containerized microservice architecture that is easy to deploy, monitor and scale every time we run A/B tests. The focus will be on the infrastructure and automation of the deployment of the models rather than the models themselves. Hence, I will avoid explaining the details of the model design. For illustration purposes, the model used is one created in <a href="https://towardsdatascience.com/real-time-stream-processing-for-machine-learning-at-scale-with-spacy-kafka-seldon-core-6360f2fedbe">this post</a> by Alejandro Saucedo. The model performs text classification based on Reddit moderation dataset. How the model is built and how it works is described in the original post.</p><p>In case you already know how A/B testing works, feel free to jump to the <em>A/B Testing in Kubernetes with seldon-core</em> section.</p><p>All images unless otherwise noted are by the author.</p><h3>What is A/B testing?</h3><p>A/B testing, at its core, compares two variants of one variable and determines which variant performs better. The variable can be anything. For instance, for a website, it can be the background color. We can use A/B testing to validate if changing the background color invites the users to stay longer on the website. For recommendation engines, it can be whether changing the model parameters generates more revenue.</p><p>A/B testing has been used since the early twentieth century, to improve the success of <a href="https://en.wikipedia.org/wiki/A/B_testing#History">advertisement campaigns</a>. Afterward, A/B testing has been used in medicine, marketing, SaaS, and many other domains. Notably, A/B testing was used in Obama’s 2012 campaign to <a href="https://www.optimizely.com/insights/blog/how-obamas-campaign-team-sourced-ab-tests-from-user-feedback/">increase voters’ donations</a>.</p><h4>How Does A/B Testing Work?</h4><p>To run A/B testing, you need to create two different versions of the same component, that differ on only one variable. In the case of selecting the most inviting background color for our website, version A is the current color (e.g. red), also known as <em>Control</em>, and version B is the new color (e.g. blue), called <em>Variation</em>. Users are randomly shown either version A or version B.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*KjGzK4UdRyb40F2rSUxKNg.png" /><figcaption>Split traffic between version A and B in A/B testing.</figcaption></figure><p>Before we can pick the better performing version, we need a way to objectively measure the results. For this, we have to choose (at least) one metric to analyze. A meaningful metric in this example would be user session duration. Longer sessions mean users are using the website more. In our analysis, we search for the variation with longer user sessions. If we are happy with the results, we can choose to deploy this version to all the users.</p><h3>How does A/B testing apply in Machine Learning</h3><p>In Machine Learning, as almost in every engineering field, there are no silver bullets. We need to test to find a better solution. Searching for the data science technique that fits our data best, means we have to test many of them. To optimize the model, we need to play with many parameters or parameter sets.</p><p>A/B testing is an excellent strategy to validate whether a new model or a new version outperforms the current one. All this while testing with the actual users. The improvements can be in terms of F1 score, user engagement, or better response time.</p><h3>A/B Testing Process</h3><p>Let’s consider the case when we want to test the model’s performance. To run A/B testing, we need to:</p><ol><li><strong>Define the hypothesis</strong>. In this step, we decide what is it we want to test. In our case, we want to test whether the new model version provides faster predictions.</li><li><strong>Define metric(s)</strong>. To pick the better version in the test, we need to have a metric to measure. In this example, we will measure the time spent from the user’s request arrival until it gets a response.</li><li><strong>Create variant</strong>. Here we need to create a deployment that uses the new model version.</li><li><strong>Run experiment. </strong>After preparing the variant, we can run the experiment, ideally for a defined time frame.</li><li><strong>Collect data. </strong>At the same time, we must be collecting the data needed to measure the metric(s) from 2.</li><li><strong>Analyze results. </strong>All that is left now is to analyze the data and pick the variant that yields better results.</li></ol><h3>A/B Testing in Kubernetes with seldon-core</h3><p><strong>Kubernetes</strong> is the default choice for the infrastructure layer because of its flexibility and industry-wide adoption. We can provision resources dynamically based on the tests we want to run, and release them once the testing phase is finished.</p><p>In the MLOps space, there are not many open-source tools that support A/B testing out-of-the-box. <strong>Seldon-core</strong> is the exception here and it:</p><ul><li>supports Canary Deployments (configurable A/B deployments)</li><li>provides customizable metrics endpoint</li><li>supports REST and gRPC interfaces</li><li>has very good integration with Kubernetes</li><li>provides out-of-the-box tooling for metric collection and visualization (Prometheus and Grafana)</li></ul><p>Therefore, choosing seldon-core for model deployment is not a difficult decision.</p><p>Resources used in this post are in <a href="https://github.com/data-max-hq/ab-testing-in-ml">this GitHub repository</a>.</p><h4>What Tooling is Needed</h4><p>The architecture we are aiming for looks as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3X_IhrzRjFivexq0Gql_g.png" /><figcaption>The aim architecture for A/B testing.</figcaption></figure><ol><li>Ingress Controller — makes sure requests coming from the users reach the correct endpoints. The ingress controller concept is described in great detail in the Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/">documentation</a>. We will be using ambassador as an ingress controller since it is supported by seldon-core. Other alternatives are Istio, Linkerd, or NGINX.</li><li>Seldon-core — as mentioned above, will be used for serving ML models as containerized microservices and for exposing metrics.</li><li>Seldon-core-analytics — is a seldon-core component that bundles together tools to collect metrics (Prometheus) and visualize them (Grafana).</li><li>Helm — is a package manager for Kubernetes. It will help us install all these components.</li></ol><h4><strong>Building the models</strong></h4><p>To compare the two model versions, we first need to have the model versions.</p><p>In the test, we want to find which model version is better. The better model version for this case is defined as the one that provides predictions faster. For demonstration purposes, the only difference between the two versions will be an artificial delay added to version A before returning the response.</p><p>Let’s start by cloning the repository:</p><pre>git clone <a href="/service/mailto:git@github.com">git@github.com</a>:data-max-hq/ab-testing-in-ml.git<br>cd ab-testing-in-ml</pre><p>Build the version A:</p><pre>docker build -t ab-test:a -f Dockerfile.a .</pre><p>Now, let’s build the version B:</p><pre>docker build -t ab-test:b -f Dockerfile.b .</pre><h4>Setting up</h4><p>After preparing the container images, let’s get started with the deployment. We will assume that we have a Kubernetes cluster up and running. The easiest way to get a Kubernetes cluster is to set up a local one with minikube, kind, or k3s.</p><p>Initially, we will install the helper components. We start with the ingress controller:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/345029842e7bb846059437a6bb902725/href">https://medium.com/media/345029842e7bb846059437a6bb902725/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uF-cTyEfpMydsImAIXv9og.png" /><figcaption>Install ambassador.</figcaption></figure><p>Next, we will install seldon-core-analytics:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f55f8aa29ab3b45ccaefa387a39b59f/href">https://medium.com/media/3f55f8aa29ab3b45ccaefa387a39b59f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9oEm0Yw4akRZhGSVpYbs0Q.png" /><figcaption>Install seldon-core-analytics.</figcaption></figure><p>The next step is to install seldon-core:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea33d9df663ed3289841b83775eb022e/href">https://medium.com/media/ea33d9df663ed3289841b83775eb022e/href</a></iframe><p>This step, among other things, installs the necessary custom resource definitions (CRDs) in our cluster, needed to have SeldonDeployment working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TUfSJxbGUmnOKqs2cHKPA.png" /><figcaption>Install seldon-core CRDs.</figcaption></figure><p>Up to this point, we have installed the necessary components for our infrastructure. Next, we need to bring this infrastructure to life with the actual microservices that we want to test.</p><h3>Deploy ML models as microservices</h3><p>The next step is deploying both versions of our ML models. Here, we will use a canary configuration of a SeldonDeployment resource. A canary configuration is a setting where two (or more) versions are deployed and they will receive parts of the overall traffic. The Kubernetes manifest file looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4289c2c29b120cd0092de0d3de0d2a0f/href">https://medium.com/media/4289c2c29b120cd0092de0d3de0d2a0f/href</a></iframe><p>After this deployment, we have the complete architecture up and running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVUc9P_gsyFJGkjlUIxPDw.png" /><figcaption>Fully working architecture.</figcaption></figure><p>In our code, we have created a custom metric that reports the time until the prediction for every request. In addition, we have added a tag to be able to track each prediction from which version it was generated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ux_CPPRSlvob8Z9V-LBZlA.png" /><figcaption>Code snippet to add custom metrics and tags.</figcaption></figure><p>Let’s now test whether the deployment works. First, we will port-forward the ambassador port, to send requests directly from our machine:</p><pre>kubectl port-forward svc/ambassador -n ambassador 8080:80</pre><p>and then we will send a request:</p><pre>curl -X POST -H &#39;Content-Type: application/json&#39; \<br>  -d &#39;{&quot;data&quot;: { &quot;ndarray&quot;: [&quot;This is a nice comment.&quot;]}}&#39; \<br>  http://localhost:8080/seldon/seldon/abtest/api/v1.0/predictions</pre><p>Inspecting the response we can see:</p><ul><li>In the data.ndarray key, we get the prediction.</li><li>In the meta.metrics and meta.tagskeys, we get the custom metrics defined above.</li><li>In the meta.requestPath key, we can see the model(s) that handled this request.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*9e9j-E6Mq9CnLD-jSXF9RA.png" /><figcaption>JSON response from the seldon-core microservice.</figcaption></figure><p>Finally, we need to build a dashboard to visualize the collected metric. We start by port-forwarding Grafana, to make it reachable from our machine:</p><pre>kubectl port-forward svc/seldon-core-analytics-grafana -n seldon-system 3000:80</pre><p>We will create the dashboard, or import one already prepared from <a href="https://github.com/data-max-hq/ab-testing-in-ml/blob/main/dashboard/dashboard.json">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVjRioro9LeJf_6GNVsnPw.png" /><figcaption>The imported dashboard.</figcaption></figure><p>After the dashboard is created, we have the deployment and the monitoring ready.</p><p>Now, let’s generate some load. The seldon_client/client.py script in the repo uses the seldon-core python client to send a few thousand requests.</p><pre>python seldon_client/client.py</pre><p>We can now see values visualized in our dashboard and can compare the model versions on the prediction response time basis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rl8Z0PiC6LOwAPW6yyvmLw.png" /><figcaption>Model A vs. Model B prediction times.</figcaption></figure><p>Unsurprisingly, the model version B, without the artificial delay, responds faster.</p><h3>What’s next?</h3><p>In real life, choices are not always binary. More often than not, we have to consider more options. To address this, we can use Multi-armed Bandits (MAB). MAB are A/B/n tests that update in real-time based on the performance of each variation. MABs are supported on seldon-core as well.</p><h3>Summary</h3><p>With this demo, we were able to set up all the necessary infrastructure for A/B testing, collect and visualize metrics, and in the end, make an informed decision about the initial hypothesis. We also have the option to track further metrics using the custom tags we added in the response.</p><p>We specialize in productionizing Machine Learning workloads, and you can learn more <a href="https://www.data-max.io/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e75e91ef91ef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/a-practical-guide-to-a-b-testing-in-mlops-with-kubernetes-and-seldon-core-e75e91ef91ef">A practical guide to A/B Testing in MLOps with Kubernetes and seldon-core</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern Data Team Hats]]></title>
            <link>https://sbakiu.medium.com/modern-data-team-hats-f605fddd8aeb?source=rss-a0654b43131a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f605fddd8aeb</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Sadik Bakiu]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 08:14:24 GMT</pubDate>
            <atom:updated>2022-05-01T19:43:56.083Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DFjxFRf4J9MBbjdNqOTMbw.png" /><figcaption>Different hats in a team. Picture from <a href="http://storyset.com/">Storyset</a>.</figcaption></figure><h3>This blog was written together <a href="https://medium.com/u/727361d7139">Martin Rusnak</a> from rusnakconsulting.com and <a href="https://medium.com/u/a90b2a7d5726">Bujar Bakiu</a>.</h3><p>Not that long ago (maybe somewhere this is still the case), companies had multiple one dimensional data teams. Each team was composed of either only Data Scientists, Business Analysts, or Data Engineers. With this set up, companies struggled to integrate data products into their wider software architecture. Commonly accepted reasons for this are:</p><ul><li>Lack of <strong>communication</strong> between teams. Requirements prioritized in one of them were not aligned with the other teams. For instance, if the Data Science team needed to explore the new marketing campaign data, it had to wait for the Data Engineering team to make these data available.</li><li>Considering solutions in <strong>isolation</strong>. Data Scientists might not be considering the performance of the solution during inference, but rather optimizing for accuracy during testing and evaluation. However, the inference would be a huge challenge for the operations team.</li></ul><p>Overall, there were huge gaps when building end-to-end processes like automation, orchestration, and testing.</p><h3><strong>Modern Data Team Hats</strong></h3><p>To solve the problems with one-dimensional teams, the proven approach of cross-functional teams came to the rescue. In these teams, there are members focused more on Data Analyst, Data Science, ML Engineering, etc. They work together bringing more depth, a wider scope of information, and a diversity of opinions to reach their goal.</p><p>We believe that there are no clear boundaries between the roles one can play in the team. Therefore, in this post, we name these hats. A hat is a position someone holds when discussing or solving a problem.</p><p>Every team is different, however, these are the most commonly used terms to describe these hats in a data team.</p><h4>Data Engineer</h4><p>The Data Engineering hat builds reliable data pipelines and data infrastructure. They serve as a bridge with the infrastructure team to deploy specialized components and upgrades. They take care of integrating other data sources and implementing data quality checks. If needed, data versioning is implemented by this hat. A big part of the work is as well optimization of the performance in terms of ingesting data and answering queries. Most often used tools are:</p><ul><li>Orchestration, e.g. Airflow, Dagster, Prefect</li><li>Data processing, e.g. Pandas, Spark, Dask</li><li>Data warehousing, e.g. BigQuery, Redshift, Hive</li><li>Data versioning, e.g. DVC, Pachyderm</li></ul><h4>Analytics Engineer</h4><p>The Analytics Engineering hat is occupied primarily with cleaning and transforming the data. Together with the data engineering hat, they bring software engineering best practices to analytics code, like version control, automated testing, and deployment. Tools usually used:</p><ul><li>Data warehousing, e.g. BigQuery, Redshift, Snowflake</li><li>Transformation, e.g. dbt, Dataform</li></ul><h4>Data Analyst</h4><p>The Data Analyst hat interrogates the data looking for insights to support data-driven decision making. They have strong collaboration and skill overlap with the Analytics Engineer. They visualize the data to help everyone make sense of it. Tools used:</p><ul><li>Visualization, e.g. Metabase, Looker, Power BI, Tableau</li><li>Transformation, e.g. dbt, Dataform, SQL</li></ul><h4>Data Scientist</h4><p>The Data Scientist hat finds the best way to model the data for predictions. They have strong skills in feature engineering. People wearing this hat have deep knowledge of machine learning techniques, statistics, and analytics. Used tools are:</p><ul><li>ML libraries like scikit-learn, XGboost</li><li>Deep Learning libraries, e.g. Tensorflow, PyTorch</li><li>Experiment tracking, e.g. MLflow, Kubeflow, Aim</li><li>Feature store, e.g. Feast, Hopsworks</li><li>Explainability, e.g. Lime, SHAP</li></ul><h4>Machine Learning Engineer</h4><p>Machine Learning Engineering hat brings in a thorough knowledge of software engineering best practices. They productionize ML models to solve business needs and integrate them with the current organization infrastructure. They build the infrastructure for A/B testing, distributed model training, and ML workflow orchestration as well as extend existing platforms. Tools used:</p><ul><li>Orchestration: MLflow, Kubeflow, Flyte, Kubernetes</li><li>Model serving, e.g. seldon-core, BentoML, TensorFlow Serving, Torchserve</li><li>Training, e.g. Horovod, Ray</li><li>Feature store, e.g. Feast, Hopsworks</li></ul><h4>MLOps</h4><p>The MLOps hat focuses on integrating automation and monitoring at all steps of ML system construction. They bring DevOps best practices to the team, like integration, deployment, model monitoring, etc. The most commonly used tools are:</p><ul><li>Model Monitoring, e.g. whylabs, evidently</li><li>Automation, e.g. Gitlab CI, Github Actions</li><li>Infrastructure, e.g. Terraform, Kubernetes, Helm charts</li></ul><h4>Product Manager</h4><p>The Product Manager hat is usually separate from the other very technical hats. They make sure what is being developed bring value to the users and stakeholder.</p><p>A team will likely not contain all these hats. Which ones are required depends on the team size, challenge at hand, and many other factors. Often, one person covers more than one hat.</p><p>At <a href="https://www.data-max.io/">Data Max</a>, we focus on covering all the hats mentioned here. We are proud of our expertise and are eager to share our knowledge. Reach out to us at <a href="/service/mailto:hello@data-max.io">hello@data-max.io</a>.</p><p>This post was originally posted in <a href="https://www.data-max.io/blog">https://www.data-max.io/blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f605fddd8aeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Orchestrating Spark Jobs with Kubeflow for ML Workflows]]></title>
            <link>https://sbakiu.medium.com/orchestrating-spark-jobs-with-kubeflow-for-ml-workflows-830f802a99fe?source=rss-a0654b43131a------2</link>
            <guid isPermaLink="false">https://medium.com/p/830f802a99fe</guid>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Sadik Bakiu]]></dc:creator>
            <pubDate>Mon, 12 Jul 2021 16:56:56 GMT</pubDate>
            <atom:updated>2022-03-31T15:49:46.923Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A maestro conductor in front of an orchestra." src="https://cdn-images-1.medium.com/max/1024/1*P0kR_CJQZ0yMOc5tD2NGmQ.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/mohamed_hassan-5229782/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=3020019">mohamed Hassan</a> from <a href="https://pixabay.com/">Pixabay</a>.</figcaption></figure><p>This post is about <a href="https://www.kubeflow.org/">Kubeflow</a>, <a href="https://spark.apache.org/">Spark</a> and their interaction. One year ago, I was trying to trigger a Spark job from a Kubeflow pipeline. It was proving to be a stubborn but exciting problem. The other weekend, I started tinkering with this problem again. In the end, persistence and patience yielded satisfactory results. To skip the intro, click <a href="https://medium.com/p/830f802a99fe#5307">here</a>.</p><h3>Motivation</h3><p>Why is it necessary to orchestrate Spark jobs with Kubeflow? Isn’t it sufficient to simply submit these jobs to a Kubernetes cluster and wait till they are finished? The answer of course is, it depends. In the use case I was working on, it was necessary to be able to orchestrate jobs, to make sure resources are fully utilized, and all the processing steps are finished as soon as possible.</p><p>A typical Machine Learning (ML) workflow consists of three stages: preprocessing, training, and serving. During preprocessing, data cleaning and data transformations are performed. During the training stage, one or more models are trained. These models are in turn made available to the target audience in the serving stage. The data generated during serving, can be fed back to the pipeline to help improve model accuracy, keep the model relevant and up-to-date as old training data might become irrelevant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQFSBofiqIl2WOhbpI3O0w.jpeg" /><figcaption>Typical Machine Learning Workflow. Icon credits: <a href="https://www.flaticon.com/authors/eucalyp">Eucalyp</a>, <a href="https://www.flaticon.com/authors/freepik">Freepik</a></figcaption></figure><p>This post is about the preprocessing stage.</p><p>The increasing amount of data available as input for ML workflows, increases the need for efficient processing of data. Using bigger machines is expensive and sometimes not possible anymore. Hence, the solution is Distributed Computing. Distributed computing frameworks with time have become more mature and available for a broader audience, besides research or expert data engineers. Naturally, the complexity of the workflows increases as well. On one hand, some workflow steps are dependent on the output of others and have to be executed sequentially. On the other hand, other steps have no such dependencies between them and can be executed in parallel. In this post, I will consider Apache Spark for distributed computing. There are however other alternatives, e.g. <a href="https://dask.org/">Dask</a>, <a href="https://ray.io/">Ray</a>, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XsHJAPEuo5TwnOQZI1j7oQ.jpeg" /><figcaption>Preprocessing, multiple dependent steps. Icon credits: <a href="https://www.flaticon.com/authors/phatplus">phatplus</a>, <a href="https://www.flaticon.com/authors/eucalyp">Eucalyp</a>, <a href="https://www.flaticon.com/authors/freepik">Freepik</a></figcaption></figure><p>In addition to orchestration complexity, data transformations happening outside of the common infrastructure create data silos. Hence, it is important for these workflows to be integrated into the existing infrastructure. This comes with the additional benefit of saving time and money by not providing separate infrastructure. Nowadays, companies use <a href="https://kubernetes.io/">Kubernetes</a> as a platform to run an ample mix of workloads types, and ML workloads should also be one of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDu_Evb8ZkdDwI4KJLNCKg.jpeg" /><figcaption>Using common infrastructure for many types of workloads.</figcaption></figure><p>Is it possible to orchestrate and integrate these workloads in a Kubernetes cluster? Let’s start by taking a look into the tools and concepts involved here.</p><h3>Spark</h3><p>Apache Spark is a distributed computation framework. It is used widely for data-intensive processing tasks. It relies on spreading the computation across multiple nodes in the cluster, and aggregating the results in the end at one node, namely the driver. (More details can be found <a href="https://spark.apache.org/docs/latest/cluster-overview.html">here</a>.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*POsehONAax4_luKDk2JRdg.jpeg" /><figcaption>Spark Components. <a href="https://runawayhorse001.github.io/LearningApacheSpark/introduction.html">Source</a></figcaption></figure><h3>Kubernetes</h3><p>Kubernetes is a portable and extensible container orchestration framework. It has become the de-facto industry standard. It offers flexibility on the type of workloads that can be run on it and where these workloads are run, as long as they are containerized.</p><p>Similar to Spark, in Kubernetes, the <em>control plane </em>is responsible for distributing the workload into a set of nodes and making sure it continues to run. In the context of this post, the workload is a single step, e.g. processing step, model training, or model serving. The workload is defined in a manifest file (i.e. YAML file).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*WHF1xejO9ONaoY39qaHW5w.png" /><figcaption>Kubernetes components. <a href="https://kubernetes.io/docs/concepts/overview/components/">Source</a></figcaption></figure><h3>Spark on Kubernetes</h3><p>Executing a Spark job on a Kubernetes cluster is a piece of cake 🍰 (yummy!). One can either use the familiar spark-submit command with the native Spark Kubernetes scheduler, or use <a href="https://github.com/GoogleCloudPlatform/spark-on-k8s-operator#installation">spark-operator</a>, an open-source project that facilitates the operator pattern. Here, I will only consider the latter. The spark-operator makes specifying and running Spark applications similar to running other workloads on Kubernetes. It uses Kubernetes Custom Resource Definitions (CRDs) to specify and run them.<br>Practically, if the operator is installed, one only needs to write a manifest file and use kubectl utility to submit the job to the cluster. The control plane will take care of spinning up the driver and the requested executors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*2e-g7OXokZPLCYV6v94H9g.png" /><figcaption>Submitting a Spark Job to k8s cluster using spark operator. <a href="https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/docs/design.md">Source</a></figcaption></figure><h3>Kubeflow</h3><p>Kubeflow is a project dedicated to making ML workflows on Kubernetes scalable and easy to use. It covers from workflow orchestration to model serving stages. There are multiple independent projects composing Kubeflow.</p><ul><li><a href="https://www.kubeflow.org/docs/components/kfserving/">KFServing</a> is a component used for model deployment and serving. It handles multiple frameworks out-of-the-box. e.g. Tensoflow, PyTorch, ONNX, scikit-learn.</li><li><a href="https://www.kubeflow.org/docs/components/training/">Training Operators</a> are a collection of operators that help in training ML models. Supported frameworks are: Tensorflow, PyTorch, MXNet, etc.</li><li><a href="https://www.kubeflow.org/docs/components/katib/">Katlib</a> is a component dedicated to hyper-parameter tuning, for neural architecture search.</li><li><a href="https://www.kubeflow.org/docs/components/pipelines/">KFPipelines</a> helps orchestrate and execute each step of the pipeline in the platform.</li></ul><p>Considering again the stages of an ML workflow, Kubeflow is a platform that helps in all those stages. In the processing step, one can perform all sorts of transformations, as it will be shown below. For model training, training operators can be used out-of-the-box or via custom code wrapped in a Docker container. The same logic applies to the serving stage. ML models can be made available via KFServing, or via containerized custom code.</p><h3>Kubeflow Pipelines</h3><p>Kubeflow Pipelines provides a platform for orchestrating ML workflows based on containers on top of a Kubernetes cluster. A <em>pipeline</em> is a description of such a workflow. It is composed of <em>components</em> and <em>relations</em> between these components forming a graph. A component during the execution will be translated into a pod. The component is practically a set of code that performs one step in the workflow, e.g. train a model or transforming data. After this component finishes executing, the next one starts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IR7MQwzIqDWgptQc6j5cFg.png" /><figcaption>A sample KF pipeline.</figcaption></figure><h3>Components and Component Specification</h3><p>A Kubeflow Pipeline component is a self-contained code block that performs one of the steps in the pipeline. Each component is packaged as a Docker image or as a manifest file. To execute the component, a <em>component specification</em> must be available. It defines the component’s metadata, interface, and implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S_1RpxuFtB7VI10AOZjnDA.jpeg" /></figure><h3>Spark on Kubeflow on Kubernetes</h3><p>The remaining challenge is to orchestrate a Spark job from Kubeflow and submit it to the cluster. This is solved using <em>pipeline components for kubernetes </em>(G<a href="https://github.com/kubeflow/pipelines/tree/master/components/kubernetes">ithub</a>). These components allow performing commands like kubectl apply, kubectl get, kubectl delete against the cluster during pipeline execution. The <em>k8s apply component</em> starts by loading a manifest file and performs kubectl apply. For the case of a Spark job, it loads the job manifest file and submits it to the cluster. A sparkapplication resource is created in the cluster. Similarly, the <em>k8s get component</em> gets information from the <em>control plane</em>. In the example of a Spark job, it periodically polls the <em>control plane</em> to get the status of the job. Once the job is in COMPLETED state, the pipeline moves to the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l4FP3SlP9wRCnzbYcKkZrQ.jpeg" /><figcaption>KF Pipeline Spark job orchestration. Icon credits: <a href="https://www.flaticon.com/authors/freepik">Freepik</a>, <a href="https://pngtree.com/so/document-clipart">document-clipart</a></figcaption></figure><p>Here is an example manifest file for a Spark job. It calculates an approximate value of Pi(π):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5aa58d146ae419d34fd8c98f53670ff3/href">https://medium.com/media/5aa58d146ae419d34fd8c98f53670ff3/href</a></iframe><p>The next step is to use the <em>k8s apply component</em>. The input to this component is the manifest file, and the output will be, among others, the sparkapplication name. The following code snippet will make sure the job is submitted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17ba4cc1d443cff2db4ccbd1af4f4fe6/href">https://medium.com/media/17ba4cc1d443cff2db4ccbd1af4f4fe6/href</a></iframe><p>After the apply operation, the execution engine has to wait for the job to complete before moving on. Using the <em>k8s get component</em>, it gets the application’s state and iterates until the job achieves COMPLETED state. The iteration is done using recursion and the <a href="https://kubeflow-pipelines.readthedocs.io/en/latest/source/kfp.dsl.html#kfp.dsl.Condition">dsl.Condition</a> instruction. The @graph_component decorator indicates recursive execution for the function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a1297e0397074bc4f81b13a3a5571b3/href">https://medium.com/media/5a1297e0397074bc4f81b13a3a5571b3/href</a></iframe><p>Once the application is completed, the execution will carry on with other pipeline steps.</p><p>The full source code used here can be found on <a href="https://github.com/sbakiu/kubeflow-spark">Github</a>.</p><h3>Summary</h3><p>It is impressive to see how fast the ecosystem in ML is moving and the degree of integration it is facilitating. Now, it is possible to orchestrate Spark jobs with Kubeflow Pipelines running on a Kubernetes cluster. The underlying infrastructure is almost irrelevant. It can be a local PC, a self-managed K8s cluster, or a public cloud provider managed K8s deployment. One only needs to add the building blocks on top.</p><p>Great and exciting times are ahead!</p><p>At <a href="http://www.data-max.io/">Data Max</a> we help companies truly become data-powered organizations. We strive for technical excellence, and passion for what we do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=830f802a99fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker best-practices in Apache Spark application deployments]]></title>
            <link>https://sbakiu.medium.com/docker-best-practices-in-apache-spark-application-deployments-c013ad5aab9e?source=rss-a0654b43131a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c013ad5aab9e</guid>
            <category><![CDATA[multi-stage-builds]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sadik Bakiu]]></dc:creator>
            <pubDate>Tue, 01 Jun 2021 14:15:52 GMT</pubDate>
            <atom:updated>2021-06-01T14:16:20.078Z</atom:updated>
            <content:encoded><![CDATA[<p>Apache Spark has become the de facto standard tool for distributed data processing. Similarly, Kubernetes has become the de facto standard container orchestration tool. Deploying Spark jobs on Kubernetes has been natively supported since <a href="https://spark.apache.org/releases/spark-release-2-3-0.html">version 2.3</a>. An alternative to such deployment, is available using <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/operator/">operator</a> pattern, see <a href="https://github.com/GoogleCloudPlatform/spark-on-k8s-operator">spark-on-k8s-operator</a>. Both these solutions start by preparing a container image followed by deploying it in the cluster. However, these solutions follow different principles on building their images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*2LJK4Tuyam5lcpMyZmU3JA.png" /><figcaption>Spark-provided container image build</figcaption></figure><p>On the one hand, the Spark-provided build scripts start by building Spark locally and then adding the application specific artifacts. On the other, in the operator solution the application specific artifacts are added by building an image on top of a provided base image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*Wk9M0aSVJYw8aAGqC4tzbg.png" /><figcaption>Kubernetes operator container image build</figcaption></figure><p>In my experience, building Spark locally is rarely needed, and starting with a predefined base image can be limiting. Therefore, here I will present a couple of optimized and extensible Dockerfile templates. The aim is to use Docker multi-stage builds to reduce build time for the container image, especially time needed to download Spark itself and other dependencies that do not change often. The source code including the Dockerfile(s) can be found <a href="https://github.com/sbakiu/spark-dockerfile-multi-stage">here</a>.</p><h3>Spark on Kubernetes</h3><p>Starting from a client machine, with access configured to the cluster, spark-submit submits an application to the cluster.</p><figure><a href="https://spark.apache.org/docs/latest/running-on-kubernetes.html"><img alt="Image credits: https://spark.apache.org/docs/latest/img/k8s-cluster-mode.png" src="https://cdn-images-1.medium.com/max/761/1*tkWi16Clt_6RjLJNmyLVkg.png" /></a><figcaption>Image credits: Spark Docs <a href="https://spark.apache.org/docs/latest/running-on-kubernetes.html">https://spark.apache.org/docs/latest/running-on-kubernetes.html</a></figcaption></figure><p>1. Initially, the Spark driver is created in a Pod.<br>2. The driver then created executors, running also in Pods and connects to them.<br>3. Once the processing is done, executors are terminated and cleaned up. The driver pod remains in completed state.</p><h3>Multi-stage builds</h3><p><a href="https://docs.docker.com/develop/develop-images/multistage-build/">Multi-stage builds</a> are used to reduce the resulting Docker image size, while also reducing the build time. Therefore in the template files, the following split has been followed:<br> 1. Starting from openjdk base image, a few required packages are installed</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fe538a5ca774d91fa44cb919d9e6399/href">https://medium.com/media/7fe538a5ca774d91fa44cb919d9e6399/href</a></iframe><p>2. Spark is installed</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f2eae1d0c93c418d68c4266983d026e/href">https://medium.com/media/0f2eae1d0c93c418d68c4266983d026e/href</a></iframe><p>3. A few system configurations are made, like setting SPARK_HOME environment variable</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a0fd102418626791bb88c96f72462f7/href">https://medium.com/media/9a0fd102418626791bb88c96f72462f7/href</a></iframe><p>4. Add support for public cloud object storage systems like S3 and GCS</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/909d460b3693e2753500104d4a58ae39/href">https://medium.com/media/909d460b3693e2753500104d4a58ae39/href</a></iframe><p>5. In this final step, Scala/Java Spark applications differ from PySpark application. The former only needs to copy the .jar artifact to the designated location, while the latter needs to first have python installed (together with the application specific dependencies) and copy the artifacts in the designated directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5aae8c180c394f53e941eaf453ea8e26/href">https://medium.com/media/5aae8c180c394f53e941eaf453ea8e26/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a132bc67d5cf3c471dbca359ce0ca18/href">https://medium.com/media/3a132bc67d5cf3c471dbca359ce0ca18/href</a></iframe><h3>Testing</h3><p>To test the application deployment, the example spark-pi application will be used. Make sure you have access to a Kubernetes cluster. If you don’t have one, you can use <a href="https://minikube.sigs.k8s.io/docs/">minikube</a> to create a local one.</p><p>Run kubectl cluster-info to get the master IP address and the port where the jobs can be submitted. Next one can build the Docker images.</p><p>For Scala run: docker build -t localhost:5000/spark-local -f Dockerfile .</p><p>For Python run: docker build -t localhost:5000/spark-local-py -f Dockerfile-python .</p><p>And finally deploy the applications on the cluster:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c716e5f9e816987a7b7de9886c77fb6c/href">https://medium.com/media/c716e5f9e816987a7b7de9886c77fb6c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/508666e225ce6d59f0176c802cf46002/href">https://medium.com/media/508666e225ce6d59f0176c802cf46002/href</a></iframe><h3>Next Steps</h3><p>There are a few things that can be improved in this deployment.</p><p>Firstly, the applications are being executed by the root user. This is of course not recommended in production deployments because of the extensive permissions this user has.</p><p>Secondly, based on the organizational set up, credentials need to be added/ingested to the containers. There are a lot of possibilities to achieve this. Therefore, it is not feasible to be included in a template solution. Nonetheless, it cannot be avoided 😄.</p><h3>Summary</h3><p>While Spark and Kubernetes have gone a long way together, container image building best practices are not always being followed. Here, I focus on bringing in multi-stage build principle for Spark job container images.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c013ad5aab9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DIY Analytics Platform]]></title>
            <link>https://sbakiu.medium.com/diy-analytics-platform-66638cc6a92f?source=rss-a0654b43131a------2</link>
            <guid isPermaLink="false">https://medium.com/p/66638cc6a92f</guid>
            <category><![CDATA[hive]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[jupyter]]></category>
            <dc:creator><![CDATA[Sadik Bakiu]]></dc:creator>
            <pubDate>Wed, 31 Mar 2021 06:24:31 GMT</pubDate>
            <atom:updated>2021-03-31T06:24:31.983Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qGg4y8CzhFfKmVr4" /><figcaption>Photo by <a href="https://unsplash.com/@nahakiole?utm_source=medium&amp;utm_medium=referral">Robin Glauser</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are a lot of platforms and providers out there offering great tools and solutions falling in the scope of an Analytics Platform. Many of them requiring zero manual effort to set them up. But sometimes what is missing is just that little bit of customization to fit our needs perfectly. Often I struggled to find a place where I could do an explorative analysis of multiple data sources and have the tables, table structures, and intermediate results available when developing for the production data pipeline. In this post, I will share how to build a tiny analytics platform on a local machine, having the power to customize every aspect of it. The documentation and code used in this tutorial are in <a href="https://github.com/sbakiu/analytics-platform-diy">Github</a>.</p><h3>Requirements for an Analytics Platform</h3><p>There are four main aspects such a platform needs to satisfy:</p><ul><li><strong>Data Source Discovery —</strong> enables access to many data sources. Preferably to all of them, because the more data the better, right? Well, not always, but let’s not get into that sort of argument, shall we?</li><li><strong>Experimentation —</strong> whoever has worked in an analytics-related project knows the actual data is not what it looks like. Many ugly, and sometimes nice, surprises hide in there. Hence, it is important to have the freedom to experiment with different tools, libraries, programming languages, etc.</li><li><strong>Handle Workload — </strong>experimentation alone will not bring in any revenue. The actual <em>$$$</em> come from making the full results available to target consumers, be it recommendations to end-users or actions triggered based on data insight. That’s why currently in the job market there is huge demand for Data Engineering and ML Engineering.</li><li><strong>Orchestration —</strong>most of the time, data flows between multiple stages getting cleansed, enriched, transformed, and so on. Manually triggering one step after the other is at least time-consuming. Orchestration capabilities would take care of triggering the sequence of steps in the right order and automatically.</li></ul><h3><strong>Tooling</strong></h3><p>As the basis for the platform, my recommendation is a framework that is widely adopted by the community, easy to work with and you can have access to independent of your personal infrastructure changes. I have chosen to use <a href="https://minikube.sigs.k8s.io/docs/">minikube</a> (local Kubernetes), however, there are other great options outthere that can be used.</p><p>The first step for the platform is to create a metastore. Metastore is a database storing data about the data. It stores information about databases in the platform, tables and also provides a certain degree of authorization controls. And most importantly, this service should be shared between other players on the platform. <a href="https://github.com/apache/hive">Apache Hive</a> is one such service. Sadly, there is no easy way to deploy it in a Kubernetes cluster, therefore it has to be done manually, step by step. See <a href="https://github.com/sbakiu/analytics-platform-diy#install-metastore">ReadMe</a> for detail.</p><p>From now on, it becomes less complicated and includes fewer moving parts. After having the metastore problem solved, next step is to satisfy the requirements for the platform. To ensure the discoverability of a wide range of data sources, <a href="https://github.com/trinodb/trino">Trino</a> (formerly known as Presto) is a great option. It is a distributed SQL query engine designed to query large data sets distributed over one or more heterogeneous data sources. Deployment is very straightforward with a helm chart.</p><p>Next in line is experimentation. <a href="https://jupyter.org/">Jupyter Notebooks</a> and <a href="https://github.com/jupyterhub/jupyterhub">Jupyterhub</a> have become the go-to tools for every task related to data exploration. They are easy to use, provide a wide range of capabilities, and are ridiculously easy to extend with community-provided plugins or external packages.</p><p>To handle distributed large-scale workload execution, <a href="https://github.com/apache/spark">Spark</a> is the de facto standard across all industries. <a href="https://github.com/GoogleCloudPlatform/spark-on-k8s-operator">Spark-on-k8s-operator</a> makes it especially easy to add Spark capabilities to the platform.</p><p>Orchestration is something not included in the repository, however, it would be a choice between Airflow and Argo. Both tools offer Pipeline as code capabilities and are actively supported by great communities.</p><h3><strong>Next Steps</strong></h3><p>There are a few things, I did not get around to adding in the deployment:</p><ul><li><a href="https://github.com/dremio/dremio-oss">Dremio </a>— would be an alternative to Trino. It uses Apache Arrow, and it is easy to deploy in a Kubernetes cluster. Checkout <a href="https://github.com/dremio/dremio-cloud-tools">https://github.com/dremio/dremio-cloud-tools</a> .</li><li><a href="https://github.com/argoproj/argo-workflows">Argo</a> or <a href="https://github.com/apache/airflow">Airflow </a>— used for orchestration. Although Argo has a tighter Kubernetes integration, Airflow is a bit more mature for data-related tasks. It is a difficult choice between the two.</li><li><a href="https://github.com/minio/minio">Minio</a> — is widely used to provide a performant unified access layer for object storage, be it AWS S3 or GCS from GCP.</li></ul><h3><strong>Summary</strong></h3><p>While there are a lot of offerings in the market for analytics platforms, we prefer the ones that can be tailored to our needs. Tools like Hive, Trino, Jupyter, and Spark cover a large portion of the responsibilities of an analytics platform. Nonetheless, it is important to have a base layer allowing easy extension. Kubernetes, Helm, and so on, certainly fit the bill and make building a platform tailored to our infrastructure and personal preferences a piece of cake.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66638cc6a92f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Productionalizing ML with Kubernetes, Kubeflow and seldon-core]]></title>
            <link>https://sbakiu.medium.com/productionalizing-ml-with-kubernetes-kubeflow-and-seldon-core-39aed36ade83?source=rss-a0654b43131a------2</link>
            <guid isPermaLink="false">https://medium.com/p/39aed36ade83</guid>
            <category><![CDATA[seldon-core]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sadik Bakiu]]></dc:creator>
            <pubDate>Tue, 09 Mar 2021 08:56:29 GMT</pubDate>
            <atom:updated>2021-04-03T08:00:45.981Z</atom:updated>
            <content:encoded><![CDATA[<h3>Make it to prod for ML with Kubernetes, Kubeflow and seldon-core</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fodk3pWQY3CCX8CZ" /><figcaption>Photo by <a href="https://unsplash.com/@mcsheffrey?utm_source=medium&amp;utm_medium=referral">Connor McSheffrey</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A big challenge businesses faces is the deployment of machine learning models in production environments. It requires dealing with a complex set of moving parts through different pipelines. Once the models are developed, they need to be trained, deployed, monitored and kept track of.</p><p>This post tries to describe, how using <a href="https://aws.amazon.com/eks"><strong>AWS EKS</strong></a>, <a href="https://www.kubeflow.org/docs/components/pipelines/overview/pipelines-overview/"><strong>Kubeflow-Pipelines</strong></a> and <a href="https://docs.seldon.io/projects/seldon-core/en/latest/"><strong>seldon-core</strong></a> enables productionalizing the deployment of ML models including important components like CI/CD pipeline, Model Registry and a scalable inference layer using modern microservice architecture. All the necessary steps for creating this architecture are available on <a href="https://github.com/sbakiu/ml-kf-pipeline"><strong>Github</strong></a>.</p><p>There are essentially 3 stages in the ML execution pipeline. Firstly, there is the preprocessing stage, followed by training stage and lastly there is inference. <br>In the first stage, raw data is received. It can be unstructured, semistructured or structured data and from there (important) features are extracted. In the training stage, it is determined how much we care about those features, hence building the models. Once the built model has satisfactory performance and acurracy, it is exposed to users/partners to ripe the benefits of the endevour. And that in of itself, produces more data that we can use to advance the development of the model, in the next iteration.</p><p>Looking at a company that is not internet native, taking advantage of machine learning technologies and implementations, is something new and intriguing. However there are challenges. There have been decades of software development, massive investments have been made in building the infrastructure. Years of experience have been collected in process engineering, tooling, infrastructure and monitoring. Some companies earlier and some later have already collected a lot of experience. On top of that, regulations come along that have to be followed. Therefore, it is ciritical to think of ML as part of the ecosystem that has to integrated, not as an independent software system that can live on its own.</p><p>ML project usually start with research style environment, where the experiments are usually run on small data dumps, on local Jupyter Notebooks, doing some iterative work. Moving it to deploy into production can be a gruelling task. When moving from a small subset of data, to the real production, the workload are several orders of magnitude bigger. Data might be streaming and comes with certain time constraints. Integration with operational databases is needed without causing disruptions. To analyze these data, and extract meaningful insights is suddenly not easy anymore and requires much more processing power.</p><p>Another challenge in the local set up is keeping track of what experiments yields optimal results. How can one go back to version that provided these results. One also needs to be able to test several approaches at the same time to guarantee maximum benefits from this endevour. And once all that is done, one needs to monitor the model on real time, check for performance drift, and incorporate the feedback loop in the pipeline.</p><p>To achieve this, many teams need to collaborate, data needs to be available, upto date, models need to be developed, application developers need to incorporate this new step in their flow, and devops engineers need to enable deployment. On top, the question raises, where do the models train, should it be done on production, or in earlier stages. How are they promoted to production?</p><p>The challenges mentioned above are hurdles potential pitfall for the project. Maybe training process is too memory/space intensive to effectively run with partial or whole production workload. Maybe data silos make within the company make it impossible to have a full training execution on current data. Maybe inter-team communication overhead, makes the project execution slow and costly. The result is that 80% of ML initiatives, do not make it into production, failing to provide value to stakeholders.</p><h3>Tooling</h3><p>It is important to use the right tool for the right job, therefore first step is looking at tooling.<br>It is necessary to have a reliable, scalable base layer for the infrastructure. One such technology is <strong>Kubernetes</strong>. It can be any managed or not managed distribution. Kubernetes provides a scalable environment for deployments. It is widely used in the industry today, in all sorts of set ups. In addition, Kubenetes provides a low barrier to entry.</p><p><strong>Kubeflow Pipelines </strong>is a great tool to orchestrate ML pipelines. It is robust, reliable and provides a great developer experience (DX). The pipelines themselves are defined as code, providing possibility to track and rollback changes. The tool supports multiple execution engines and is open-source.</p><p><a href="https://aws.amazon.com/s3/"><strong>S3</strong></a> in our case is used as poor man’s choice of a model registry. We push our trained models there, and make them available for the final stage, namely staging. Currently there are excellent free to use or open-source tools for model registry: <a href="https://github.com/VertaAI/modeldb"><strong>Model DB</strong></a>, <a href="https://www.mlflow.org/docs/latest/model-registry.html"><strong>MLflow Model Registry</strong></a>, just to name a few.</p><p><strong>Seldon-core</strong> is a powerful tool to deploy and monitor ML models on Kubernetes clusters. It supports multiple ML frameworks and deployment setups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPiWJhmmMwFrdsWNxAmTAQ.png" /><figcaption>Modern ML Pipeline</figcaption></figure><p>How an automated pipeline might look like, is depicted in the picture. <br>The starting point are a set of data sources. The pipeline orchestrates preprocessing, model training and registration of the model in model registry. Each of these steps might contain multiple substeps and might use different set of technologies. For instance, in preprocessing a combination of Spark and simple python transformations can be used. Training includes training of more than one model using multiple frameworks, e.g. scikit learn, Tensorflow, etc. And lastly, all the produced models need to be registered in the registry.<br>Final step in the pipeline, after successful completion of the previous ones is deployment, done using seldon-core and kubernetes manitfests.</p><h3>Summary</h3><p>In conclusion, ML project are as exiting as they are challenging to get them right. Picking and developing the right model for the problem at hand, can be the fast and inexpensive part. Challenges raise when the initial set up of the project does not take into account, non-functional requirments of the productiove enviroment, or inter-team collaboration becames a hinderance for the project. To help minimize the effect of these issues, and integrate the workload in the bigger ecosystem, specialized tools come to the rescue. Such tools are: Kubernetes, kubeflow-pipelines, seldon-core, native cloud managed services and many others that will probably be published in the next days.</p><h3>Resources</h3><ul><li>Start EKS Cluster (<a href="https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html">https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html</a>)</li><li><a href="https://aws.amazon.com/premiumsupport/knowledge-center/eks-cluster-connection/">https://aws.amazon.com/premiumsupport/knowledge-center/eks-cluster-connection/</a></li><li>Deploy Kubeflow on EKS (<a href="https://www.kubeflow.org/docs/aws/">https://www.kubeflow.org/docs/aws/</a> )</li><li><a href="https://docs.seldon.io/projects/seldon-core/en/latest/workflow/install.html">https://docs.seldon.io/projects/seldon-core/en/latest/workflow/install.html</a></li><li>Seldon Kubeflow example (<a href="https://github.com/SeldonIO/seldon-core/tree/master/examples/kubeflow">https://github.com/SeldonIO/seldon-core/tree/master/examples/kubeflow</a> )</li><li><a href="https://github.com/sbakiu/ml-kf-pipeline">https://github.com/sbakiu/ml-kf-pipeline</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39aed36ade83" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>