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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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