Skip to content

ENH: Add functionality to set seed #772

@NickleDave

Description

@NickleDave

We should add functionality to set the seed for torch

This came up because @VinCheetah is having a bit of trouble replicating results from the 2022 eLife TweetyNet paper

A separate question is whether we want to "set the seed for everything", I see some libraries do something like this (from https://gist.github.com/gatheluck/c57e2a40e3122028ceaecc3cb0d152ac)

import os
import random
import numpy as np
import torch

def set_all_seeds(seed):
  random.seed(seed)
  os.environ('PYTHONHASHSEED') = str(seed)
  np.random.seed(seed)
  torch.manual_seed(seed)
  torch.cuda.manual_seed(seed)
  torch.backends.cudnn.deterministic = True

Earlier versions of lightning similarly had a function seed_everything (that AFAICT has since migrated to fabric): https://pytorch-lightning.readthedocs.io/en/1.7.7/api/pytorch_lightning.utilities.seed.html#pytorch_lightning.utilities.seed.seed_everything

but just doing a bare minimum of setting the torch seed will let us control e.g. random initialization of model parameters

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions