๐‘บ๐’๐’‰๐’š๐’–๐’

[Pytorch] Fixing Radom Seed ๋ณธ๋ฌธ

Python

[Pytorch] Fixing Radom Seed

๐Ÿฆ„ํ•‘ํฌํด๐Ÿ’ž 2025. 2. 5. 15:25
# fixing random seed
def seed_everything(seed:int = 1004):
    random.seed(seed)
    np.random.seed(seed)
    os.environ["PYTHONHASHSEED"] = str(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)  # current gpu seed
    torch.cuda.manual_seed_all(seed) # All gpu seed
    torch.backends.cudnn.deterministic = True  # type: ignore
    torch.backends.cudnn.benchmark = False 

seed = seed_everything(42)

print(f"Setting seed to: {seed}")
print("random:", random.randint(0, 100))
print("numpy:", np.random.randint(0, 100))
print("torch:", torch.randint(0, 100, (1,)).item())

 

'Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Python] What is "self" in Python?  (2) 2025.01.07
[Python] Debugging tool (Pdb)  (0) 2025.01.07
[Code] Studying Pytorch for Deep Learning Models  (0) 2025.01.04