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

Class RandomState

rat-sql-gap/seq2struct/utils/random_state.py:8–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class RandomState:
9 def __init__(self):
10 self.random_mod_state = random.getstate()
11 self.np_state = np.random.get_state()
12 self.torch_cpu_state = torch.get_rng_state()
13 self.torch_gpu_states = [
14 torch.cuda.get_rng_state(d)
15 for d in range(torch.cuda.device_count())
16 ]
17
18 def restore(self):
19 random.setstate(self.random_mod_state)
20 np.random.set_state(self.np_state)
21 torch.set_rng_state(self.torch_cpu_state)
22 for d, state in enumerate(self.torch_gpu_states):
23 torch.cuda.set_rng_state(state, d)
24
25
26class RandomContext:

Callers 3

__init__Method · 0.85
__enter__Method · 0.85
__exit__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected