latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
Environment variables
TensorPlay reads a small set of environment variables to adjust runtime behavior: where downloaded files are cached, whether out-of-tree device backends load at import, how errors are reported, and how the experimental graph translator validates itself.
Unless noted otherwise, set a variable before the process starts (or at
least before the module that reads it is imported — several are read once
and cached). Values are strings; 1 and 0 enable and disable.
Paths and caching
Variable |
Default |
Effect |
|---|---|---|
|
|
Root directory for weights downloaded by the vision model loaders. |
TENSORPLAY_HOME is consulted by
tensorplay.vision.load_state_dict_from_url (and the model zoo helpers
built on it) when deciding where to cache downloaded checkpoints. The hub
cache used by tensorplay.hub is a different tree — it lives under
~/.cache/tensorplay and is relocated through the tensorplay.hub.set_dir
API, not through this variable.
Device and CUDA
Variable |
Default |
Effect |
|---|---|---|
|
|
Import out-of-tree device backends at |
|
unset |
Make |
|
|
Device key for the sparse operator tuning store. |
Setting TENSORPLAY_DEVICE_BACKEND_AUTOLOAD=0 skips the out-of-tree
backend scan during import, for startup time or isolation. The current
state is visible through the helper the import path itself uses:
import tensorplay
tensorplay._is_device_backend_autoload_enabled()
# True, unless the variable is set to something other than 1
With TENSORPLAY_NVML_BASED_CUDA_CHECK=1, tensorplay.cuda.is_available()
probes the driver through NVML instead of initializing a CUDA context —
useful because a context created before fork poisons the child. The
check is therefore fork-safe under this flag.
TENSORPLAY_DEVICE_NAME selects the device-name key under which the
sparse operator tuning metadata is stored and looked up; set it to the
accelerator in use (e.g. a GPU name) to read the matching tuning entries.
Debugging
Variable |
Default |
Effect |
|---|---|---|
|
unset |
Attach captured native stack traces to errors raised from C++. |
When set to 1, errors raised on the C++ side of the library carry the
native stack trace captured at the throw site. The flag is read once at
first use and cached — set it before the first error occurs, which in
practice means before the workload starts.
Serialization
Variable |
Default |
Effect |
|---|---|---|
|
|
Upper bound on threads staging MEGA tensor payloads. |
When saving a MEGA checkpoint, the tensor payloads are staged by a thread
pool whose size is min(TENSORPLAY_SERIALIZATION_WORKERS, number of tensors) — never more threads than tensors, and never more than requested.
The default uses at most four workers regardless of core count. An invalid
(non-integer) value falls back to the default.
Graph translation (experimental)
Variable |
Default |
Effect |
|---|---|---|
|
|
Validate translated graphs against the original. |
|
|
Wall-clock budget for validation, in milliseconds. |
|
|
Skip bisection when validation fails. |
These configure the experimental graph translator’s self-check: when
TENSORPLAY_TRANSLATION_VALIDATION=1, each translated program’s guards are
checked symbolically (via sympy, and z3 when installed) to admit exactly
the executions of the original program. The timeout bounds the symbolic
check; when a mismatch is found, a bisection pass pinpoints the first
divergent guard unless TENSORPLAY_TRANSLATION_NO_BISECT=1 skips it. All
three are read when tensorplay.graph.experimental is imported.
Help improve this page
Found an error, an unclear step, or a missing example?
DLPack
DLPack is a neutral, zero-copy exchange format for tensors. It lets two different libraries hand a tensor back and forth without copying the data, describing only the shape, strides, data type, and device. TensorPlay int
foreach operations
foreach operations lift an ordinary tensor operation over a whole list of tensors in one call. tensorplay._foreach_add(tensors, other) is semantically equivalent to a Python loop applying tensorplay.add at each list posi

