Skip to main content

Random number generation for AWS Trainium via NKI

Project description

trnrand

CI codecov Ruff PyPI Python License Docs

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

Current phase

trnrand follows the trnsci 5-phase roadmap. Active work is tracked in phase-labeled GitHub issues:

(No Phase 2 for trnrand — the precision story is inherited where relevant.)

Suite-wide tracker: trnsci/trnsci#1.

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

Disclaimer

trnsci is an independent open-source project. It is not sponsored by, endorsed by, or affiliated with Amazon.com, Inc., Amazon Web Services, Inc., or Annapurna Labs Ltd.

"AWS", "Amazon", "Trainium", "Inferentia", "NeuronCore", "Neuron SDK", and related identifiers are trademarks of their respective owners and are used here solely for descriptive and interoperability purposes. Use does not imply endorsement, partnership, or any other relationship.

All work, opinions, analyses, benchmark results, architectural commentary, and editorial judgments in this repository and on trnsci.dev are those of the project's contributors. They do not represent the views, positions, or commitments of Amazon, AWS, or Annapurna Labs.

Feedback directed at the Neuron SDK or Trainium hardware is good-faith ecosystem commentary from independent users. It is not privileged information, is not pre-reviewed by AWS, and should not be read as authoritative about product roadmap, behavior, or quality.

For official AWS guidance, see aws-neuron documentation and the AWS Trainium product page.

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

trnrand-0.4.1.tar.gz (685.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trnrand-0.4.1-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file trnrand-0.4.1.tar.gz.

File metadata

  • Download URL: trnrand-0.4.1.tar.gz
  • Upload date:
  • Size: 685.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trnrand-0.4.1.tar.gz
Algorithm Hash digest
SHA256 8654bbb80c72d1480b33fd4ede6e90df5c7483a0e23ec32d0af014a7d3141bf6
MD5 c4c552a68efcde940487319fda66b477
BLAKE2b-256 1ff76ff4b308a7337dcb85cc123b4e7aafc66c57c43e8fb89b4bd6e8675d531d

See more details on using hashes here.

Provenance

The following attestation bundles were made for trnrand-0.4.1.tar.gz:

Publisher: publish.yml on trnsci/trnrand

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trnrand-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: trnrand-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trnrand-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf1972f5487d3ecc2ff880b9c6e76132ab41195519dfc3aa032b287b9b2f2e4
MD5 8b170343acc9f0dc1185fa84443abd9d
BLAKE2b-256 d11764454112507f3c2d4d6077bd4a34238deb2dde02156f9cb1e6d1f2ee5740

See more details on using hashes here.

Provenance

The following attestation bundles were made for trnrand-0.4.1-py3-none-any.whl:

Publisher: publish.yml on trnsci/trnrand

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page