skillfed

pytorch-seed

RNG seeding and context management for pytorch

pytorch-seed v0.2.0 124.1K downloads/30d#11,885 on PyPI2
Permissive 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) Abandoned released

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-seed

uv

uv add pytorch-seed

poetry

poetry add pytorch-seed

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: Only

Tags

pytorch reproducible seedingtorch rng seed everythingpytorch random state managementdeterministic pytorch trainingtorch cuda rng controlpytorch reproducibility utilities
reproducibilityrng-seeding

More Artificial Intelligence packages

Further reading