S-exp GPU
All pages
Docs · Models and optimizersMarkdown

Determinism

SexpGPU's numerical contract is agreement with reference loss curves within margin of error. Device results agree within numerical tolerance or a validated error boundary for the model, output and precision. There is no single tolerance for every model. Compare training curves and distributions when rounding grows into different trajectories.

Identical bits are not guaranteed across runs, devices or versions, including for the same experiment on the same device with the same binary. Recorded choices and --deterministic reduce how much a plan may vary; they are tools for the closest reproduction, not guarantees of identical results.

Which flag, when

you wantrun with
the fastest run, on whatever card you getno choice flags: the run chooses for its current device
a spot job that may resume on another card--choices fresh, or SEXPGPU_CHOICES=fresh: the resume chooses for its current device instead of pinning its checkpoint's choices
a resume that keeps its recorded choicesno choice flags: a resume pins itself to its checkpoint's choices, and stops with E-CHOICE-001 if it cannot take them
the recorded choices of a colleague's run--choices <their checkpoint or experiment.json>
fixed choices without measurements--deterministic: no measured choices, unstacked, f32 between nodes; this can be slower

Measured, fixed and recorded choices

When a run measures a choice, every GPU of that run takes the result. A later run can measure a different result. For some choices, the run uses a fixed default. With --deterministic, all choices use fixed rules. A pinned run takes recorded choices or stops if it cannot take them. None of these modes promises identical bits, including on resume.

The reference interpreter, CPU and Metal make no measured choices. CPU, Metal, CUDA and the reference interpreter agree within numerical tolerance, not bit for bit. A Metal checkpoint that recorded a recompute budget of 0 resumes only with --choices fresh; pinning it fails with E-CHOICE-001.

The lowering report of a CUDA run ends with a determinism line describing how choices were obtained and a choices line with what it chose. Its numeric codes describe choice provenance, not reproduction guarantees: 1 uses the run's own measurements, 2 uses recorded or fixed choices, and 3 chooses again on resume or evaluation, or uses choices recorded on a different kind of device. A resume without the carried bf16 gradient error also uses 3. The text names any choices filled in fresh. For example:

  determinism         1: choices measured by this run; identical bits are not guaranteed
  choices             stacking 1, recompute 10.99 flops a byte, 17 convolution engines; on compute_80 with 108 multiprocessors, cuBLAS 130101, cuDNN 91300, NVRTC 13.0, patterns on

What a run chooses

The run uses measurements, the machine's current state, or fixed defaults to make these choices. It records every choice in its checkpoints.

decisionhow it is madeunder --deterministic
scan backward storagethe static memory plan keeps intermediates if the program fits, otherwise recomputes from saved state; recorded for resumethe same static admission rule
the stacking degreeamong the degrees whose memory plan fits the free memory; see memory1, unstacked
a BF16 product's implementation, alone or with a rounded bias, activation, or accumulated gradientmeasured on one GPU, and on several by the first for allordinary product and rounded operations
whether CUDA pairs a BF16 weight gradient with its bias summeasured on one GPU, and on several by the first for allseparate operations
an F32 product's implementationmeasured on one GPU, and on several by the first for all; see numericsordinary GEMM
an F64 product of two F32 tensors widened by castmeasured on A100 and H100, and on several by the first for all; see numericsthe casts and an ordinary F64 GEMM
the fused cross-entropy's fold over the vocabulary and its gradient's arithmeticmeasured on one GPU, and on several by the first for allthe ordinary kernels
a convolution's cuDNN engine, or an F32 one's im2col compositionthe fastest of cuDNN's first deterministic plans and an F32 convolution's composition, timed when the device first meets the shapecuDNN's first deterministic plan
an F32 attention's implementation, with its gradientsmeasured on one GPU, and on several by the first for allthe ordinary kernels
a BF16 causal attention's forward plan and backward implementationmeasured on one GPU, and on several by the first for allcuDNN's
the recompute budget of kernel fusionthe device's measured flops over its bandwidth9 flops a byte
gradients between nodesSEXPGPU_NODE_GRADIENTS, bf16 by default, the same on every node; see several nodesf32

On several GPUs of one kind, the first GPU makes the measured choices for products, attention, and cross-entropy. Every other GPU takes those choices so they all sum in one order. The run records the choices as it would on one GPU. On GPUs of different kinds, each of these takes the implementation in the last column.

Two runs that stack a different number of microbatches into one call can round differently, since cuBLAS can sum a product of more rows in another order, and two convolution engines sum in different orders; on a chaotic run that grows into a different loss curve. bf16 between nodes rounds each device's gradients and carries the rounding error into the next step; a checkpoint does not hold the carried error.

A generator makes no choice of its own: its graphs share the training graph's stacking. A record pinned from a run without a generator stops with E-CHOICE-001 when the generator keeps the run unstacked (it reads :microbatch, :records or :stage-records, has bf16 nodes or has :until) or the plan with the generator does not fit at the recorded degree.

A plan or its numerical results can vary when:

  • a fresh run can measure a choice and get a different result from an earlier run. A pinned or --deterministic run measures no choices;
  • another process holds device memory, so a different set of stacking degrees fits;
  • an allocation fails during the run: the memory: allocation failed line says so, and a stacked run computes unstacked from that step. A pinned run stops with the allocation error instead;
  • it resumes a run with bf16 between nodes: the resumed run starts without the carried error, one step's rounding away from the uninterrupted run. With f32 between nodes, this source of resume error is absent. This does not guarantee identical resumed and uninterrupted results.

Pinning a run to recorded choices

A run records every choice above, the stacking in effect and whether it ran under --deterministic, with its device facts. They go into each checkpoint's experiment.json under choices (checkpoints), into the metadata of the run's lowering annotation and of each choices annotation after it, and into the choices line of the report; sexpgpu checkpoint prints them. When annotation metadata exceeds Metrics' 64 KiB limit, choices become counts such as "673 products, 25 replay: too large to record". Checkpoints and JSONL streams retain the full choices for pinning.

"choices": {
  "device": "compute_80 with 108 multiprocessors, cuBLAS 130101, cuDNN 91300, NVRTC 13.0, patterns on",
  "strict": false,
  "stacking": 1,
  "recompute": 10.99...,
  "convolutions": { ... },
  "node_gradients": null
}
flagvariablethe run's choices
nonenoneits own; a resume takes its checkpoint's
--choices <checkpoint>SEXPGPU_CHOICESthe ones that checkpoint recorded, <location>/step-<n>, o41:// included
--choices <file.json>SEXPGPU_CHOICESthe choices of a JSON file: an experiment.json, or the metadata of a lowering or choices annotation (a run's last holds every choice it made)
--choices freshSEXPGPU_CHOICES=freshits own, a resume too
--choices missingSEXPGPU_CHOICES=missingits checkpoint's, and its own for what they do not record
--deterministicSEXPGPU_DETERMINISTIC=1none measured: the last column of the table above

A pinned run measures nothing. It takes each recorded choice as it is, or stops before its first step with E-CHOICE-001 naming the choice it cannot take: a stacking whose plan does not fit or is not offered, a cuDNN engine this version cannot use on this device or a convolution the record has none for, or gradients between nodes in another dtype than SEXPGPU_NODE_GRADIENTS says. It never falls back to another choice. --choices fresh chooses again instead of pinning the record.

--choices missing is the way past a choice the record has none for: a graph the record's run never planned, a pass added since, or a convolution at another batch size. The run takes every choice the checkpoint records, as a resume does, and chooses the ones it lacks as a fresh run would. A recorded choice this device cannot take still stops it with E-CHOICE-001. The determinism line names the graphs that chose fresh and the record used for the rest. The lowering report has a fresh line for each such graph, with what it chose, and one that counts them. Its checkpoints record both, so a later resume pins them all. With no checkpoint to take choices from, or one that recorded none, it chooses everything, as a run without --choices does.

A resume pins itself to its checkpoint's choices. A checkpoint with no choices recorded resumes by choosing. The determinism line names whether the record's device facts match this machine's. Matching facts reduce sources of variation; they do not guarantee identical results.

--deterministic gives up the stacking and the engines a measurement would pick, so it is slower. It refuses --choices <record> and SEXPGPU_NODE_GRADIENTS=bf16 with E-CHOICE-002.

A time budget stops a run between complete steps, so how many steps a timed run takes depends on the wall clock. Its checkpoint holds complete steps and can be resumed; neither timing nor resume guarantees the results of an uninterrupted run.

Offline evaluation

sexpgpu evaluate runs a run's passes from its checkpoints, often on another machine. A pass runs unstacked, so the choices that move its bits are the recompute budget, the convolution engines and the CUDA product implementations:

  • On the kind of device the checkpoint's choices were made on, it takes them. Compare its eval/* values with inline evaluation within numerical tolerance.
  • On another kind, it chooses its own, measured as a run does.
  • --choices and --deterministic replace either, as for a run. A pinned convolution or CUDA product whose shape has no recorded choice stops with E-CHOICE-001; a shape shared with training reuses its recorded implementation. --choices fresh chooses every shape.
  • --choices missing fills gaps: on the kind of device the choices were made on, it chooses only the unrecorded shapes and pins the rest; on another kind it chooses every shape.

The determinism line of its lowering report and the evaluated offline on <device>: determinism <level> annotation describe the choice provenance using the numeric codes above. They do not promise identical bits or identical inline and offline values.

What the device decides

The rest of the lowering depends on the machine and its libraries. cuBLAS picks its kernels from the GPU and its version, cuDNN its plans, NVRTC the generated kernels' math functions, and NCCL the sum between GPUs from the topology. So the recorded device names the compute capability, multiprocessor count, cuBLAS, cuDNN and NVRTC, with GPU and node counts appended when there are several. Reusing recorded choices does not fix every source of numerical variation.

What the run's configuration decides

These are part of the run, not the machine, and change its bits by design: the GPU count and the node count (each rank sums its own microbatches, NCCL sums across ranks), and the diagnostics selection, whose sampled steps run the diagnosed graph for their first microbatch.

Generator exits

A generator's :until reads the state, so rounding can move a row's flag across its threshold and stop the batch at another trip. The state at an exit is the state the same trips give without :until in that execution. A different exit can change what the generator makes, the pass's metrics, and in training the loss and every later step. runtime/generate_trips shows where a step's or a pass's batches stopped.

Random draws

A draw holds no state. Each element of normal or uniform is a pure function of the draw's stream key, its salt when it has one, and the element's index (tensors). An unnamed stream is keyed by the draw's place alone, a parameter's path or its graph and position, a named one by its name, and either is mixed with defrun :seed. The key does not depend on the machine, device, stacking or kernel execution order. For a fixed key and index, the interpreter and CUDA map a uniform to the same bits; a normal can differ in the last ulp of the device's ln, cos and sqrt. This identity of the uniform mapping does not guarantee reproduction of a run's bits.

A salt picks another stream and nothing else. Nothing about a draw is in a checkpoint, and none needs to be: a resume reconstructs the stream keys, because :step comes back from the checkpoint and :microbatch counts from zero in every step. That holds while the resumed run keeps the microbatch count and the number of GPUs, since a salt that reads :microbatch draws for the global microbatch index. A graph whose salt reads a field is not stacked, so its separate calls use their own keys. The directions of a forward-query run are draws of the same kind, keyed by each parameter's path and salted by the step and the microbatch.

What does change a draw: another :seed, another salt, another path for a parameter's initializer, and in any other graph another unnamed draw added before it, which renumbers the keys after it.

Named draws

A draw written with :stream is keyed by its kind (normal or uniform), its name and its shape, not its place, and then by its salt, its scan index and defrun :seed as any draw is. So it is the same in every graph that makes it: another pass name, another graph, draws added or removed around it, a refactored function. It is not mixed with the step, the microbatch, the rank, the trip or the batch's items: only its salt moves it, so a draw that should change every step or every trip reads those in its salt, and element i of a draw is element i of the batch it is laid over, whatever item is there. Inside a scan the draw still varies with the index, and the same index in another graph's scan draws the same values. Recomputation in a gradient sweep keeps its key, and a draw has no derivative.

Paired draws make paired inputs, not paired results: the interpreter and every device draw a named uniform to the same bits, and a normal to the last ulp of the device's ln, cos and sqrt, but what two passes compute around it still follows the rest of this page.

Loaded weights

A :load parameter's starting value comes from a file. Keeping its bytes unchanged preserves that input to the run; it does not guarantee identical results. Each checkpoint's experiment.json pins it: the file read (the shard, for an index), the tensor, and the file's size and version, its ETag on S3 or the SHA-256 of a local file. A resume reads the file again and stops with E-LOAD-001, showing both, when the tensor, size or version differ; the same bytes at another path, a bundle's copy, resume and are named in the resumed from annotation. A fresh run reads whatever is at the path, so never write over a source you mean to reproduce: put a new version under a new name. See checkpoints.

Related: devices, precision and numerics, checkpoints, explain.