{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/9183","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/9183/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/9183/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/9183/events","html_url":"https://github.com/pytorch/pytorch/pull/9183","id":338565418,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk5NDYzMDk5","number":9183,"title":"Updated WeightedRandomSampler to fit usage of other samplers","user":{"login":"rsnk96","id":10851575,"node_id":"MDQ6VXNlcjEwODUxNTc1","avatar_url":"https://avatars1.githubusercontent.com/u/10851575?v=4","gravatar_id":"","url":"https://api.github.com/users/rsnk96","html_url":"https://github.com/rsnk96","followers_url":"https://api.github.com/users/rsnk96/followers","following_url":"https://api.github.com/users/rsnk96/following{/other_user}","gists_url":"https://api.github.com/users/rsnk96/gists{/gist_id}","starred_url":"https://api.github.com/users/rsnk96/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsnk96/subscriptions","organizations_url":"https://api.github.com/users/rsnk96/orgs","repos_url":"https://api.github.com/users/rsnk96/repos","events_url":"https://api.github.com/users/rsnk96/events{/privacy}","received_events_url":"https://api.github.com/users/rsnk96/received_events","type":"User","site_admin":false},"labels":[{"id":559719279,"node_id":"MDU6TGFiZWw1NTk3MTkyNzk=","url":"https://api.github.com/repos/pytorch/pytorch/labels/ready%20for%20review","name":"ready for review","color":"b60205","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-07-05T13:02:48Z","updated_at":"2018-09-12T18:59:01Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/9183","html_url":"https://github.com/pytorch/pytorch/pull/9183","diff_url":"https://github.com/pytorch/pytorch/pull/9183.diff","patch_url":"https://github.com/pytorch/pytorch/pull/9183.patch"},"body":"Commit to address #9171 \r\n\r\nIt does not break functioning of `BatchSampler()` or any of the other samplers, tested with the following code. It should also make it easy to dynamically change sampling weights in every call of the iterator of `WeightedRandomSampler`\r\n\r\n```python\r\nimport torch\r\nfrom torchvision import datasets, transforms\r\nfrom torch._six import int_classes as _int_classes\r\n\r\n\r\nmnist_dataset = datasets.MNIST(\r\n    \"../data\",\r\n    train=False,\r\n    download=True,\r\n    transform=transforms.Compose([transforms.ToTensor()]),\r\n)\r\ntest_loader_no_sampler = torch.utils.data.DataLoader(\r\n    mnist_dataset, batch_size=1, shuffle=True\r\n)\r\ntest_loader_random = torch.utils.data.DataLoader(\r\n    mnist_dataset, sampler=torch.utils.data.sampler.RandomSampler(mnist_dataset)\r\n)\r\ntest_loader_subsetrandom = torch.utils.data.DataLoader(\r\n    mnist_dataset, sampler=torch.utils.data.sampler.SubsetRandomSampler(range(10000))\r\n)\r\ntest_loader_subsetrandom_2 = torch.utils.data.DataLoader(\r\n    mnist_dataset,\r\n    batch_size=100,\r\n    num_workers=4,\r\n    sampler=torch.utils.data.sampler.SubsetRandomSampler(range(10000)),\r\n)\r\ntest_loader_weightedrandom = torch.utils.data.DataLoader(\r\n    mnist_dataset,\r\n    sampler=torch.utils.data.sampler.WeightedRandomSampler(weights=[1] * 10000),\r\n)\r\ntest_loader_weightedrandom_2 = torch.utils.data.DataLoader(\r\n    mnist_dataset,\r\n    batch_size=100,\r\n    num_workers=4,\r\n    sampler=torch.utils.data.sampler.WeightedRandomSampler(\r\n        weights=[1] * 10000, num_samples=2\r\n    ),\r\n)\r\n\r\nfor iter_no, (data, label) in enumerate(test_loader_no_sampler):\r\n    continue\r\nprint(\"No sampler: \", iter_no)\r\n\r\nfor iter_no, (data, label) in enumerate(test_loader_random):\r\n    continue\r\nprint(\"Random sampler: \", iter_no)\r\n\r\nfor iter_no, (data, label) in enumerate(test_loader_subsetrandom):\r\n    continue\r\nprint(\"Subset Random sampler: \", iter_no)\r\n\r\nfor iter_no, (data, label) in enumerate(test_loader_subsetrandom_2):\r\n    continue\r\nprint(\"Subset Random sampler with batch size 100: \", iter_no)\r\n\r\nfor iter_no, (data, label) in enumerate(test_loader_weightedrandom):\r\n    continue\r\nprint(\"Weighted Random sampler: \", iter_no)\r\n\r\nfor iter_no, (data, label) in enumerate(test_loader_weightedrandom_2):\r\n    continue\r\nprint(\"Weighted Random sampler 100 batch size and 2 samples every draw: \", iter_no)\r\n\r\n```\r\n\r\nOutput:\r\n```\r\nNo sampler:  9999\r\nRandom sampler:  9999\r\nSubset Random sampler:  9999\r\nSubset Random sampler with batch size 100:  99\r\nWeighted Random sampler:  9999\r\nWeighted Random sampler 100 batch size and 2 samples every draw:  199\r\n```"},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/420760574","html_url":"https://github.com/pytorch/pytorch/pull/9183#issuecomment-420760574","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/9183","id":420760574,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDc2MDU3NA==","user":{"login":"SsnL","id":5674597,"node_id":"MDQ6VXNlcjU2NzQ1OTc=","avatar_url":"https://avatars2.githubusercontent.com/u/5674597?v=4","gravatar_id":"","url":"https://api.github.com/users/SsnL","html_url":"https://github.com/SsnL","followers_url":"https://api.github.com/users/SsnL/followers","following_url":"https://api.github.com/users/SsnL/following{/other_user}","gists_url":"https://api.github.com/users/SsnL/gists{/gist_id}","starred_url":"https://api.github.com/users/SsnL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SsnL/subscriptions","organizations_url":"https://api.github.com/users/SsnL/orgs","repos_url":"https://api.github.com/users/SsnL/repos","events_url":"https://api.github.com/users/SsnL/events{/privacy}","received_events_url":"https://api.github.com/users/SsnL/received_events","type":"User","site_admin":false},"created_at":"2018-09-12T18:59:01Z","updated_at":"2018-09-12T18:59:01Z","author_association":"CONTRIBUTOR","body":"@apaszke "}}
{"actor":{"display_login":"SsnL"}}