@@ -359,7 +359,9 @@ class RandomDataset(BenchmarkDataset):
359359 def __init__ (self , ** kwargs ) -> None :
360360 super ().__init__ (** kwargs )
361361 # Use numpy's default_rng for deterministic sampling
362- self ._np_rng = np .random .default_rng (self .random_seed )
362+ # Do not use random.seed() or np.random.seed() elsewhere in this class.
363+ # This ensures that the RNG is isolated from global RNG state.
364+ self ._rng = np .random .default_rng (self .random_seed )
363365
364366 def sample (
365367 self ,
@@ -408,7 +410,7 @@ def get_prefix(
408410 Get the prefix for the dataset.
409411 """
410412 return (
411- self ._np_rng .integers (
413+ self ._rng .integers (
412414 0 , tokenizer .vocab_size , size = prefix_len ).tolist ()
413415 if prefix_len > 0
414416 else []
@@ -459,11 +461,11 @@ def get_sampling_params(
459461 output_high ,
460462 )
461463
462- input_lens = self ._np_rng .integers (input_low , input_high + 1 ,
464+ input_lens = self ._rng .integers (input_low , input_high + 1 ,
463465 size = num_requests )
464- output_lens = self ._np_rng .integers (output_low , output_high + 1 ,
466+ output_lens = self ._rng .integers (output_low , output_high + 1 ,
465467 size = num_requests )
466- offsets = self ._np_rng .integers (0 , tokenizer .vocab_size ,
468+ offsets = self ._rng .integers (0 , tokenizer .vocab_size ,
467469 size = num_requests )
468470 return input_lens , output_lens , offsets
469471
@@ -544,7 +546,7 @@ def __init__(self, **kwargs) -> None:
544546
545547 def generate_synthetic_image (self , width : int , height : int ) -> Image .Image :
546548 """Generate synthetic PIL image with random RGB values."""
547- random_pixels = self ._np_rng .integers (
549+ random_pixels = self ._rng .integers (
548550 0 ,
549551 256 ,
550552 (height , width , 3 ),
@@ -620,12 +622,12 @@ def get_image_dimensions_iterator(
620622 whose size is between min_num_images and max_num_images.
621623 """
622624 request_num_images = int (
623- self ._np_rng .integers (min_num_images , max_num_images + 1 )
625+ self ._rng .integers (min_num_images , max_num_images + 1 )
624626 )
625627 for _ in range (request_num_images ):
626628 yield (
627- int (self ._np_rng .integers (min_width , max_width + 1 )),
628- int (self ._np_rng .integers (min_height , max_height + 1 )),
629+ int (self ._rng .integers (min_width , max_width + 1 )),
630+ int (self ._rng .integers (min_height , max_height + 1 )),
629631 )
630632
631633 def sample (
0 commit comments