Set a seed across all your libraries and frameworks with a single function call.
from saatgut import seed_everything
# Seed everything, everywhere, all at once.
seed_everything(42)The saatgut library is a simple interface to set the seed of many different python libraries. Often times it is helpful to disable all randomness in the program execution to make debugging easier or to make machine learning pipelines more reproducible. When calling the function above, saatgut checks if any of the libraries it knows are installed, and if they are, it sets the given random seed for them.
But sometimes, the seed is not enough. To improve reproducibility even more, you can domesticate everything. This will seed your libraries and modify OS variables to ensure that the environment is as consistent as possible.
from saatgut import domesticate_everything
domesticate_everything(42)To exterminate even the last bit of randomness, you can enable the "hard mode".
This will disable parallel execution in libraries that support it, modify more OS variables, and overwrite some
functions from the random module. This will ensure that your code runs in a fully deterministic manner,
but it will significantly slow down your code (depending on the libraries you use) and make
cryptographic functions deterministic as well. Never use this in a production environment!
from saatgut import domesticate_everything
domesticate_everything(42, hard_mode=True)pip install saatgutrandomnumpytorchtensorflowjax
By extension, this leads to reproducibility in libraries that use these libraries, such as:
pandasscikit-learnscipy- huggingface libraries, like
transformers - opencv (
cv2) statsmodelsgensim
... and many more!
You can also seed specific libraries if you don't want to seed everything. This works for all the libraries listed above.
from saatgut import seed_random, seed_numpy, seed_torch, seed_tensorflow, seed_jax
# Seed only numpy and torch.
seed_numpy(42)
seed_torch(43)Domestication is available for specific libraries as well:
from saatgut import domesticate_random, domesticate_numpy, domesticate_torch, domesticate_tensorflow, domesticate_jax
domesticate_torch(seed=42, force_matmul_precision=True)
domesticate_tensorflow(seed=43, disable_parallelism=True)
domesticate_random(seed=44, derandomize_cryptography=True)The additional parameters used above are specific to the library and can be found in the documentation of each function.
Use them only if normal domestication is not enough for your use case.
Using hard_mode=True in domesticate_everything is equivalent to setting all the additional parameters to True in the specific domestication functions.
The name "saatgut" is derived from the German word for "seed" (Saatgut).
Contributions are welcome! If you find a bug or have a feature request, please open an issue on GitHub. If you want to contribute code, please take a look at the open issues.
This project is licensed under the MIT License. See the LICENSE file for details.
