Back to Tinygrad

List of environment variables that control tinygrad behavior.

docs/env_vars.md

0.13.04.0 KB
Original Source

List of environment variables that control tinygrad behavior.

This is a list of environment variable that control the runtime behavior of tinygrad and its examples. Most of these are self-explanatory, and are usually used to set an option at runtime.

Example: DEV=CL DEBUG=4 python3 -m pytest

However you can also decorate a function to set a value only inside that function.

python
# in tensor.py (probably only useful if you are a tinygrad developer)
@Context(DEBUG=4)
def numpy(self) -> ...

Or use contextmanager to temporarily set a value inside some scope:

python
with Context(DEBUG=0):
  a = Tensor.ones(10, 10)
  a *= 2

Global Variables

The columns of this list are are: Variable, Possible Value(s) and Description.

  • A # means that the variable can take any integer value.

These control the behavior of core tinygrad even when used as a library.

VariablePossible Value(s)Description
DEBUG[1-7]enable debugging output (operations, timings, speed, generated code and more)
DEV[AMD, NV, ...]enable a specific backend, see below
BEAM[#]number of beams in kernel beam search
DEFAULT_FLOAT[HALF, ...]specify the default float dtype (FLOAT32, HALF, BFLOAT16, FLOAT64, ...), default to FLOAT32
IMAGE[1]enable 2d specific optimizations
FLOAT16[1]use float16 for images instead of float32
JIT[0-2]0=disabled, 1=jit enabled (default), 2=jit enabled, but graphs are disabled
VIZ[1]0=disabled, 1=viz enabled
ALLOW_TF32[1]enable TensorFloat-32 tensor cores on Ampere or newer GPUs.
WEBGPU_BACKEND[WGPUBackendType_Metal, ...]Force select a backend for WebGPU (Metal, DirectX, OpenGL, Vulkan...)
CUDA_PATHstrUse CUDA_PATH/include for CUDA headers for CUDA and NV backends. If not set, TinyGrad will use /usr/local/cuda/include, /usr/include and /opt/cuda/include.

DEV variable

The DEV variable deserves special note due to its more nuanced syntax. DEV is used to specify the target device, target renderer and target architecture for said device, separated by colons. Specifying the renderer and architecture is optional, omitting a preference will cause tinygrad to automatically determine a suitable setting. The DEV variable may also be used to specify the interface through which to access the device (eg. PCI, USB). Interfaces may be specified preceding the target triple, separated by a plus (eg. DEV=USB+AMD:LLVM). Similarly as above, the interface may be omitted. Example usage follows:

DEV contentsInterpretation
AMDuse the AMD device
AMD:LLVMuse the AMD device with the LLVM renderer
NV:CUDA:sm_70use the NV device with the CUDA renderer targetting sm_70
AMD::gfx950use the AMD device targetting gfx950
USB+AMDuse the AMD device over the USB interface
CPU:LLVMuse the CPU device with the LLVM renderer
CPU:LLVM:x86_64,znver2,avx2,-avx512fuse the CPU device with the LLVM renderer, with additional arch flags

Debug breakdown

VariableValueDescription
DEBUG>= 1Enables debugging and lists devices being used
DEBUG>= 2Provides performance metrics for operations, including timing, memory usage, bandwidth for each kernel execution
DEBUG>= 3Outputs the applied optimizations at a kernel level
DEBUG>= 4Outputs the generated kernel code
DEBUG>= 5Displays the intermediate representation of the computation UOps
DEBUG>= 6Displays the intermediate representation of the computation UOps in a linearized manner, detailing the operation sequence
DEBUG>= 7Outputs the assembly code generated for the target hardware