I'm trying to design a system where the caller sends data to celery workers which run on GPU machines, they do some processing and return the results to the caller. Since GPUs can process a batch-full of data in parallel (say N items in parallel), it makes sense for the celery task to accept N items of data and process all N items together.
On the caller side, I am able to use chunks to break apart my list of data items into sublists of some fixed BATCH_SIZE.
job = tasks.predict.chunks(texts, BATCH_SIZE)
result = job.apply_async()
However, my issue is that I would like to specify the BATCH_SIZE on the receiving end (worker) instead of the caller, because each worker may have a different limit on the number of data items it can process in one batch (because GPU memory size can vary across different workers).
What's the best way to go about doing this? I want the celery worker to be able to consume an arbitrary N items from the data workload during a single task.