lundi 1 mai 2023

python set random seed, but results not reusing

I'm training a simple neural network model in python, I need to run batch experiments to test the performance of different module configurations by executing python train.py.

  • train configs:
  1. dataset_A, dataset_B, dataset_C, total 3 datasets
  2. total 19 model configurations.
  • Python training mode:
  1. if I using 2 for loops to generate some results, some of them are wrong. If I rerun the wrong results seperately, the correct results will be produced, even if run multiple times.

  2. I split the 3 datasets, modify the train.py and run it one dataset at a time, I get different results than in training mode 1).

I set the random seed in the ./utils/util.py:

def set_seed(seed):
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)

In train.py, it call the function set_seed(42). In short, if I set exact same configuration, mutilple runs will produce the same results. However, if I just change the order of the datasets list, I will have different results. I would be grateful if someone could give me some advice.




Aucun commentaire:

Enregistrer un commentaire