brave-yak-3559
08/07/2023, 12:16 AMbotocore.*exceptions*.ClientError: An *error* occurred (ValidationException) when calling the PutItem operation: Item size has exceeded the maximum allowed size . the sample data i am working has 1.5 mil rows but for the real data the number of rows can be around 10 million. below is my code. any suggestion is appreciated. Thanks.
@project(name="sample")
class SampleFlow(FlowSpec):
@batch(image=DEFAULT_IMAGE, **{'cpu': 4, 'memory': 20480})
@step
def start(self):
import pandas as pd
with S3() as s3:
s3obj = s3.get('<s3://data.csv>')
df = pd.read_csv(s3obj.path)
self.rows=df.to_dict('records')
self.next(self.ml_model,foreach='rows')
@batch(image=DEFAULT_IMAGE, **{'cpu': 6, 'memory': 15000})
@step
def ml_model(self):
import MLModel
row = self.input
result = MLModel(row)
result = {**row, **result}
self.result = result
print(result)
self.next(self.join_results)
@batch(image=DEFAULT_IMAGE, **{'cpu': 6, 'memory': 180000})
@step
def join_results(self,inputs):
import pandas as pd
dict_list = [inp.result for inp in inputs]
self.processed_df = pd.DataFrame(dict_list)
self.next(self.end)victorious-lawyer-58417
08/07/2023, 2:37 AMself.rows would have the 1.5M rows you mentioned. Hence foreach='rows' would results to a foreach over 1.5M items, which I think is what causes the error.
It takes a while to launch each task, so having a separate task for each row is going to be inconveniently slow.
A better approach is to chunk the rows and let each task handle a batch of data. You can do something like this below the self.rows line
batch_size = 10000
self.batches = [self.rows[i*batch_size:(i+1)*batch_size] for i in range(math.ceil(len(self.rows) / batch_size))]victorious-lawyer-58417
08/07/2023, 2:37 AMself.next(self.ml_model, foreach='batches')victorious-lawyer-58417
08/07/2023, 2:37 AMml_model step, you can have
for row in self.input
to then process one row at a timevictorious-lawyer-58417
08/07/2023, 2:39 AMbatch_size=10000 it'll do about 150 tasks, which is a much more reasonable number. You can test even larger batch sizes, which may make processing fasterbrave-yak-3559
08/07/2023, 2:42 AMbrave-yak-3559
08/07/2023, 2:42 AMvictorious-lawyer-58417
08/07/2023, 3:31 AMcpu s in @resources to increase parallelism in each taskbrave-yak-3559
08/07/2023, 6:07 AMvictorious-lawyer-58417
08/07/2023, 7:07 AM