Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PyTorch seed affect dropout layers?

I came across the idea of seeding my neural network for reproducible results, and was wondering if pytorch seeding affects dropout layers and what is the proper way to seed my training/testing?

I'm reading the documentation here, and wondering if just placing these lines will be enough?

torch.manual_seed(1)
torch.cuda.manual_seed(1)
like image 700
Matheus Ianzer Avatar asked Apr 01 '26 14:04

Matheus Ianzer


1 Answers

You can easily answer your question with some lines of code:

import torch
from torch import nn

dropout = nn.Dropout(0.5)
torch.manual_seed(9999)
a = dropout(torch.ones(1000))
torch.manual_seed(9999)
b = dropout(torch.ones(1000))
print(sum(abs(a - b)))
# > tensor(0.)

Yes, using manual_seed is enough.

like image 144
Fábio Perez Avatar answered Apr 08 '26 05:04

Fábio Perez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!