latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
Multiprocessing package - tensorplay.multiprocessing
Warning
If the main process exits abruptly (e.g. because of an incoming signal),
Python’s multiprocessing sometimes fails to clean up its children.
It’s a known caveat, so if you’re seeing any resource leaks after
interrupting the interpreter, it probably means that this has just happened
to you.
Strategy management
Set the strategy for sharing CPU tensors. |
|
Return the current strategy for sharing CPU tensors. |
|
Return a set of sharing strategies supported on a current system. |
CUDA in multiprocessing
Cross-process sharing is implemented for CPU tensors only: pickling a tensor
on any other device raises a RuntimeError, so move tensors to the CPU
before sending them through a queue, and move them back on the device in the
receiving process.
Using CUDA inside subprocesses additionally requires the spawn or
forkserver start method. The runtime cannot be re-initialized in a process
that was forked after initialization; such a child fails with
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method.
Spawning subprocesses
Note
Available for Python >= 3.4.
This depends on the spawn start method in Python’s
multiprocessing package.
Spawning a number of subprocesses to perform some function can be done
by creating Process instances and calling join to wait for
their completion. This approach works fine when dealing with a single
subprocess but presents potential issues when dealing with multiple
processes.
Namely, joining processes sequentially implies they will terminate
sequentially. If they don’t, and the first process does not terminate,
the process termination will go unnoticed. Also, there are no native
facilities for error propagation.
The spawn function below addresses these concerns and takes care
of error propagation, out of order termination, and will actively
terminate processes upon detecting an error in one of them.
A ProcessContext is returned by spawn when called with join=False.
tensorplay.multiprocessing.pool
Help improve this page
Found an error, an unclear step, or a missing example?
Meta device
The “meta” device is an abstract device whose tensors record only metadata — shape, dtype, strides — and no data. Meta tensors answer “what would the result look like” without spending compute or memory on values, which
Patching batch norm
Batch normalization updates its running_mean and running_var buffers in place on every training forward. Under a transform that evaluates a module more than once — differentiating through it, or mapping an ensemble over

