Skip to content

Instantly share code, notes, and snippets.

@aasthavar
Created August 2, 2025 14:47
Show Gist options
  • Select an option

  • Save aasthavar/f1fa9f7e13954b905f9593ab986cd371 to your computer and use it in GitHub Desktop.

Select an option

Save aasthavar/f1fa9f7e13954b905f9593ab986cd371 to your computer and use it in GitHub Desktop.
πŸ”₯ Prepare ML Environment | Seed All The Things πŸ”₯
import os
import torch
import random
import numpy as np
import pandas as pd
def set_seed(seed: int):
"""
Set random seed for reproducibility across numpy, torch, and python.
"""
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
# if using CUDA
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
# ensure deterministic behavior
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
# set PYTHONHASHSEED environment variable
os.environ['PYTHONHASHSEED'] = str(seed)
print(f"seeds set to: {seed}")
set_seed(seed=37)
pd.set_option("display.max_columns", None)
pd.set_option('display.max_rows', None)
pd.set_option('display.width', 1000)
pd.set_option("max_colwidth", None)
pd.set_option("max_seq_item", None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment