From d482a69c482955be42ac6bf126d079ffea3f3be2 Mon Sep 17 00:00:00 2001 From: awaelchli Date: Fri, 12 Jul 2024 22:15:29 +0200 Subject: [PATCH] comments --- src/lightning/fabric/utilities/seed.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lightning/fabric/utilities/seed.py b/src/lightning/fabric/utilities/seed.py index da0d61845d..26a2a1d7f1 100644 --- a/src/lightning/fabric/utilities/seed.py +++ b/src/lightning/fabric/utilities/seed.py @@ -103,9 +103,13 @@ def pl_worker_init_function(worker_id: int, rank: Optional[int] = None) -> None: def _generate_seed_sequence(base_seed: int, worker_id: int, global_rank: int, count: int) -> List[int]: + """Generates a sequence of seeds from a base seed, worker id and rank using the linear congruential + generator (LCG) algorithm.""" + # Combine base seed, worker id and rank into a unique 64-bit number combined_seed = (base_seed << 32) | (worker_id << 16) | global_rank seeds = [] for _ in range(count): + # x_(n+1) = (a * x_n + c) mod m. With c=1, m=2^64 and a is D. Knuth's constant combined_seed = (combined_seed * 6364136223846793005 + 1) & ((1 << 64) - 1) seeds.append(combined_seed) return seeds