Skip to main content

Easy seeding for machine learning frameworks

Project description

seedpy logo

seedpy

Easily seed frameworks used for machine learning like Numpy and PyTorch using context managers.

Disclaimer

This is almost entirely untested software (especially the torch part). Use at your own risk. If you have feature suggestions, found bugs, or want to contribute, feel free to open up issues and / or pull-requests.

Changelog

  • 0.3 - Added seed and random state conversion methods and a numerical seed generator
  • 0.2 - Added decorators, removed requirement for numpy and pytorch

Installation

pip install git+https://github.com/MatthiasJakobs/seedpy.git

Usage

Use fixedseed to fix the seed of the global Numpy inside the context manager:

np.random.seed(0)

# Number generated using seed "0"
before_fixedseed = np.random.rand(5)

with fixedseed(np, seed=10100):
    # Number generated using seed "10100"
    inside_fixedseed = np.random.rand(5)

# Number generated using seed "0"
after_fixedseed = np.random.rand(5)

You can also pass in the torch global object, or even a list of both:

with fixedseed([torch, np], seed=10100):
    ...

The same syntax can be used for the randomseed context in order to randomize calculations inside an otherwise fixed environment:

with randomseed([torch, np]):
    ...

You can use get_random_state to obtain a numpy.random.RandomState object from any seed-like value (int or str) or an existing RandomState object. This is particularly useful when defining reproducible functions to offer a wide variety of possible seeding options, e.g.

def do_something(..., state=None):
    random_state = get_random_state(state) # could be int, str or RandomState
    ....

Project details


Release history Release notifications | RSS feed

This version

0.3

Download files

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

Source Distribution

seedpy-0.3.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

seedpy-0.3-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file seedpy-0.3.tar.gz.

File metadata

  • Download URL: seedpy-0.3.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for seedpy-0.3.tar.gz
Algorithm Hash digest
SHA256 206768c0d4aa2624180a329740c8d3b650b9e061d1d754529bfee43e065ba967
MD5 1b0e1aa139992fb1ef8e7fc8e54c6a22
BLAKE2b-256 dc087eca95607684bffa24c70fc355ac4cf494ebc62b1a95f3677f99e579bc17

See more details on using hashes here.

File details

Details for the file seedpy-0.3-py3-none-any.whl.

File metadata

  • Download URL: seedpy-0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for seedpy-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 de5473f3324383a0e34c309a4d2b3c2f0d6c382c7be1909984aa51af7332c9fb
MD5 98da9297ccf94c69542c826c06f3fc99
BLAKE2b-256 b5826bdc6a9766d34c43b8b49669f42b8ef9c23c00f67e1d51325192bb1c3a59

See more details on using hashes here.

Supported by

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