Code strangely sometimes works and sometimes doesn't

Hi guys. My code is simply a “variation” of this code here: with the difference that I’m using MNIST dataset instead of CIFAR-10 and a different model (AlexNet). I don’t know why but sometimes accuracy is very high (starting from almost 91%) while sometimes it’s simply just very low (11%). If you’re asking i’ve changed the train_transform and test_transform according to the MNIST dataset and set everything accordingly to this. Please help me i’m freaking out

Depending on your use case, model, etc. the training might be sensitive to e.g. the initialization of the model as well as other hyperparameters.
You could try to use other init methods from torch.nn.init or play around with other hyperparameters such as the learning rate (maybe it’s too high and lets the model diverge in a lot of cases).