facebookresearch/xformers

How to set random seeds fixed

Open

#618 aberto em 3 de jan. de 2023

Ver no GitHub
 (17 comments) (1 reaction) (0 assignees)Python (473 forks)batch import
good first issue

Métricas do repositório

Stars
 (6.903 stars)
Métricas de merge de PR
 (Mesclagem média 3d 6h) (1 fundiu PR em 30d)

Description

❓ 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

Guia do colaborador