Skip to content

Commit

Permalink
timeout in get
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens committed Nov 22, 2023
1 parent 8ca93b6 commit 7c63518
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tensordict/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2954,9 +2954,10 @@ def map(
pool (mp.Pool, optional): a multiprocess Pool instance to use
to execute the job. If none is provided, a pool will be created
within the ``map`` method.
seed (integer, optional): the initial seed of the pool. Each member
generator (torch.Generator, optional): a generator to use for seeding.
A base seed will be generated from it, and each worker
of the pool will be seeded with the provided seed incremented
by a unique integer from ``0`` to ``num_workers``. If no seed
by a unique integer from ``0`` to ``num_workers``. If no generator
is provided, a random integer will be used as seed.
To work with unseeded workers, a pool should be created separately
and passed to :meth:`map` directly.
Expand Down
4 changes: 3 additions & 1 deletion tensordict/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,9 @@ def _legacy_lazy(func):

# Process initializer for map
def _proc_init(base_seed, queue):
worker_id = queue.get()
print('init worker', os.getpid())
worker_id = queue.get(timeout=10)
print('worker id', worker_id)
seed = base_seed + worker_id
torch.manual_seed(seed)
np_seed = _generate_state(base_seed, worker_id)
Expand Down

0 comments on commit 7c63518

Please sign in to comment.