pytorch-seed
RNG seeding and context management for pytorch
What it is and what it does
pytorch-seed is a lightweight utility for reproducible random number generation in PyTorch projects. It provides a single `seed()` function that simultaneously seeds Python's base RNG, NumPy's RNG, PyTorch's CPU RNG, and all CUDA RNGs—ensuring deterministic behavior across the entire stack. It also offers a `SavedRNG` context manager that lets you temporarily isolate RNG state, either to run code without affecting the global RNG or to maintain independent RNG streams that resume from where they left off.
The package is designed for researchers and practitioners who need reproducible training runs or experiments. Its API mirrors PyTorch Lightning's seeding utilities, making it familiar to users of that ecosystem. Installation is straightforward with only torch and numpy as dependencies, but note that the project is abandoned as of 2023-02-15 with no active maintenance.
Use it for:
- Seed all RNGs at the start of a training script to ensure reproducible model initialization and data shuffling across runs.
- Use SavedRNG context manager to run stochastic operations (e.g., data augmentation) without affecting the main training RNG stream.
- Maintain separate RNG streams for different parts of an experiment (e.g., one for data generation, one for model dropout) that evolve independently.
- Verify that two seeded runs produce identical random sequences to validate experiment reproducibility.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides reproducible random number generation for PyTorch by seeding Python, NumPy, and all CUDA RNGs together, plus context managers to isolate or save RNG state.
Yes, if you need simple, unified RNG seeding for PyTorch and are comfortable with an abandoned package. The code is straightforward and unlikely to break with minor PyTorch updates, but you should test it with your specific PyTorch version and consider forking if you need future fixes. For active projects requiring long-term support, evaluate whether PyTorch Lightning's seed utilities or manual seeding better fits your needs.
Install
pytorch-seed on PyPI
pip
pip install pytorch-seeduv
uv add pytorch-seedpoetry
poetry add pytorch-seedInstalling pytorch-seed
Before you install
Low friction install with only torch and numpy as runtime dependencies. However, the package is abandoned—last release was 2023-02-15 with no updates since, and the repository shows minimal activity (2 stars). Use only if you need this specific seeding pattern and are comfortable maintaining a fork if issues arise.
License in practice
MIT license (permissive). You can use, modify, and distribute this package freely in commercial or private projects, with no warranty and no liability on the authors.
Quickstart
pip install pytorch-seed
import pytorch_seed
pytorch_seed.seed(123) # Seeds Python, NumPy, torch CPU, and all CUDA RNGs
# Or use SavedRNG context manager to isolate RNG state:
with pytorch_seed.SavedRNG():
result = torch.rand(1) # Does not affect global RNG
Requires PyTorch 1.0+ and Python 3.6+. CUDA RNG seeding only works if CUDA is available.
Verify before relying
- Whether SavedRNG correctly handles all edge cases with newer PyTorch versions (package is abandoned since 2023-02-15).
- Compatibility with PyTorch versions released after the package's last update.
Package facts
| License | Copyright (c) 2023 University of Michigan ARM Lab Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — torch, numpy |
| Maintenance | abandoned — 1,276 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 124,120/month — #11,885 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytorch_seed-0.2.0-py3-none-any.whl
Keywords: rng, pytorch, seeding, reproducibility
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
arm-pytorch-utilitiesProvides utility functions for PyTorch…
permissive · top 15,000 on PyPI
pytest-rngProvides pytest fixtures that make random…
permissive · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
nvidia-curandProvides NVIDIA CURAND native runtime libraries…
unclear · top 1,000 on PyPI
cuequivariance-ops-torch-cu12Provides CUDA-accelerated PyTorch kernels and…
unclear · top 15,000 on PyPI
random2Provides Python 2.7's random module…
permissive · top 15,000 on PyPI
lovely-tensorsMonkey-patches PyTorch tensors to display…
permissive · top 15,000 on PyPI
torch-audiomentationsProvides PyTorch-native audio data augmentation…
permissive · top 5,000 on PyPI
pytorchThis package is a redirect or placeholder; the…
unclear · top 15,000 on PyPI
torchcodecTorchCodec decodes and encodes videos, audio,…
unclear · top 5,000 on PyPI