ContinualAI / ContinualAI/avalanche

Multiple buffer resize calls made in ParametricBuffer

Open
#918 4 comments 0 reactions 0 assignees View on GitHub
Feature - Low Priority Training
Dominant language
Python
Stars
2.1k
Forks
321
PR merge metrics
No merged PRs in 30d

Description

Hi,
I'm working with ReplayBuffers and noticed that these methods are extremely slow. On digging into the code I noticed that the `update` function in this class calls `resize` 3 times for a single update, and since this involves going through the entire data, it ends up with a much longer runtime. The fix should be fairly simple.

Relevant Code snippets:
lines 355 - 373 of storage_policy.py
```
# update buffers with new data
for group_id, new_data_g in new_groups.items():
ll = group_to_len[group_id]
if group_id in self.buffer_groups:
old_buffer_g = self.buffer_groups[group_id]
old_buffer_g.update_from_dataset(strategy, new_data_g) ### Call 1
old_buffer_g.resize(strategy, ll) ### Call 2
else:
new_buffer = _ParametricSingleBuffer(
ll, self.selection_strategy
)
new_buffer.update_from_dataset(strategy, new_data_g)
self.buffer_groups[group_id] = new_buffer

# resize buffers
for group_id, class_buf in self.buffer_groups.items():
self.buffer_groups[group_id].resize(
strategy, group_to_len[group_id]
) ### Call 3
```

`update_from_dataset` function calls resize within its call - lines 440-442
```
def update_from_dataset(self, strategy, new_data):
self.buffer = AvalancheConcatDataset([self.buffer, new_data])
self.resize(strategy, self.max_size)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.