Performance issue while calling mlflow endpoint
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2024 11:24 AM
Hi,
I have pyspark dataframe and pyspark udf which calls mlflow model for each row but its performance is too slow.
Here is sample code
def myfunc(input_text):
restult = mlflowmodel.predict(input_text)
return result
myfuncUDF = udf(myfunc,StringType())
df = spark.sql("select * from test")
df=df.withColumn("test_result",myfuncUDF("input_text"))
Please suggest how to improve the performance.
Regards,
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 04:28 AM
Thank you Kaniz for the suggestions. This is really helpful. I even tried using applyInPandas. Not sure if this is better than spark UDF. If not can you help me in converting this function to pandas udf or any other optimized function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 11:36 PM
Thank you @Retired_mod, its really helpful and did worked. Another quick question, I have to pass 2 parameters as input to myfunc. Please help how to pass multiple parameters.
def myfunc(input_text, param2):
# Assuming mlflowmodel is defined elsewhere
result = mlflowmodel.predict(input_text, param2)
return result
# Create a Pandas UDF
@pandas_udf(StringType())
def myfunc_udf(input_text_series: pd.Series, param2_series: pd.Series) -> pd.Series:
return input_text_series.apply(myfunc) ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 05:05 AM
Hi Kaniz,
I started getting following error after using myfunc_udf with 2 parameters.
pythonException: 'ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
Regards,
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 06:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 01:40 AM
I need to send two arguments to myfunc, thus I have another brief question. I need some guidance on how to pass in many parameters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 06:12 AM
Hello Sanjay,
Could you please share your code snippet as per latest changes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 07:26 AM - edited 02-07-2024 07:39 AM
pythonException: 'ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 09:25 PM
Hello Sanjay,
The above code don't have the df defined. Can you share your df.show() output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 07:19 PM
So good

