ancient-wolf-19325
06/26/2024, 9:48 AMmap_task requires all data to be available upfront, which is not ideal for your use case of batch processing large datasets incrementally. However, there are workarounds to achieve batch processing without fully loading the dataset into memory.
Approach 1: Use Flyte Dynamic Workflows with Batching
You can use a dynamic workflow to generate batches of data and launch tasks for each batch. This allows you to process data incrementally without loading the entire dataset at once.
Approach 2: Custom Producer-Consumer Pattern
Another approach is to implement a producer-consumer pattern using Flyte tasks. The producer task can generate batches of data and enqueue them, while consumer tasks dequeue and process each batch.
Here’s a simplified example using a dynamic workflow to handle batches:
import flytekit
from flytekit import task, workflow, dynamic
from typing import List
@task
def generate_batches(batch_size: int) -> List[List[int]]:
# Simulate generating batches of data
data = list(range(150000000)) # Example data
return [data[i:i + batch_size] for i in range(0, len(data), batch_size)]
@taskancient-wolf-19325
06/26/2024, 9:48 AM>>```def process_batch(batch: List[int]) -> int: # Simulate processing a batch return sum(batch) @dynamic def dynamic_workflow(batch_size: int) -> int: batches = generate_batches(batch_size=batch_size) results = [] for batch in batches: results.append(process_batch(batch=batch)) return sum(results) @workflow def main_workflow(batch_size: int = 1000000) -> int: return dynamic_workflow(batch_size=batch_size) ``` Key Points 1. Batch Generation: The
generate_batches task creates batches of data.
2. Batch Processing: The process_batch task processes each batch.
3. Dynamic Workflow: The dynamic_workflow handles the orchestration of batch generation and processing.
This approach allows you to process large datasets in batches without loading the entire dataset into memory at once.
Would you like more detailed steps or a different approach?
Sources:
- Flyte Map Tasks
Slack Link
https://flyte-org.slack.com/archives/CP2HDHKE1/p1719395293.711739 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.