mllam/neural-lam

Complete deterministic training by adding CUBLAS workspace config and DataLoader worker seeding

Open

#265 opened on Feb 25, 2026

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Python (276 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (282 stars)
PR merge metrics
 (PR metrics pending)

Description

The Trainer already sets deterministic=True (train_model.py#L319), but two things are still missing for runs to be truly reproducible with the same seed.

  1. CUBLAS_WORKSPACE_CONFIG is not set Without this env var, cuBLAS matrix multiplications on GPU can still be non-deterministic even with deterministic=True. PyTorch documents this explicitly. Fix is one line at the top of main():
os.environ.setdefault("CUBLAS_WORKSPACE_CONFIG", ":4096:8")
  1. No worker_init_fn on the DataLoaders With num_workers=16, each worker gets a copy of the random state. Without a worker_init_fn, workers across runs can end up with correlated seeds. PyTorch recommends seeding each worker independently:
def _worker_init_fn(worker_id):
    worker_seed = torch.initial_seed() % 2**32
    np.random.seed(worker_seed)
    random.seed(worker_seed)

Then pass worker_init_fn=_worker_init_fn to all three DataLoaders in WeatherDataModule.

Contributor guide