I have a Spark RDD of over 6 billion rows of data that I want to use to train a deep learning model, using train_on_batch. I can't fit all the rows into memory so I would like to get 10K or so at a time to batch into chunks of 64 or 128 (depending on model size). I am currently using rdd.sample() but I don't think that guarantees I will get all rows. Is there a better method to partition the data to make it more manageable so that I can write a generator function for getting batches? My code is below: data_df = spark.read.parquet(PARQUET_FILE) print(f'RDD Count: {data_df.count()}') # 6B+ data_sample = data_df.sample(True, 0.0000015).take(6400) sample_df = data_sample.toPandas() def get_batch(): for row in sample_df.itertuples(): # TODO: put together a batch size of BATCH_SIZE yield row for i in range(10): print(next(get_batch())) Continue reading...