Skip to main content

core.spawn_generator

core.spawn_generator(generator=None, /, *, device=None)

Draw one seed and return a fresh generator seeded with it.

torch.manual_seed makes the result repeatable when generator is None. Each call advances the source by one draw, so two calls give generators with different seeds.

g = lk.core.spawn_generator()  # from torch's global RNG
h = lk.core.spawn_generator(torch.Generator().manual_seed(0), device="cuda")

Parameters

Name Type Description Default
generator torch.Generator | None The source of the seed. It advances by one draw. None means torch’s global RNG. It may live on any device. None
device torch.device | str | None The device of the new generator. None means the CPU. None

Returns

Name Type Description
torch.Generator A new torch.Generator. Its initial_seed() is the seed that was drawn, at most \(2^{63} - 1\).