Skip to content

Commit

Permalink
make RingBuffer sharable across spawned processes
Browse files Browse the repository at this point in the history
  • Loading branch information
hnyu committed Jan 16, 2025
1 parent bbe28a1 commit 047e9dd
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions alf/utils/data_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ def _create_buffer(spec_path, tensor_spec):

self._buffer = alf.nest.py_map_structure_with_path(
_create_buffer, data_spec)
self._flattened_buffer = alf.nest.map_structure(
lambda x: x.view(-1, *x.shape[2:]), self._buffer)

if allow_multiprocess:
self.share_memory()
Expand Down Expand Up @@ -272,8 +270,8 @@ def _set(buf, bat):
indices = env_ids * self._max_length + self.circular(
current_pos)
alf.nest.map_structure(
lambda buf, bat: buf.__setitem__(indices, bat.detach()),
self._flattened_buffer, batch)
lambda buf, bat: buf.view(-1, *buf.shape[2:]).__setitem__(
indices, bat.detach()), self._buffer, batch)

self._current_pos[env_ids] += 1
current_size = self._current_size[env_ids]
Expand Down

0 comments on commit 047e9dd

Please sign in to comment.