Skip to content

Simulating turns on deterministic cuDNN for the rest of the session, even without a seed #2159

Open

Description

@janfb

simulate_for_sbi calls seed_all_backends(seed) on every call, also with seed=None. Besides seeding the random states, seed_all_backends sets torch.backends.cudnn.deterministic = True and torch.backends.cudnn.benchmark = False. So after any simulate_for_sbi call, cuDNN uses deterministic algorithms for the rest of the session, which can slow down later GPU training with convolutional embedding nets. Nobody expects a simulation helper to change a global PyTorch setting.

import torch
from sbi.inference import simulate_for_sbi
from sbi.utils import BoxUniform

simulate_for_sbi(lambda t: t, BoxUniform(torch.zeros(2), torch.ones(2)), 5)
print(torch.backends.cudnn.deterministic)  # True

This was in main before PR #1738 already. The same happens in ABC's simulate_in_batches, and with a seed in simulate_from_theta, which reseeds before every simulator call.

I think seeding the random states and choosing deterministic algorithms should be separate: the simulation code seeds only the random states, and users who want deterministic GPU training set the cuDNN flags themselves, e.g. through an option of seed_all_backends. simulate_for_sbi with seed=None then reseeds from PyTorch's random state as before, so torch.manual_seed still reproduces it, but leaves cuDNN alone.

Activity

  1. BHARATH0153 commented on Nov 25, 2026

    @BHARATH0153
    Contributor

    fixed in #2177

  2. added 4 commits that reference this issue on Nov 26, 2026
    7a9ad5d
    c63e784
    73f4b88
    05743dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions