I have:
- Large dataframe (parquet format, 100.000.000 rows, 4.5TB size) that contains some data (features)
- Several huge ML models (each one takes 5-15GB of RAM)
- Spark cluster (AWS EMR), typical node configuration is 8 CPU, 32 RAM, can be changed if needed.
I want to apply them using PySpark, but I always get some wired errors like:
- OOM
- Random timeouts (nodes doesn't return any result) -> node killed by YARN manager
I typically used code like
def apply_model(partition):
model = load(...) # load model only when apply this function to avoid serialization issue
for row in partition:
yield model.infer(row)
or
def apply_model(partition):
model = load(...) # load model only when apply this function to
yield from model.infer(partition)
and apply that using
df.select(...).rdd.mapPartitions(apply_model)
I can't broadcast model, by serialization reasons.
The question - how to apply the big python/any-non-jvm-based model to spark dataframe & avoid spark exceptions?