mirror of
https://github.com/2noise/ChatTTS.git
synced 2026-11-04 05:23:22 +08:00
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
15 lines
329 B
Python
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)
|