Skip to main content

Requirements

  • PyTorch (1.0+)
  • python 3

Installation

pip install pytorch-seed

You can also install in editable mode with python3 -m pip install -e . so that modifications in the repository are automatically synced with the installed library.

Usage

Similar to pytorch lightning's seed_everything, we have

import pytorch_seed
pytorch_seed.seed(123)

which will seed python's base RNG, numpy's RNG, torch's CPU RNG, and all CUDA RNGs.

Also similar to pytorch lightning's isolate_rng context manager, we have

import torch
import pytorch_seed

pytorch_seed.seed(1)
with pytorch_seed.SavedRNG():
    print(torch.rand(1)) # tensor([0.7576])
print(torch.rand(1)) # tensor([0.7576])

They can also be used to maintain independent RNG streams:

import torch
import pytorch_seed

rng_1 = pytorch_seed.SavedRNG(1) # start the RNG stream with seed 1
rng_2 = pytorch_seed.SavedRNG(2)

with rng_1:
    # does not affect, nor is affected by the global RNG and rng_2
    print(torch.rand(1)) # tensor([0.7576])

with rng_2:
    print(torch.rand(1)) # tensor([0.6147])

torch.rand(1) # modify the global RNG state

with rng_1:
    # resumes from the last context
    print(torch.rand(1)) # tensor([0.2793])

with rng_2:
    print(torch.rand(1)) # tensor([0.3810])
    
# confirm those streams are the uninterrupted ones
pytorch_seed.seed(1)
torch.rand(2) # tensor([0.7576, 0.2793])

pytorch_seed.seed(2)
torch.rand(2) # tensor([0.6147, 0.3810])

Testing

Install pytest if you don't have it, then run

py.test

Metadata

Release files for pytorch-seed 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytorch-seed 0.2.0
File Size Uploaded Provenance
pytorch_seed-0.2.0.tar.gz 5.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytorch-seed 0.2.0
File Interpreter ABI Platform
pytorch_seed-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / pytorch_seed-0.2.0.tar.gz

Download URL pytorch_seed-0.2.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
096edd3404f8a00f3df2bab41024945806baf1f64b05678c82373b780458e1a3
BLAKE2b-256 checksum
How to use checksums
deb57d1b68e7eaf16411c3e0e2707e6b0e4ff053f9765deb72a70279fd54d0a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / pytorch_seed-0.2.0-py3-none-any.whl

Download URL pytorch_seed-0.2.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50a1ee2f62e55f88c20069849aa12265a007aeaea6893f3d23ad4e40173c5c89
BLAKE2b-256 checksum
How to use checksums
5c7b6e29f8600d0df90ffce98850130e5ac993e1e29101fa655e38f6c0f60393
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for pytorch-seed 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page