Files
ChatTTS/tools/seeder/ctx.py
T
github-actions[bot]andgithub-actions[bot] 93db24b4b2 chore(format): run black on main (#443)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-06-25 17:22:13 +09:00

15 lines
329 B
Python

import torch
class TorchSeedContext:
def __init__(self, seed):
self.seed = seed
self.state = None
def __enter__(self):
self.state = torch.random.get_rng_state()
torch.manual_seed(self.seed)
def __exit__(self, type, value, traceback):
torch.random.set_rng_state(self.state)