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

[Feature] Threaded collection and parallel envs #1559

Merged
merged 10 commits into from
Sep 22, 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
Prev Previous commit
Next Next commit
lint
  • Loading branch information
vmoens committed Sep 21, 2023
commit 9f58a8d44558a48980015f0a738dd00465b460e2
8 changes: 1 addition & 7 deletions test/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,13 +1215,7 @@ def test_ndbounded_shape(self):


class TestExpand:
@pytest.mark.parametrize(
"shape1",
[
None,
(4,),
(5, 4)
])
@pytest.mark.parametrize("shape1", [None, (4,), (5, 4)])
@pytest.mark.parametrize("shape2", [(), (10,)])
def test_binary(self, shape1, shape2):
spec = BinaryDiscreteTensorSpec(
Expand Down
1 change: 1 addition & 0 deletions torchrl/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ def get_trace():

class _ProcessNoWarn(mp.Process):
"""A private Process class that shuts down warnings on the subprocess and controls the number of threads in the subprocess."""

@wraps(mp.Process.__init__)
def __init__(self, *args, num_threads=None, **kwargs):
import torchrl
Expand Down
2 changes: 1 addition & 1 deletion torchrl/collectors/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ def __init__(
)
self.closed = True
if num_threads is None:
num_threads = len(create_env_fn) + 1 # 1 more thread for this proc
num_threads = len(create_env_fn) + 1 # 1 more thread for this proc
self.num_sub_threads = num_sub_threads
self.num_threads = num_threads
self.create_env_fn = create_env_fn
Expand Down
2 changes: 1 addition & 1 deletion torchrl/envs/batched_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(
super().__init__(device=None)
self.is_closed = True
if num_threads is None:
num_threads = num_workers + 1 # 1 more thread for this proc
num_threads = num_workers + 1 # 1 more thread for this proc
self.num_sub_threads = num_sub_threads
self.num_threads = num_threads
self._cache_in_keys = None
Expand Down
Loading