Skip to content

Commit 43d3641

Browse files
InnovArulfacebook-github-bot
authored andcommitted
torch.utils.data.Dataloader: documentation about RNG state consumption (#22540)
Summary: the outcome from the pytorch forum issue: https://discuss.pytorch.org/t/dataloader-problem-problem-arises-when-shuffle-true/45631 The discussion is here: #20749 Pull Request resolved: #22540 Differential Revision: D16131777 Pulled By: ezyang fbshipit-source-id: 566deda1b44dc7fae54250e9b508d120851a2848
1 parent ce8c9d9 commit 43d3641

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

docs/source/data.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,11 @@ are compatible with Windows while using multi-process data loading:
332332
Randomness in multi-process data loading
333333
""""""""""""""""""""""""""""""""""""""""""
334334

335-
By default, each worker will have its PyTorch seed set to
336-
``base_seed + worker_id``, where ``base_seed`` is a long generated
337-
by main process using its RNG. However, seeds for other libraries
338-
may be duplicated upon initializing workers (w.g., NumPy), causing
339-
each worker to return identical random numbers. (See
340-
:ref:`this section <dataloader-workers-random-seed>` in FAQ.)
335+
By default, each worker will have its PyTorch seed set to ``base_seed + worker_id``,
336+
where ``base_seed`` is a long generated by main process using its RNG (thereby,
337+
consuming a RNG state mandatorily). However, seeds for other libraries may be
338+
duplicated upon initializing workers (w.g., NumPy), causing each worker to return
339+
identical random numbers. (See :ref:`this section <dataloader-workers-random-seed>` in FAQ.).
341340

342341
In :attr:`worker_init_fn`, you may access the PyTorch seed set for each worker
343342
with either :func:`torch.utils.data.get_worker_info().seed <torch.utils.data.get_worker_info>`

torch/utils/data/dataloader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# aspect.
2424
default_collate = _utils.collate.default_collate
2525

26+
2627
class _DatasetKind(object):
2728
Map = 0
2829
Iterable = 1
@@ -39,6 +40,7 @@ class _InfiniteConstantSampler(Sampler):
3940
r"""Analogous to ``itertools.repeat(None, None)``.
4041
Used as sampler for :class:`~torch.utils.data.IterableDataset`.
4142
"""
43+
4244
def __init__(self):
4345
super(_InfiniteConstantSampler, self).__init__(None)
4446

0 commit comments

Comments
 (0)