mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 13:44:15 +08:00
Revert "Use random64 in Fischer-Yates algorithm for large N (#143682)"
This reverts commit 7013be0094e8d3ded2ba2f948082f98d63e622bb. Reverted https://github.com/pytorch/pytorch/pull/143682 on behalf of https://github.com/wdvr due to failing Meta internal tests that need to be updated ([comment](https://github.com/pytorch/pytorch/pull/143682#issuecomment-2563487675))
This commit is contained in:
@ -3594,29 +3594,6 @@ class TestRandomTensorCreation(TestCase):
|
||||
self.assertEqual(non_contiguous_tensor, res)
|
||||
self.assertEqual(res.sort().values.long(), torch.arange(n, device=device))
|
||||
|
||||
|
||||
@largeTensorTest("10GB", "cpu")
|
||||
@largeTensorTest("40GB", "cuda")
|
||||
@slowTest
|
||||
def test_randperm_large(self, device):
|
||||
# Test even distribution where rand32 might produce skewed "uniform" distribution
|
||||
# n_items is chosen to not evenly divide 2**32 and be sufficiently large
|
||||
# to easily detect skew
|
||||
def decile(index, collection_size):
|
||||
return index // (collection_size // 10)
|
||||
|
||||
n_items = 700_000_000
|
||||
shuffled = torch.randperm(n_items, device=device)
|
||||
interval = 1_000_000
|
||||
shuffled_interval = shuffled[:interval]
|
||||
# histogram implemented for float only
|
||||
deciles = decile(shuffled_interval, shuffled.shape[0]).float().cpu()
|
||||
hist, _ = deciles.histogram(10, range=(0, 10))
|
||||
expected_bin = shuffled_interval.shape[0] / 10
|
||||
expected_error = math.sqrt(expected_bin) / expected_bin * 3
|
||||
error = (hist - expected_bin).abs().max() / expected_bin
|
||||
self.assertTrue(error < expected_error, f"error {error} > {expected_error}")
|
||||
|
||||
# Test exceptions when device and generator types are incompatible
|
||||
@onlyCUDA
|
||||
@unittest.skipIf(IS_FBCODE or IS_SANDCASTLE, "Produces inconsistent errors when run in fbcode.")
|
||||
|
Reference in New Issue
Block a user