You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
simulate_for_sbi with num_workers > 1 repeats simulator noise because per-batch seeds collide #2109
With num_workers > 1, simulate_for_sbi gives every batch its own seed and calls seed_all_backends(seed) in the worker. The seeds are drawn with replacement from only
10^6 values:
sbi/simulators/simutils.py:56 (simulate_in_batches, used by ABC): torch.randint(high=1_000_000, size=(len(batches),))
Two batches that draw the same seed get exactly the same simulator noise. With the default simulation_batch_size=1, there is one batch per simulation, so by the birthday problem
about N² / (2 · 10^6) simulations repeat the noise of another one:
simulations
expected repeats
measured
5,000
~12
11
20,000
~200
199
100,000
~5,000 (5%)
From 10^6 simulations on, there are at most 10^6 distinct noise streams. There is no
warning, and the training data silently contain correlated simulations.
Expected: every batch gets independent randomness, and the run stays reproducible for a
given seed.
Related: the open PR #1738 refactors this code but keeps the same np.random.randint(0, 1_000_000) batch seeds, so it does not fix this. Reviewers there
also asked to derive the batch seeds from the user's seed for reproducibility. Spawning
independent child seeds from seed would solve both.
@aniketpandey05 thanks for the clear report and the measurements!
The simulate_for_sbi part is fixed in PR #1738: since its update today, every simulator call gets its own seed, derived from seed and drawn without replacement. Your example now reports 0 repeated noise draws.
The ABC path in simulate_in_batches still has the problem and is not part of PR #1738. Once that PR is merged, a small PR is welcome that runs simulate_in_batches through simulate_from_theta, so that its own batching and seeding code goes away.
Activity
janfb commentedon Oct 28, 2026
@aniketpandey05 thanks for the clear report and the measurements!
The
simulate_for_sbipart is fixed in PR #1738: since its update today, every simulator call gets its own seed, derived fromseedand drawn without replacement. Your example now reports 0 repeated noise draws.The ABC path in
simulate_in_batchesstill has the problem and is not part of PR #1738. Once that PR is merged, a small PR is welcome that runssimulate_in_batchesthroughsimulate_from_theta, so that its own batching and seeding code goes away.aniketpandey05 commentedon Oct 29, 2026
@Ayankkk29 hi I was working on this one
janfb commentedon Oct 29, 2026
@Ayankkk29 thanks for the offer. My note above was for @aniketpandey05, who reported this, so the ABC part stays with them once PR #1738 is merged.
cheers, Jan