Hi Sam!



 Sam_Lerman:

Is there a way I could extract the seed prior to the extra random operation so that I can set it back to that seed?


You don’t really want to do this, but if you decide that you do want to
do this, there are a couple of approaches.  See the documentation for
torch.random 5 for details.
As I understand it, you make calls to multinomial() during your training
process.  If your calls to multinomial() are deterministic – called the
same number of times at the same point in your training process – then
your training process should be reproducible, notwithstanding the fact
that multinomial() consumes some random numbers.  (If your calls
to multinomial() are not deterministic, why not?)
The problem with having multinomial() consume some random
numbers from the global generator and then resetting its state is that
your multinomial() values will now be correlated with the next set
of random values used by the next part of your training process.  In
practice, this is very unlikely to have any problematic effect, but reusing
(pseudo) random numbers like this makes them no longer properly
(pseudo) random.
If you require that your training process be reproducible but you can’t,
for whatever reason, make your multinomial() calls deterministic,
then the standard approach would be to instantiate a separate
Generator object (seeded with an uncorrelated seed) for your
multinomial() calls (or you could pre-calculate your necessary
multinomial() values before seeding the global generator).


I noticed you set the seed to 1010 in your example. Was that line necessary? It seems like just resetting the seed to 2020 would be sufficient.


Calling manual_seed() prior to calling multinomial() is not required
to make the call to randn() reproducible.  It is there to make the call
to multinomial() reproducible – certainly not necessary, but I put it
in for consistency.
Best.
K. Frank