mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-19 12:58:07 +00:00
fix: Ensure deterministic iteration for ArithmeticDataset
This commit is contained in:
parent
a8b3a86831
commit
272ebc5a42
1 changed files with 7 additions and 4 deletions
|
|
@ -34,7 +34,8 @@ class ArithmeticDataset:
|
|||
def __init__(self, config: ArithmeticDatasetConfig):
|
||||
self.config = config
|
||||
self.config.validate()
|
||||
self.rng = Random(config.seed)
|
||||
# Generate base seed if none provided
|
||||
self.seed = config.seed if config.seed is not None else Random().randint(0, 2**32)
|
||||
|
||||
def __len__(self) -> int:
|
||||
return self.config.size
|
||||
|
|
@ -51,8 +52,8 @@ class ArithmeticDataset:
|
|||
- answer: str, the ground truth result
|
||||
- metadata: dict with generation parameters
|
||||
"""
|
||||
# Use seed derived from idx for deterministic generation
|
||||
item_rng = Random(self.rng.randint(0, 2**32) + idx)
|
||||
# Create deterministic RNG from base seed and idx
|
||||
item_rng = Random(self.seed + idx)
|
||||
|
||||
num_terms = item_rng.randint(self.config.min_terms, self.config.max_terms)
|
||||
num_digits = item_rng.randint(self.config.min_digits, self.config.max_digits)
|
||||
|
|
@ -165,4 +166,6 @@ class ArithmeticDataset:
|
|||
"Solve {0}",
|
||||
"Evaluate the expression: {0}"
|
||||
]
|
||||
return self.rng.choice(templates).format(expression)
|
||||
# Use deterministic RNG for template selection
|
||||
template_rng = Random(self.seed)
|
||||
return template_rng.choice(templates).format(expression)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue