TensorPlay
API reference
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-15

tensorplay.random API

Functions 8

#

default_generator

functionFull reference ↗
tensorplay.random.default_generator() → tensorplay._C.Generator
#

fork_rng

functionFull reference ↗
tensorplay.random.fork_rng(devices=None, enabled=True, _caller='fork_rng', _devices_kw='devices')[source]

Forks the RNG state: code inside the context gets a pristine RNG.

Saves the CPU RNG state and the RNG state of every CUDA device listed in devices on entry and restores them on exit, so random operations inside the block do not advance the outer streams. devices=[] forks only the CPU generator.

#

get_rng_state

functionFull reference ↗
tensorplay.random.get_rng_state() → tensorplay::Tensor
#

thread_safe_generator

functionFull reference ↗
tensorplay.random.thread_safe_generator()[source]

Returns a thread-safe random number generator for use in DataLoader workers.

This function provides a convenient way for transforms and user code to use thread-safe random number generation without manually checking worker context.

When called in a DataLoader thread worker, returns the worker’s thread-local tensorplay.Generator. When called in the main process or process workers, returns None (which causes operations to use the default global RNG).

Example

>>> from tensorplay.random import thread_safe_generator
>>> generator = thread_safe_generator()
>>> tensorplay.randint(0, 10, (5,), generator=generator)

On this page

Ask DeepWiki