MCPcopy Create free account
hub / github.com/awslabs/gap-text2sql / __init__

Method __init__

rat-sql-gap/seq2struct/utils/random_state.py:28–42  ·  view source on GitHub ↗
(self, seed=None)

Source from the content-addressed store, hash-verified

26class RandomContext:
27 '''Save and restore state of PyTorch, NumPy, Python RNGs.'''
28 def __init__(self, seed=None):
29 outside_state = RandomState()
30
31 random.seed(seed)
32 np.random.seed(seed)
33 if seed is None:
34 torch.manual_seed(random.randint(-sys.maxsize - 1, sys.maxsize))
35 else:
36 torch.manual_seed(seed)
37 # torch.cuda.manual_seed_all is called by torch.manual_seed
38 self.inside_state = RandomState()
39
40 outside_state.restore()
41
42 self._active = False
43
44 def __enter__(self):
45 if self._active:

Callers

nothing calls this directly

Calls 2

restoreMethod · 0.95
RandomStateClass · 0.85

Tested by

no test coverage detected