Created
August 2, 2025 14:47
-
-
Save aasthavar/f1fa9f7e13954b905f9593ab986cd371 to your computer and use it in GitHub Desktop.
π₯ Prepare ML Environment | Seed All The Things π₯
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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