Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing numpy package from src/lightning #19959

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/lightning/fabric/utilities/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

log = logging.getLogger(__name__)

max_seed_value = np.iinfo(np.uint32).max
min_seed_value = np.iinfo(np.uint32).min
max_seed_value = torch.iinfo(torch.uint32).max
min_seed_value = torch.iinfo(torch.uint32).min


def seed_everything(seed: Optional[int] = None, workers: bool = False) -> int:
Expand Down Expand Up @@ -54,7 +54,6 @@ def seed_everything(seed: Optional[int] = None, workers: bool = False) -> int:
log.info(rank_prefixed_message(f"Seed set to {seed}", _get_rank()))
os.environ["PL_GLOBAL_SEED"] = str(seed)
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)

os.environ["PL_SEED_WORKERS"] = f"{int(workers)}"
Expand Down Expand Up @@ -93,12 +92,12 @@ def pl_worker_init_function(worker_id: int, rank: Optional[int] = None) -> None:
)
ss = np.random.SeedSequence([base_seed, worker_id, global_rank])
# use 128 bits (4 x 32-bit words)
np.random.seed(ss.generate_state(4))
random.seed(ss.generate_state(4))
# Spawn distinct SeedSequences for the PyTorch PRNG and the stdlib random module
torch_ss, stdlib_ss = ss.spawn(2)
torch.manual_seed(torch_ss.generate_state(1, dtype=np.uint64)[0])
torch.manual_seed(torch_ss.generate_state(1, dtype=torch.uint64)[0])
# use 128 bits expressed as an integer
stdlib_seed = (stdlib_ss.generate_state(2, dtype=np.uint64).astype(object) * [1 << 64, 1]).sum()
stdlib_seed = (stdlib_ss.generate_state(2, dtype=torch.uint64).astype(object) * [1 << 64, 1]).sum()
random.seed(stdlib_seed)


Expand Down
Loading