Skip to content

[BE] Make coding_ddpg.py runnable outside of Colab env #2750

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

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Changes from all commits
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
21 changes: 15 additions & 6 deletions advanced_source/coding_ddpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,25 @@
# %%bash
# pip3 install torchrl mujoco glfw

import torchrl
import torch
import tqdm
from typing import Tuple

# sphinx_gallery_start_ignore
import warnings
warnings.filterwarnings("ignore")
import multiprocessing
# TorchRL prefers spawn method, that restricts creation of ``~torchrl.envs.ParallelEnv`` inside
# `__main__` method call, but for the easy of reading the code switch to fork
# which is also a default spawn method in Google's Colaboratory
try:
multiprocessing.set_start_method("fork")
except RuntimeError:
assert multiprocessing.get_start_method() == "fork"
# sphinx_gallery_end_ignore


import torchrl
import torch
import tqdm
from typing import Tuple

###############################################################################
# We will execute the policy on CUDA if available
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
Expand Down Expand Up @@ -1219,6 +1228,6 @@ def ceil_div(x, y):
#
# To iterate further on this loss module we might consider:
#
# - Using `@dispatch` (see `[Feature] Distpatch IQL loss module <https://github.com/pytorch/rl/pull/1230>`_.
# - Using `@dispatch` (see `[Feature] Distpatch IQL loss module <https://github.com/pytorch/rl/pull/1230>`_.)
# - Allowing flexible TensorDict keys.
#