def setRNGSeed(seed): #numpy np.random.seed(seed) #torch torch.manual_seed(seed) torch.cuda.manual_seed(seed) # sets on...curent cuda device torch.cuda.manual_seed_all(seed) # sets on all devices in use #Pyro...maybe, seems to just set them for torch again...which would make sense set_rng_seed(seed) print("you are setting cudnn to deterministic, may make things slower") logging.info("cudnn is set to deterministic which may slow speed fyi") torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False
def get_trace(fn, *args, **kwargs): set_rng_seed(123) return poutine.trace(fn).get_trace(*args, **kwargs)
def __enter__(self): self.old_state = get_rng_state() set_rng_seed(self.rng_seed)