Skip to main content

saatgut: seed everything, everywhere, all at once.

Project description

saatgut - Seed everything, everywhere, all at once.

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)

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 but of randomness, you can use 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)

Installation

pip install saatgut

Supported libraries

  • random
  • numpy
  • torch
  • tensorflow
  • jax

By extension, this leads to reproducibility in libraries that use these libraries, such as:

  • pandas
  • scikit-learn
  • scipy
  • huggingface libraries, like transformers
  • opencv (cv2)
  • statsmodels
  • gensim

... and many more!

Seeding specific libraries

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.

Why "saatgut"?

The name "saatgut" is derived from the German word for "seed" (Saatgut).

Contributing

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.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

saatgut-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saatgut-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file saatgut-0.1.0.tar.gz.

File metadata

  • Download URL: saatgut-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for saatgut-0.1.0.tar.gz
Algorithm Hash digest
SHA256 014b5a734fd0729306c0a23a23bd37bccf8b90da1011cc572fbc53b81b459a64
MD5 ed4e3b4f8c24d978962c18a41126e987
BLAKE2b-256 7a770a7cab858a14900d8f7d6a6fc12a9846a1f59876f947d2b3d1455f990e82

See more details on using hashes here.

File details

Details for the file saatgut-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: saatgut-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for saatgut-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0cc2245d16a569c056dcd92aff8f46f0f1790b38161531a1be140871b82abe1
MD5 e2b2bc8d7444171b0d7a913b2d23cb2f
BLAKE2b-256 8dea0b906ff6412a39117e0bc52e7131dcdc0ff6ac2492e7e73f0507a8fb5c12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page