You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> assertlen(rb_pytree) ==3# the replay buffer has 3 elements!
85
+
86
+
.. note:: :meth:`~torchrl.data.replay_buffers.ReplayBuffer.extend` can have an
87
+
ambiguous signature when dealing with lists of values, which should be interpreted
88
+
either as PyTree (in which case all elements in the list will be put in a slice
89
+
in the stored PyTree in the storage) or a list of values to add one at a time.
90
+
To solve this, TorchRL makes the clear-cut distinction between list and tuple:
91
+
a tuple will be viewed as a PyTree, a list (at the root level) will be interpreted
92
+
as a stack of values to add one at a time to the buffer.
93
+
94
+
Sampling and indexing
95
+
~~~~~~~~~~~~~~~~~~~~~
96
+
97
+
Replay buffers can be indexed and sampled.
98
+
Indexing and sampling collect data at given indices in the storage and then process them
99
+
through a series of transforms and ``collate_fn`` that can be passed to the `__init__`
100
+
function of the replay buffer. ``collate_fn`` comes with default values that should
101
+
match user expectations in the majority of cases, such that you should not have
102
+
to worry about it most of the time. Transforms are usually instances of :class:`~torchrl.envs.transforms.Transform`
103
+
even though regular functions will work too (in the latter case, the :meth:`~torchrl.envs.transforms.Transform.inv`
104
+
method will obviously be ignored, whereas in the first case it can be used to
105
+
preprocess the data before it is passed to the buffer).
106
+
Finally, sampling can be achieved using multithreading by passing the number of threads
107
+
to the constructor through the ``prefetch`` keyword argument. We advise users to
108
+
benchmark this technique in real life settings before adopting it, as there is
109
+
no guarantee that it will lead to a faster throughput in practice depending on
110
+
the machine and setting where it is used.
111
+
112
+
When sampling, the ``batch_size`` can be either passed during construction
113
+
(e.g., if it's constant throughout training) or
114
+
to the :meth:`~torchrl.data.replay_buffers.ReplayBuffer.sample` method.
115
+
116
+
To further refine the sampling strategy, we advise you to look into our samplers!
117
+
118
+
Here are a couple of examples of how to get data out of a replay buffer:
119
+
120
+
>>> first_elt = rb_td[0]
121
+
>>> storage = rb_td[:] # returns all valid elements from the buffer
122
+
>>> sample = rb_td.sample(128)
123
+
>>> for data in rb_td: # iterate over the buffer using the sampler -- batch-size was set in the constructor to 1
124
+
... print(data)
125
+
126
+
using the following components:
26
127
27
128
.. currentmodule:: torchrl.data.replay_buffers
28
129
@@ -48,9 +149,14 @@ We also give users the ability to compose a replay buffer using the following co
48
149
TensorDictRoundRobinWriter
49
150
TensorDictMaxValueWriter
50
151
51
-
Storage choice is very influential on replay buffer sampling latency, especially in distributed reinforcement learning settings with larger data volumes.
52
-
:class:`LazyMemmapStorage` is highly advised in distributed settings with shared storage due to the lower serialisation cost of MemmapTensors as well as the ability to specify file storage locations for improved node failure recovery.
53
-
The following mean sampling latency improvements over using ListStorage were found from rough benchmarking in https://github.com/pytorch/rl/tree/main/benchmarks/storage.
152
+
Storage choice is very influential on replay buffer sampling latency, especially
153
+
in distributed reinforcement learning settings with larger data volumes.
154
+
:class:`~torchrl.data.replay_buffers.storages.LazyMemmapStorage` is highly
155
+
advised in distributed settings with shared storage due to the lower serialisation
156
+
cost of MemoryMappedTensors as well as the ability to specify file storage locations
157
+
for improved node failure recovery.
158
+
The following mean sampling latency improvements over using :class:`~torchrl.data.replay_buffers.ListStorage`
159
+
were found from rough benchmarking in https://github.com/pytorch/rl/tree/main/benchmarks/storage.
0 commit comments