From 2135938ce618ff55666494fc50165d0ecc880f1c Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Thu, 15 Jan 2026 11:53:25 -0700 Subject: [PATCH 1/2] Fix(util): ensure seed is < 2**23 for np.random.seed() --- thinc/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thinc/util.py b/thinc/util.py index f32f10344..cec5e5f24 100644 --- a/thinc/util.py +++ b/thinc/util.py @@ -93,7 +93,7 @@ def gpu_is_available(): def fix_random_seed(seed: int = 0) -> None: # pragma: no cover """Set the random seed across random, numpy.random and cupy.random.""" random.seed(seed) - numpy.random.seed(seed) + numpy.random.seed(seed % 2**32) if has_torch: torch.manual_seed(seed) if has_cupy_gpu: From 30c936057ca17ab102216cab039e17b3058112f6 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Thu, 15 Jan 2026 12:28:03 -0700 Subject: [PATCH 2/2] fix: limit range of seed passed to torch.manual_seed() --- thinc/util.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/thinc/util.py b/thinc/util.py index cec5e5f24..cc1f8794b 100644 --- a/thinc/util.py +++ b/thinc/util.py @@ -95,10 +95,16 @@ def fix_random_seed(seed: int = 0) -> None: # pragma: no cover random.seed(seed) numpy.random.seed(seed % 2**32) if has_torch: - torch.manual_seed(seed) + # Must be within the inclusive range [-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff] + # https://github.com/pytorch/pytorch/blob/d38164a545b4a4e4e0cf73ce67173f70574890b6/torch/random.py#L32-L41 + torch.manual_seed(seed % 0xffff_ffff_ffff_ffff) if has_cupy_gpu: + # cupy has no documented range limit on seed as of 2026-01-15 + # https://docs.cupy.dev/en/latest/reference/generated/cupy.random.seed.html cupy.random.seed(seed) if has_torch and has_torch_cuda_gpu: + # torch.cuda has no documented range limit on seed as of 2026-01-15 + # https://docs.pytorch.org/docs/stable/generated/torch.cuda.manual_seed_all.html torch.cuda.manual_seed_all(seed) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False