Why doesn't setting `random.seed(42)` give me identical results in pytorch?
I am setting random seed for both random and numpy.random at the beginning of my main file:

import random
import numpy as np
np.random.seed(42)
random.seed(42)
import torch


Nevertheless, when I create a Net() object with randomly initialized parameters, it gives a completely different result every time:

net=neuralnet.Net()
print ("initialized params: ", net.fc1.weight)


Note that neuralnet.Net() is in a different file, and is a class that extends torch.nn.Module. it is torch.nn.Module that is randomly initializing net.fc1.weight, not my own code.

How is it possible that when I create a Net() object with randomly initialized parameters, it gives a completely different result every time?

try:

import torch
torch.manual_seed(0)


For further information:
https://pytorch.org/docs/stable/notes/randomness.html
