Fix the reproducibility audit for a training config
Your task
An AI said a PyTorch training setup was "fully reproducible" because it called torch.manual_seed(42), yet two runs gave different validation scores. Python's and NumPy's random generators, the CUDA seed, the data loader's shuffling, its worker processes and cuDNN's choice of kernels each need a setting of their own. Your team audits run configs for every one of them.
An assistant wrote missing_determinism_settings(config_lines), the audit. It is in the editor. It has a bug. Find it and fix it.
Input and output:
config_lines: the run's config, onekey=valuesetting per line. Later lines override earlier ones, as in a layered config file.- Return the required settings that are missing, in alphabetical order.
Rules the tests check:
- The required settings, in alphabetical order:
cudnn_deterministic,dataloader_generator,numpy_seed,python_seed,torch_cuda_seed,torch_seedandworker_init_fn. - Split a line at its first
=into a key and a value. Skip lines with no=. Trim whitespace from both ends of the key and of the value, and lowercase both. - If a key appears more than once, its last line wins.
- A required setting is missing when its key never appears, or its final value is empty,
falseornone. Any other value counts,0included. - Other keys are ignored.
Examples
missing_determinism_settings(config_lines: list[str]) -> list[str]Example 1
Input
missing_determinism_settings(["python_seed=42", "numpy_seed=42", "torch_seed=42", "torch_cuda_seed=42", "dataloader_generator=g", "worker_init_fn=seed_worker", "cudnn_deterministic=true"])Output
[]Example 2
Input
missing_determinism_settings(["torch_seed=42"])Output
["cudnn_deterministic", "dataloader_generator", "numpy_seed", "python_seed", "torch_cuda_seed", "worker_init_fn"]