CoolFace
Apppublic

team7/talk_with_wind_test_something

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
init.py34 linesDownload Raw Back to helpers
1import torch2import numpy as np3import random4 5 6def worker_init_fn(wid):7    seed_sequence = np.random.SeedSequence(8        [torch.initial_seed(), wid]9    )10 11    to_seed = spawn_get(seed_sequence, 2, dtype=int)12    torch.random.manual_seed(to_seed)13 14    np_seed = spawn_get(seed_sequence, 2, dtype=np.ndarray)15    np.random.seed(np_seed)16 17    py_seed = spawn_get(seed_sequence, 2, dtype=int)18    random.seed(py_seed)19 20 21def spawn_get(seedseq, n_entropy, dtype):22    child = seedseq.spawn(1)[0]23    state = child.generate_state(n_entropy, dtype=np.uint32)24 25    if dtype == np.ndarray:26        return state27    elif dtype == int:28        state_as_int = 029        for shift, s in enumerate(state):30            state_as_int = state_as_int + int((2 ** (32 * shift) * s))31        return state_as_int32    else:33        raise ValueError(f'not a valid dtype "{dtype}"')34