I was expecting that the draws from the multinomial distribution would be reproducible too. Why am I getting this behavior and how do I fix this?
I am trying to draw from a multinomial distribution and want the draws to be reproducible.
Passing generator to torch.multinomial
will just tell pytorch which generator to use, it will not reset its states.
Try this
import torch
g = torch.Generator().manual_seed(1)
p = torch.rand(3, generator=g)
initial_state = g.get_state()
print(torch.multinomial(p, num_samples=10, replacement=True, generator=g))
g.set_state(initial_state)
print(torch.multinomial(p, num_samples=10, replacement=True, generator=g))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With