<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: himadri bhattacharjee</title>
    <description>The latest articles on DEV Community by himadri bhattacharjee (@himadri_bhattacharjee_67e).</description>
    <link>https://dev.to/himadri_bhattacharjee_67e</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3449208%2Fd004d6b5-9083-471a-8e71-5fbe1fa40a32.png</url>
      <title>DEV Community: himadri bhattacharjee</title>
      <link>https://dev.to/himadri_bhattacharjee_67e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himadri_bhattacharjee_67e"/>
    <language>en</language>
    <item>
      <title>Question: Alternative to MLeap for Real-Time Inference Without Spark Context with SparkXGBClassifier</title>
      <dc:creator>himadri bhattacharjee</dc:creator>
      <pubDate>Thu, 21 Aug 2025 05:55:00 +0000</pubDate>
      <link>https://dev.to/himadri_bhattacharjee_67e/question-alternative-to-mleap-for-real-time-inference-without-spark-context-with-sparkxgbclassifier-3dhj</link>
      <guid>https://dev.to/himadri_bhattacharjee_67e/question-alternative-to-mleap-for-real-time-inference-without-spark-context-with-sparkxgbclassifier-3dhj</guid>
      <description>&lt;p&gt;We are exploring alternatives to &lt;strong&gt;&lt;a href="https://github.com/combust/mleap" rel="noopener noreferrer"&gt;MLeap&lt;/a&gt;&lt;/strong&gt; for running inference without Spark, since MLeap has limitations with Spark/PySpark version compatibility and library updates.  &lt;/p&gt;




&lt;h4&gt;
  
  
  Our Setup &amp;amp; Goal
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Environment&lt;/strong&gt;: PySpark 3.5.5
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Algorithm&lt;/strong&gt;: Distributed ML training using XGBoost with Spark.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Goal&lt;/strong&gt;: Run &lt;strong&gt;real-time inference&lt;/strong&gt; without requiring a Spark session/context, to reduce overhead and response latency.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  What We Did
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Took a dataset (Titanic), converted it to Parquet, and split it into 80% (train) and 20% (test).
&lt;/li&gt;
&lt;li&gt;Trained with Spark (80% data) including preprocessing + XGBoost.
&lt;/li&gt;
&lt;li&gt;Evaluated on Spark (20% data) and logged the trained model.
&lt;/li&gt;
&lt;li&gt;Tried multiple logging/serialization approaches:

&lt;ul&gt;
&lt;li&gt;MLflow &lt;code&gt;pyfunc&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;ONNX
&lt;/li&gt;
&lt;li&gt;XGBoost native model (JSON/binary)
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;For inference: loaded the same 20% data, applied preprocessing &lt;strong&gt;outside Spark&lt;/strong&gt;, reloaded the trained model, and ran predictions.
&lt;/li&gt;
&lt;/ol&gt;




&lt;h4&gt;
  
  
  The Problem
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In all approaches tested (MLflow &lt;code&gt;pyfunc&lt;/code&gt;, ONNX, XGBoost native save/load), &lt;strong&gt;accuracy differs&lt;/strong&gt; between:

&lt;ul&gt;
&lt;li&gt;Spark-based evaluation (during training)
&lt;/li&gt;
&lt;li&gt;Non-Spark inference (real-time service)
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;It seems &lt;strong&gt;precision is lost&lt;/strong&gt; when the model is saved and reloaded outside Spark.
&lt;/li&gt;

&lt;/ul&gt;




&lt;h4&gt;
  
  
  Main Requirement
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The accuracy from &lt;strong&gt;Spark-based evaluation&lt;/strong&gt; and &lt;strong&gt;non-Spark inference&lt;/strong&gt; must match.
&lt;/li&gt;
&lt;li&gt;Need a solution to serialize/deserialize models that works across Spark training and non-Spark inference.
&lt;/li&gt;
&lt;li&gt;Prefer portable formats (JSON or similar).
&lt;/li&gt;
&lt;li&gt;Must avoid Spark context overhead at inference for real-time serving.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Question
&lt;/h4&gt;

&lt;p&gt;👉 Is there any solution or alternative to &lt;strong&gt;MLeap&lt;/strong&gt; for serving models trained with Spark (e.g., XGBoost with PySpark), but performing inference outside of Spark (lightweight, real-time)?  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should support &lt;strong&gt;PySpark 3.5.5&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Must work with &lt;strong&gt;XGBoost distributed training&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Should prevent accuracy mismatch between Spark and non-Spark inference
&lt;/li&gt;
&lt;li&gt;JSON or portable serialization preferred
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any recommendations for frameworks, libraries, or best practices beyond MLeap would be greatly appreciated.  &lt;/p&gt;

</description>
      <category>pyspark</category>
    </item>
  </channel>
</rss>
