facebookresearch/xformers

How to set random seeds fixed

Open

#618 aperta il 3 gen 2023

Vedi su GitHub
 (17 commenti) (1 reazione) (0 assegnatari)Python (473 fork)batch import
good first issue

Metriche repository

Star
 (6903 star)
Metriche merge PR
 (Merge medio 3g 6h) (1 PR mergiata in 30 g)

Descrizione

❓ Questions and Help

Different results occur when I run the same code twice. And the set_seed func run before all.

def set_seed(seed):
    random.seed(seed)  # Python random module.
    np.random.seed(seed)  # Numpy module.
    set_seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
    torch.random.manual_seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)  # if you are using multi-GPU.
    torch.backends.cudnn.benchmark = cudnn_benchmark
    torch.backends.cudnn.deterministic = cudnn_deterministic

Guida contributor