Fix Tuner._mutate RNG collisions for sub-second iterations (#24451)

Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
Co-authored-by: Onuralp SEZER <onuralp@ultralytics.com>
This commit is contained in:
Murat Raimbekov 2026-05-12 20:54:30 +06:00 committed by GitHub
parent a462bb65c8
commit 166604e39d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -406,7 +406,7 @@ class Tuner:
# Mutate if we have data, otherwise use defaults
if x is not None:
np.random.seed(int(time.time()))
rng = np.random.default_rng()
ng = len(self.space)
# Crossover
@ -416,8 +416,8 @@ class Tuner:
gains = np.array([v[2] if len(v) == 3 else 1.0 for v in self.space.values()]) # gains 0-1
factors = np.ones(ng)
while np.all(factors == 1): # mutate until a change occurs (prevent duplicates)
mask = np.random.random(ng) < mutation
step = np.random.randn(ng) * (sigma * gains)
mask = rng.random(ng) < mutation
step = rng.standard_normal(ng) * (sigma * gains)
factors = np.where(mask, np.exp(step), 1.0).clip(0.25, 4.0)
hyp = {k: float(genes[i] * factors[i]) for i, k in enumerate(self.space.keys())}
else: