Skip to content

Commit 0324c25

Browse files
committed
edit
1 parent 8f3f391 commit 0324c25

22 files changed

Lines changed: 353 additions & 129 deletions

docs/build_local.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/bin/bash
2+
# Build TorchRL documentation locally using uv with a temporary virtual environment.
3+
#
4+
# Usage:
5+
# ./build_local.sh # Build docs (runs tutorials)
6+
# ./build_local.sh --no-run # Build docs without running tutorials (faster)
7+
#
8+
# The script creates a temporary virtual environment, installs dependencies,
9+
# builds the documentation, and cleans up on failure.
10+
11+
set -e
12+
13+
# Configuration
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15+
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
16+
VENV_DIR="${ROOT_DIR}/.doc-venv"
17+
BUILD_DIR="${SCRIPT_DIR}/_local_build"
18+
PYTHON_VERSION="3.12"
19+
20+
# Parse arguments
21+
RUN_TUTORIALS=true
22+
for arg in "$@"; do
23+
case $arg in
24+
--no-run)
25+
RUN_TUTORIALS=false
26+
shift
27+
;;
28+
--help|-h)
29+
echo "Usage: $0 [--no-run]"
30+
echo ""
31+
echo "Options:"
32+
echo " --no-run Skip running tutorials (faster build)"
33+
echo " --help, -h Show this help message"
34+
exit 0
35+
;;
36+
esac
37+
done
38+
39+
# Cleanup function - always runs on exit
40+
cleanup() {
41+
local exit_code=$?
42+
43+
# Restore conf.py if we modified it (do this regardless of success/failure)
44+
if [ -f "$SCRIPT_DIR/source/conf.py.bak" ]; then
45+
mv "$SCRIPT_DIR/source/conf.py.bak" "$SCRIPT_DIR/source/conf.py"
46+
echo "Restored conf.py from backup"
47+
fi
48+
49+
if [ $exit_code -ne 0 ]; then
50+
echo ""
51+
echo "============================================"
52+
echo "Build failed with exit code $exit_code"
53+
echo "Cleaning up virtual environment..."
54+
echo "============================================"
55+
rm -rf "$VENV_DIR"
56+
echo "Virtual environment removed: $VENV_DIR"
57+
fi
58+
exit $exit_code
59+
}
60+
trap cleanup EXIT INT TERM
61+
62+
echo "============================================"
63+
echo "TorchRL Documentation Build Script"
64+
echo "============================================"
65+
echo ""
66+
echo "Root directory: $ROOT_DIR"
67+
echo "Virtual env: $VENV_DIR"
68+
echo "Build output: $BUILD_DIR"
69+
echo "Run tutorials: $RUN_TUTORIALS"
70+
echo ""
71+
72+
# Check for uv
73+
if ! command -v uv &> /dev/null; then
74+
echo "Error: 'uv' is not installed."
75+
echo "Install it with: curl -LsSf https://astral.sh/uv/install.sh | sh"
76+
exit 1
77+
fi
78+
79+
# Remove existing venv if it exists
80+
if [ -d "$VENV_DIR" ]; then
81+
echo "Removing existing virtual environment..."
82+
rm -rf "$VENV_DIR"
83+
fi
84+
85+
# Create virtual environment
86+
echo "Creating virtual environment with Python $PYTHON_VERSION..."
87+
uv venv "$VENV_DIR" --python "$PYTHON_VERSION"
88+
89+
# Activate virtual environment
90+
echo "Activating virtual environment..."
91+
source "$VENV_DIR/bin/activate"
92+
93+
# Upgrade pip and install build tools
94+
echo "Installing build tools..."
95+
uv pip install --upgrade pip setuptools ninja packaging "pybind11[global]" cmake
96+
97+
# Install PyTorch (nightly for latest features)
98+
echo "Installing PyTorch..."
99+
uv pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
100+
101+
# Install tensordict from git
102+
echo "Installing tensordict..."
103+
uv pip install git+https://github.com/pytorch/tensordict.git
104+
105+
# Install torchrl in editable mode
106+
echo "Installing torchrl..."
107+
cd "$ROOT_DIR"
108+
uv pip install -e . --no-build-isolation
109+
110+
# Install documentation requirements
111+
echo "Installing documentation requirements..."
112+
# First install pytorch_sphinx_theme separately (editable git not supported by uv -r)
113+
uv pip install git+https://github.com/pytorch/pytorch_sphinx_theme.git
114+
# Install remaining requirements (skip the editable line)
115+
grep -v "pytorch_sphinx_theme" "$SCRIPT_DIR/requirements.txt" | uv pip install -r -
116+
117+
# Verify installation
118+
echo "Verifying torchrl installation..."
119+
python -c "import torchrl; print(f'TorchRL version: {torchrl.__version__}')"
120+
121+
# Set up environment for building
122+
export MAX_IDLE_COUNT=180
123+
export BATCHED_PIPE_TIMEOUT=180
124+
export TORCHRL_CONSOLE_STREAM=stdout
125+
126+
# Clear old MuJoCo environment variables that might interfere with MuJoCo 3.x
127+
unset MUJOCO_PATH
128+
unset MUJOCO_PY_MUJOCO_PATH
129+
unset LD_LIBRARY_PATH # Reset to avoid old MuJoCo libs
130+
131+
# Set plot_gallery based on mode
132+
# Create backup of conf.py for cleanup to restore
133+
cp "$SCRIPT_DIR/source/conf.py" "$SCRIPT_DIR/source/conf.py.bak"
134+
135+
if [ "$RUN_TUTORIALS" = true ]; then
136+
echo ""
137+
echo "Note: Tutorials WILL be executed"
138+
# Enable plot_gallery (replace both True and "False" variants)
139+
sed -i '' 's/"plot_gallery": "False"/"plot_gallery": True/' "$SCRIPT_DIR/source/conf.py"
140+
sed -i '' 's/"plot_gallery": False/"plot_gallery": True/' "$SCRIPT_DIR/source/conf.py"
141+
else
142+
echo ""
143+
echo "Note: Tutorials will NOT be executed (--no-run mode)"
144+
# Disable plot_gallery
145+
sed -i '' 's/"plot_gallery": True/"plot_gallery": "False"/' "$SCRIPT_DIR/source/conf.py"
146+
fi
147+
148+
# Build documentation
149+
echo ""
150+
echo "============================================"
151+
echo "Building documentation..."
152+
echo "============================================"
153+
cd "$SCRIPT_DIR"
154+
sphinx-build ./source "$BUILD_DIR" -v -j auto
155+
156+
echo ""
157+
echo "============================================"
158+
echo "Documentation built successfully!"
159+
echo "============================================"
160+
echo ""
161+
echo "Output: $BUILD_DIR"
162+
echo ""
163+
echo "To view the documentation, run:"
164+
echo " python -m http.server 8000 -d $BUILD_DIR"
165+
echo " # Then open http://localhost:8000 in your browser"
166+
echo ""
167+
echo "To clean up the virtual environment, run:"
168+
echo " rm -rf $VENV_DIR"

docs/requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ docutils
1414
sphinx_design
1515

1616
torchvision
17-
dm_control
18-
mujoco<3.3.6
17+
dm_control>=1.0.0
18+
mujoco>=3.0.0,<3.3.6
1919
gymnasium[classic_control,atari]
2020
pygame
2121
tqdm
2222
ipython
2323
imageio[ffmpeg,pyav]
2424
memory_profiler
25-
pyrender
2625
pytest
2726
vmas
2827
onnxscript
@@ -32,3 +31,6 @@ psutil
3231
hydra-core>=1.1
3332
omegaconf
3433
hydra-submitit-launcher
34+
transformers
35+
accelerate
36+
sentencepiece

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
intersphinx_mapping = {
8080
"torch": ("https://pytorch.org/docs/stable/", None),
81-
"tensordict": ("https://pytorch.github.io/tensordict/", None),
81+
"tensordict": ("https://docs.pytorch.org/tensordict/stable/", None),
8282
# "torchrl": ("https://pytorch.org/rl/", None),
8383
"torchaudio": ("https://pytorch.org/audio/stable/", None),
8484
"torchtext": ("https://pytorch.org/text/stable/", None),
@@ -110,7 +110,7 @@ def kill_procs(gallery_conf, fname):
110110
"download_all_examples": True,
111111
"abort_on_example_error": True,
112112
# "show_memory": True,
113-
"plot_gallery": True,
113+
"plot_gallery": "False",
114114
"capture_repr": ("_repr_html_", "__repr__"), # capture representations
115115
"write_computation_times": True,
116116
# "compress_images": ("images", "thumbnails"),

docs/source/reference/config.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,10 @@ Data Collection Configurations
433433
:toctree: generated/
434434
:template: rl_template_class.rst
435435

436-
DataCollectorConfig
437-
SyncDataCollectorConfig
438-
AsyncDataCollectorConfig
439-
MultiSyncDataCollectorConfig
440-
MultiaSyncDataCollectorConfig
436+
CollectorConfig
437+
AsyncCollectorConfig
438+
MultiSyncCollectorConfig
439+
MultiAsyncCollectorConfig
441440

442441
Replay Buffer and Storage Configurations
443442
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/source/reference/cudnn_persistent_rnn.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:orphan:
2+
13
.. note::
24
In some circumstances when using the CUDNN backend with CuDNN 7.2.1, the backward
35
can be up to 5x slower when called with a batch_first input. This is expected to be fixed

docs/source/reference/cudnn_rnn_determinism.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:orphan:
2+
13
.. note::
24
If the following conditions are not met, the backward pass will use a slower but more
35
memory efficient implementation:

docs/source/reference/data_datasets.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
.. currentmodule:: torchrl.data
22

3+
.. _TED-format:
4+
35
Datasets
46
========
57

68
TorchRL provides dataset utilities for offline RL and data management.
79

10+
TorchRL Episode Data (TED) Format
11+
---------------------------------
12+
13+
The TED format is TorchRL's standard data layout for offline RL datasets. It structures
14+
trajectories as nested tensors where each element contains the full trajectory data,
15+
making it efficient for sequence-based sampling and training.
16+
817
.. autosummary::
918
:toctree: generated/
1019
:template: rl_template.rst

docs/source/reference/llms_collectors.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:orphan:
2+
13
.. currentmodule:: torchrl.collectors.llm
24

35
LLM Collectors

docs/source/reference/llms_data.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:orphan:
2+
13
.. currentmodule:: torchrl.data.llm
24

35
Data Structures

docs/source/reference/llms_envs.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:orphan:
2+
13
.. currentmodule:: torchrl.envs.llm
24

35
LLM Environments

0 commit comments

Comments
 (0)