Random number generation for AWS Trainium via NKI
Project description
trnrand
Random number generation for AWS Trainium via NKI.
Seeded pseudo-random distributions, quasi-random sequences for quasi-Monte Carlo, and on-device Philox RNG targeting the GpSimd engine.
Part of the trnsci scientific computing suite (github.com/trnsci).
Install
pip install trnrand
# With Neuron hardware support
pip install trnrand[neuron]
Usage
import trnrand
# Seeded, reproducible generation
g = trnrand.Generator(seed=42)
# Standard distributions
x = trnrand.normal(1000, mean=0.0, std=1.0, generator=g)
u = trnrand.uniform(1000, low=-1.0, high=1.0, generator=g)
e = trnrand.exponential(1000, rate=2.0, generator=g)
# Quasi-random sequences (better convergence for MC integration)
sobol_pts = trnrand.sobol(1024, n_dims=5, seed=42)
halton_pts = trnrand.halton(1024, n_dims=3)
lhs_pts = trnrand.latin_hypercube(100, n_dims=4)
# Module-level seeding
trnrand.manual_seed(42)
x = trnrand.standard_normal(256)
Operations
| Category | Function | Description |
|---|---|---|
| Distributions | uniform |
U[low, high) |
normal |
N(μ, σ²) | |
standard_normal |
N(0, 1) | |
exponential |
Exp(λ) | |
bernoulli |
Bernoulli(p) | |
randint |
Uniform integers [low, high) | |
randperm |
Random permutation | |
truncated_normal |
Bounded normal (rejection sampling) | |
| Quasi-random | sobol |
Sobol sequence (scrambled) |
halton |
Halton sequence | |
latin_hypercube |
Latin Hypercube Sampling |
MC vs QMC Example
python examples/mc_integration.py
Compares pseudo-random vs Sobol quasi-random for estimating the volume of a 5-D hypersphere. QMC converges O(1/N) vs O(1/√N).
Status
- Seeded Generator with state management
- Standard distributions (uniform, normal, exponential, Bernoulli, etc.)
- Sobol, Halton, Latin Hypercube sequences
- MC vs QMC integration example
- NKI Philox kernel on GpSimd
- On-device Box-Muller (uniform → normal)
- Benchmarks vs cuRAND
Related Projects
| Project | What |
|---|---|
| trnfft | FFT + complex ops |
| trnblas | BLAS operations |
| trnsolver | Linear solvers |
License
Apache 2.0 — Copyright 2026 Scott Friedman
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trnrand-0.1.0.tar.gz.
File metadata
- Download URL: trnrand-0.1.0.tar.gz
- Upload date:
- Size: 638.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b4ec3c37520b514d67cec59c493b93372ede6958d6bc049f4f65ee477936c8d
|
|
| MD5 |
9df5eab65b1fe2eb7c93dfc01c58c197
|
|
| BLAKE2b-256 |
5f3911a03d681d472a661ab310df8f00eab4083d32dc0bfd8f7b1840fb120a07
|
Provenance
The following attestation bundles were made for trnrand-0.1.0.tar.gz:
Publisher:
publish.yml on trnsci/trnrand
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trnrand-0.1.0.tar.gz -
Subject digest:
1b4ec3c37520b514d67cec59c493b93372ede6958d6bc049f4f65ee477936c8d - Sigstore transparency entry: 1282483941
- Sigstore integration time:
-
Permalink:
trnsci/trnrand@68d4cb52d9cc893604e19b64ae4ac9f6c09300c3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/trnsci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68d4cb52d9cc893604e19b64ae4ac9f6c09300c3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file trnrand-0.1.0-py3-none-any.whl.
File metadata
- Download URL: trnrand-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0275a7f814ff3d303bfb41b791f47af7ad55e5670658aacb6edd4c70e9cc23dd
|
|
| MD5 |
e60b15135a92ad5d5d9208017888faf6
|
|
| BLAKE2b-256 |
a24e2fb9b30611d68fe661dc0f1dbef855d66d8ae2db4ab327474117f2d5a1c7
|
Provenance
The following attestation bundles were made for trnrand-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on trnsci/trnrand
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trnrand-0.1.0-py3-none-any.whl -
Subject digest:
0275a7f814ff3d303bfb41b791f47af7ad55e5670658aacb6edd4c70e9cc23dd - Sigstore transparency entry: 1282483967
- Sigstore integration time:
-
Permalink:
trnsci/trnrand@68d4cb52d9cc893604e19b64ae4ac9f6c09300c3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/trnsci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68d4cb52d9cc893604e19b64ae4ac9f6c09300c3 -
Trigger Event:
release
-
Statement type: