S-exp GPU
All pages
Docs · The command lineMarkdown

Devices

A run executes on one device kind, chosen at start with --device or SEXPGPU_DEVICE. The file never names a device; the same IR runs on every backend.

devicewhat it isfor
cputhe optimized host backend, the defaultlocal training and evaluation without a GPU
referencethe unoptimized IR interpreterreference runs and debugging
metalthe GPU of an Apple silicon Maclocal training and evaluation at small sizes
cudaNVIDIA GPUs on Linuxtraining
rocmAMD GPUs on Linux x86-64training

The CPU backend

The CPU backend uses multiple host cores for dense tensor work. Limit its worker count when sharing a machine:

sexpgpu run <file.sx> --device cpu --cpu-cores 4
SEXPGPU_CPU_CORES=8 sexpgpu run <file.sx> --device cpu

The limit applies to SexpGPU's CPU workers and does not change the machine's other processes. --cpu-cores must be a positive integer.

The reference interpreter

The reference interpreter keeps every node's value alive for the whole graph and runs one thread. Use it for small reference runs:

(defvariant smoke (layers 2) (width 128) (seq 64))
sexpgpu run <file.sx> --variant smoke --steps 3 --device reference

The reference device is the numerical oracle for the other backends. A normal --device cpu run uses the optimized host backend instead, which agrees with it within numerical tolerance, not bit for bit.

The Metal device

--device metal or SEXPGPU_DEVICE=metal selects the Apple GPU. It requires an Apple silicon Mac, macOS 12 or newer, and the published macOS binary; it needs neither CUDA nor the Xcode command-line tools.

sexpgpu run my-run.sx --device metal

Every IR operation runs on Metal, gradients included, and training, generation, evaluation, metrics and checkpoints work as on the other devices. Scatters fold repeated indices in input order.

Metal uses one GPU and has no memory plan or stacking. A buffer larger than the device's maximum, or an allocation Metal cannot satisfy, stops the run with E-MEM-002:

sexpgpu run: E-MEM-002: the Metal device could not allocate 34358689800 bytes for a tensor of [65535, 65535] i64; the run does not fit this GPU

A graph the GPU starts but cannot finish stops the run with Metal's error code and description, and the bytes this process holds on the GPU against the device's recommended working set; error 8 is out of memory, and other processes on the GPU count against the same memory.

BF16 values are stored as F32 and rounded at explicit casts, matching the CPU interpreter, so BF16 saves no memory and no time on Metal. Integers are stored as I64, including i32. SEXPGPU_DEVICES accepts only 0 or unset, and CUDA-specific kernel switches have no effect.

The CUDA device

SEXPGPU_DEVICE=cuda runs on the published Linux binaries.

requirementwhy
a CUDA 13 driver, 580 series or newerthe binary loads the 13.x driver at start
compute capability 8.0 or newer: A100, L4, H100an older card is refused when the device opens. The native cuDNN products run on compute_80 only, the native attention and convolution on compute_80 and newer
CUDA 13's cuBLAS, cuBLASLt and NVRTCthe products and the generated kernels; a run that cannot load one stops before the device opens and names it. See install
cuDNN 9.13.0 for CUDA 13, optionalthe native product, attention and convolution graphs; without it those regions run the ordinary lowering, and the lowering report says so
NCCL for CUDA 13, over several GPUsthe sum between GPUs, from libnccl.so.2 or libnccl.so; a run over several GPUs or nodes that cannot load it stops before they start

sexpgpu doctor checks the floor and each library's version.

When CUDA reports a launch failure during a graph node, the error includes the node's lowered operation and the GPU identity and driver API version when available. With asynchronous launches, the node is where the failure was observed. Earlier GPU work may have failed. To narrow it down, rerun the same selection with CUDA_LAUNCH_BLOCKING=1 set on the machine executing the run. This changes launch timing, so record whether the failure occurs in each mode.

For a run over several GPUs, collective memory lines report each GPU's free memory before and after communicator initialization and the first gradient sum. An NCCL submission failure reports free memory again and includes the library's error detail when available. Include these lines when reporting a failure; ncclUnhandledCudaError alone does not identify an out-of-memory error.

For CUDA multi-GPU runs, NCCL_SET_STACK_SIZE defaults to 1 so memory planning includes NCCL's kernel stack; an explicit setting is preserved.

A CUDA or ROCm run compiles each of its kernels once for all of its GPUs: the timing kernels line counts the kernels it compiled, and as loaded those a GPU took from that compile instead of compiling them again. Nothing compiled is kept after the run, so every run compiles its own kernels.

What the device did with each graph is the lowering report. runtime/peak_bytes reports the allocator's high-water mark every step; see metrics.

The ROCm device

SEXPGPU_DEVICE=rocm runs on the ROCm build, which the install script puts beside the CUDA build on Linux x86-64 as sexpgpu-rocm. sexpgpu hands every command that names rocm, with --device or SEXPGPU_DEVICE, to sexpgpu-rocm; without that file beside it, the command exits 2 and prints the install command.

requirementwhy
an AMD Instinct GPU, such as MI250X or MI300Xthe kernels compile for the GPU's own architecture, gfx90a on an MI250X and gfx942 on an MI300X, which the lowering report names
ROCm 7.2's HIP runtime, HIPRTC and rocBLASthe device, the generated kernels and the products; a run that cannot load one stops before the device opens and names it. See install
RCCL, over several GPUsthe sum between GPUs; a run over several GPUs or nodes that cannot load it stops before they start

sexpgpu doctor opens the GPU and names it and its architecture.

A ROCm run is planned, compiled and replayed as a CUDA run is, so the kernel cache above and the memory plan, the stacking and several GPUs and nodes below hold for it too. What differs:

  • The ordinals are HIP's, and each of an MI250X's two dies is its own device. HIP_VISIBLE_DEVICES limits what is visible.
  • The lowering report starts with the device rocm and the architecture, lowering: rocm gfx942 <GPU>, patterns on.

Memory

Before its first step a CUDA or ROCm run works out the most it will hold at once on each GPU, and chooses how many microbatches one call of the training graph runs (its stacking). Both are lines of the lowering report. When the stacking is measured at the first step, the report waits for the measurement and names the degree chosen, so it follows the first step's evaluation. The run ends with the peak it reached against the plan:

lowering: cuda compute_80 NVIDIA A100-SXM4-80GB, patterns on
  ...
  memory                    2.7 GiB of 78.8 GiB free
  stacking                  1: measured at the first step, the model within 5% could not separate them (4 130.2 ms, model 130.5 ms; 2 135.2 ms, model 131.5 ms; 1 128.9 ms, model 133.6 ms)
...
memory: peak 2.8 GiB in a training step of 2.7 GiB planned in training (+1.8%)

Each peak names where it was reached: the training step or evaluation pass in which the run's memory last rose to its peak, and the part of a step the plan expected to hold the most, such as training, update default or evaluation eval.

  • Stacking needs training and generator graphs without bf16 nodes. An optimizer may compute in bf16, as newton-schulz does: it runs once a step on the summed gradients. Stacking is chosen among the degrees that fit: the only one, the cost model's prediction, or a measurement at the first step when the predictions are within 5 percent. A measured choice can differ from run to run and on another device, where the F32 products then sum in another order; see determinism.
  • The plan keeps 1 GiB free for the libraries, counts selected optimizer diagnostics, and counts the memory a step keeps to reuse in the next step, not only what is in use at once. It stacks F32 microbatches only when the stacked graph fits, drops cached parameter results when only that fits (a later microbatch or evaluation batch holds all of them from its start), then shrinks the execution cache to what the rest of the plan leaves free, then counts only what is in use at once, and otherwise refuses with E-MEM-001 before any initializer runs. A plan that counts only what is in use at once adds idle buffers released when the device is full to the memory line: the run gives memory back and takes it again as it goes, which is slower and can still fail to allocate (below); raising :microbatches can avoid it.
  • The execution cache holds the graphs CUDA replays instead of launching their kernels one by one. Shrunk, the memory line names it, execution cache 6.9 GiB, or says execution cache off when too little is left to hold one. Graphs that do not fit in it run without replay, with the same results, which can make evaluation passes and updates slower.
  • An allocation that fails anyway releases the device's caches and retries, and says so in a memory: allocation failed line and annotation. A training microbatch is retried once, by the run or by the device itself, and from then on the run keeps cached parameter results and the execution cache off, which the line names (caches released and kept off (parameter results recomputed, execution cache off)), so that the next microbatch does not run out again. When the retry fails too, or when the third microbatch in a row cannot allocate on its first try, the run stops with E-MEM-003, naming the step, the microbatch, the planned memory and what is free on the device. An evaluation pass runs once more from its first batch, and stops the run when it fails again. A rank that stops this way stops the whole run.
  • A generator is a phase of the plan, stacked with the training graph's degree. The memory line adds its largest, generation 0.4 GiB, and the cost model prices a step's generation with its training calls.
  • Both lines are annotations on the metrics stream, the memory one with its parts: parameters, optimizer states, gradients, constants, collective buffers, the largest graph's live set, the idle buffers a step keeps beside it, the execution cache, a generator's largest phase, and where it peaks.
  • The final memory line compares the graphs' live set with the plan less its idle buffers. It reports the execution cache's peak against its size on its own and leaves out the collective buffers a run over several nodes holds; runtime/peak_bytes adds the cache's peak to the allocator's.
  • SEXPGPU_MEMORY plans against a smaller card than the one present.

Several GPUs

SEXPGPU_DEVICES=0,1 runs data parallel over those GPU ordinals, in rank order; unset uses every visible device, and one ordinal is the single-GPU path. CUDA_VISIBLE_DEVICES, or HIP_VISIBLE_DEVICES on ROCm, limits what is visible.

  • The global defrun :microbatches is split over the GPUs, so the device count must divide it. Each rank reads its own share of every training loader.
  • The result is the same experiment: one optimizer step per step, gradients combined across ranks.
  • Timing series and sampled diagnostics are rank zero's; a diagnostic's reducer folds across ranks.
  • A resume needs the device count the checkpoint was written with.

When evaluation leaves a host round incomplete for 60 seconds, the log prints data-parallel wait once a minute. It names each rank waiting for peers and each rank's latest evaluation step, pass, local batch and activity, with the time since that activity began. The same information is a Metrics annotation. Include these lines when reporting an evaluation stall with sexpgpu feedback --bug.

Several nodes

One run can span machines: one run process on each node, each with SEXPGPU_DEVICE=cuda, or each with SEXPGPU_DEVICE=rocm, and the same number of GPUs. A node's GPUs are the global ranks after the previous nodes'.

variablemeaning
SEXPGPU_NODESthe node count; unset or 1 is one node
SEXPGPU_NODE_RANKthis process's node, 0 to nodes - 1. Node 0 writes the metrics, the status file and the checkpoints, so a checkpoint location every node reads is a bucket or o41:// one; on a resume node 0 alone reads the tensors and sends them to the others
SEXPGPU_RENDEZVOUShost:port of node 0, where it listens once for the other nodes. Under SkyPilot the host is the first line of SKYPILOT_NODE_IPS
SEXPGPU_NODE_GRADIENTSbf16 (default) rounds each device's f32 gradients to bf16 for the sum between nodes, carrying each rounding's error into the next step, half the bytes on the wire; f32 sends gradients without this rounding or carried error and is what --deterministic sends. It does not guarantee identical results across node layouts or resume. Every node sets the same

Node 0 prints rendezvous: listening on 0.0.0.0:<port> after it binds. To let the operating system choose a free port, start node 0 with port 0. Use the announced port with node 0's reachable host address for the other nodes. Keep node 0 running while they join.

Under SkyPilot with num_nodes, each node's run sets the three from SkyPilot's own variables:

export SEXPGPU_NODES="$SKYPILOT_NUM_NODES" SEXPGPU_NODE_RANK="$SKYPILOT_NODE_RANK"
export SEXPGPU_RENDEZVOUS="$(echo "$SKYPILOT_NODE_IPS" | head -n1):29500"

A sexpgpu rrun job with --nodes N sets the three on every node itself, from rrun's RRUN_NODES, RRUN_NODE_RANK, RRUN_MASTER_ADDR and RRUN_MASTER_PORT.

A resume needs the node count the checkpoint was written with.

Errors

They stop run with exit 1, before or during training; doctor reports E-DP-001 and E-DP-005.

codewhenfix
E-DP-001SEXPGPU_DEVICES does not parse, repeats an ordinal, names one that is not visible, or no GPU is visiblelist visible ordinals once each, SEXPGPU_DEVICES=0,1
E-DP-002a resume's rank count, node count or loader rank differs from the checkpoint's; the message names bothresume with the checkpoint's nodes and devices
E-DP-003the global microbatches do not divide over the GPUspick a device count that divides :microbatches
E-DP-004the ranks' or the nodes' parameters, optimizer states, or CUDA product choices disagree at a checkpointa backend bug, never the experiment's fault: that checkpoint was not written, so --resume latest continues from the one before; report the full diagnostic and SEXPGPU_DEVICES with sexpgpu feedback
E-DP-005SEXPGPU_NODES is not a count, SEXPGPU_NODE_RANK is not in 0..nodes, SEXPGPU_RENDEZVOUS is not host:port, SEXPGPU_NODE_GRADIENTS is not f32 or bf16, or the device is not cuda or rocmset all three on every node, with SEXPGPU_DEVICE=cuda or rocm
E-DP-006a node differs from node 0 at the rendezvous: node count, a node index twice, GPU count, experiment (the IR's digest), the files and selection it was compiled from or the steps, seed, data or time limit it runs with, gradient dtype, or the checkpoint it resumes; the message names boththe same files, flags, device count and checkpoint location on every node
E-DP-007a node did not arrive at the rendezvous within 300 s, a connection to node 0 sent no node's hello, or a node left the runstart every node, and keep other programs off node 0's port; after a loss, restart every node with --resume latest
E-DP-008the sum of gradients between the GPUs of one node ran for 600 s without finishing: a GPU or the link between GPUs stopped answering, a fault of the machine; the message names the GPUs still in itrun on another machine with --resume latest

E-DP-004 names the checkpoint step, the ranks, and the first parameter or optimizer state that differs: its key and either the schema difference or the first differing element's flat index and values, with hexadecimal bits for floats. Across nodes it names the node whose checkpoint digest differs.

Related: run, doctor, defrun, environment.