Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Fix doc upload #1738

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
init
  • Loading branch information
vmoens committed Dec 6, 2023
commit 8d315d8f3ac885935c1c2a0e3863bf2c64881224
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
upload:
needs: build-docs
if: github.repository == 'pytorch/rl' && github.event_name == 'push' &&
((github.ref_type == 'branch' && github.ref_name == 'main') || github.ref_type == 'tag')
((github.ref_type == 'branch' && github.ref_name == 'main') || github.ref_type == 'tag' || contains(github.event.pull_request.labels.*.name, 'ciflow/docs'))
permissions:
contents: write
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:

# mkdir -p "${TARGET_FOLDER}"
# rm -rf "${TARGET_FOLDER}"/*
mv "${RUNNER_ARTIFACT_DIR}"/html/* "${TARGET_FOLDER}"
cp -r "${RUNNER_ARTIFACT_DIR}"/html/* "${TARGET_FOLDER}"
git add "${TARGET_FOLDER}" || true

# if [[ "${TARGET_FOLDER}" == main ]]; then
Expand Down
41 changes: 6 additions & 35 deletions docs/source/reference/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,6 @@ The following mean sampling latency improvements over using ListStorage were fou
| :class:`LazyMemmapStorage` | 3.44x |
+-------------------------------+-----------+

Replay buffers with a shared storage and regular (RoundRobin) writers can also
be shared between processes on a single node. This allows each worker to read and
write onto the storage. The following code snippet examplifies this feature:

>>> from torchrl.data import TensorDictReplayBuffer, LazyMemmapStorage
>>> import torch
>>> from torch import multiprocessing as mp
>>> from tensordict import TensorDict
>>>
>>> def worker(rb):
... # Updates the replay buffer with new data
... td = TensorDict({"a": torch.ones(10)}, [10])
... rb.extend(td)
...
>>> if __name__ == "__main__":
... rb = TensorDictReplayBuffer(storage=LazyMemmapStorage(21))
... td = TensorDict({"a": torch.zeros(10)}, [10])
... rb.extend(td)
...
... proc = mp.Process(target=worker, args=(rb,))
... proc.start()
... proc.join()
... # the replay buffer now has a length of 20, since the worker updated it
... assert len(rb) == 20
... assert (rb["_data", "a"][:10] == 0).all() # data from main process
... assert (rb["_data", "a"][10:20] == 1).all() # data from remote process

Sharing replay buffers across processes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -105,30 +78,28 @@ are currently not sharable, and the same goes for stateful samplers such as
A shared replay buffer can be read and extended on any process that has access
to it, as the following example shows:

>>> import pickle
>>>
>>> from torchrl.data import TensorDictReplayBuffer, LazyMemmapStorage
>>> import torch
>>> from torch import multiprocessing as mp
>>> from tensordict import TensorDict
>>>
>>> def worker(rb):
... # Updates the replay buffer with new data
... td = TensorDict({"a": torch.ones(10)}, [10])
... # Extends the shared replay buffer on a subprocess
... rb.extend(td)
>>>
...
>>> if __name__ == "__main__":
... rb = TensorDictReplayBuffer(storage=LazyMemmapStorage(21))
... td = TensorDict({"a": torch.zeros(10)}, [10])
.. # extends the replay buffer on the main process
... rb.extend(td)
...
... proc = mp.Process(target=worker, args=(rb,))
... proc.start()
... proc.join()
... # Checks that the length of the buffer equates the length of both
... # extensions (local and remote)
... # the replay buffer now has a length of 20, since the worker updated it
... assert len(rb) == 20
... assert (rb["_data", "a"][:10] == 0).all() # data from main process
... assert (rb["_data", "a"][10:20] == 1).all() # data from remote process


Storing trajectories
Expand Down Expand Up @@ -175,7 +146,7 @@ can be used:
is_shared=False)

Checkpointing Replay Buffers
----------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Each component of the replay buffer can potentially be stateful and, as such,
require a dedicated way of being serialized.
Expand Down
Loading