Skip to content

Sampler should be seeded lazily #63609

@ejguan

Description

@ejguan

🐛 Bug

After #63026 is landed, the generator for Sampler is attached to the instance, which helps to serialize the state of Sampler. But, it brings a problem that it will prevent Sampler's generator being seeded before each epoch.

To Reproduce

Check #63026 (comment)

User would expect same result for the sampler without specifying generator input when set seed for each epoch.

sampler = RandomSampler(ds)
torch.manual_seed(0)
l1 = list(sampler)
torch.manual_seed(0)
l2 = list(sampler)
# Expect same
assert l1 == l2

cc @ssnl @VitalyFedyunin @ejguan @NivekT

Metadata

Metadata

Assignees

Labels

module: dataloaderRelated to torch.utils.data.DataLoader and Samplermodule: regressionIt used to work, and now it doesn'ttriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions