RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Whitepapers · Riptide · Exact training

Training that gives the same weights on every machine

Train the same model with the same seed on a GPU and on a CPU, and stock PyTorch ends with different weights. This paper shows training that ends with the same weights, to the bit, on two NVIDIA GPU models and three CPU families, at the same accuracy as stock, and measures what each replacement of exp, log, tanh and the roots in training costs.

Version
1.3 (updated 1 December 2026: added Method section; limitations section retitled; added "Reproduce it yourself")
Date
1 December 2026
Author
Samario Torres, Riptide
Software
PyTorch 2.13.0 (cu129 on GPUs, TF32 off for float32) with Riptide's exact-training prototype on top; Triton (attention kernels); Riptorch 0.4.x branch build for the Riptorch section
Download PDFOpen in new tabriptidecompute.com/whitepapers/bit-identical-training

Abstract

A model trained on one machine should be the model you get on another. With stock PyTorch it is not: on 1 December 2026 the same four models, with the same seed, the same initial weights and the same batches, ended with 6 or 7 different sets of final weights over 7 runs: one per machine, and a different one on the same Xeon at 1 thread and at 16.

Riptide's exact training mode gives one SHA-256 of the final weights on an RTX 4090, an H100 SXM, an Intel Xeon 8488C, an AMD EPYC 9R14 and an AWS Graviton4, for all four models (an MLP, a CNN, a 3.2M-parameter GPT and an LSTM), and keeps the standard maths: softmax, cross-entropy, GELU, LayerNorm and Adam. Accuracy is the same as stock: GPT 1.5282 ± 0.0032 nats per character against 1.5279 ± 0.0057, CNN 77.52% against 77.35%, MLP 98.41% against 98.41%. A fully rational version, with no transcendental functions, is bit-identical too, at an accuracy cost on the language model.

The cause of the disagreement is measurable. Once matrix products and sums are exact, the remaining difference between machines is the library's transcendental functions: over fixed inputs, exp, log and tanh each give 4 different float32 results across 5 devices. Riptide's device-independent versions give one result everywhere, and its exp is more accurate than CUDA's (1.2 against 1.86 units in the last place).

Removing transcendentals does not make training faster at these sizes. Compiled, an exp, a rational function and a plain multiply all run at the memory-copy speed, so each single replacement lands at 0.92–1.05× of the same step without it. The exact mode itself is much slower today, which the section "Limitations and next steps" sets out.

What this lets you do

  • Train once, reproduce anywhere. A run on a laptop CPU, a cloud Arm instance and an NVIDIA GPU ends in the same weights, so a result can be audited, a regression bisected and a model rebuilt from its seed on whatever hardware is available.
  • Keep the model you already have. The bit-identical mode keeps stock maths and stock accuracy on all four models; nothing in the architecture or the hyperparameters changed.
  • Know where your training differs. The map below shows which functions in a forward and backward pass are transcendental, how much of the step they take, and which of them actually differ between machines.

Where the transcendentals are

Only three places in backpropagation evaluate a transcendental function again; the rest of the backward pass is already arithmetic on values saved from the forward pass.

Table 1. Every transcendental in a training step, forward and backward.
functionwhereforwardbackward
attention softmaxevery transformer layerexp per scoreexp again: fused attention recomputes the probabilities
GELU (erf or tanh form)transformer MLPerf or tanhagain: the GELU gradient evaluates exp or tanh
SiLU / SwishLlama-style MLPssigmoidagain: the SiLU gradient recomputes the sigmoid
sigmoid / tanh gatesLSTM, GRUexp per gatenone: from the saved outputs
softmax + cross-entropyclassifiers, language-model headexp and logexp again; the log never reaches a gradient
LayerNorm, RMSNorm, BatchNormevery blockone 1/√ per rownone: the saved value is reused
Adam / AdamWevery parameter, every step√ of the second moment(optimiser)

In the GPT that is about 85 million transcendental evaluations against about floating-point operations per step (0.05%). Yet the kernels that contain them take 45% of the GPU kernel time on the RTX 4090 (compiled: LayerNorm 15.5%, GELU 15.4%, fused attention 9.7%, Adam 3.7%) and 33% on the H100. They are memory-bound, which is why replacing the function inside them changes almost nothing.

Method

This section describes the exact training mode at the level of the algorithm. The implementation, a prototype on stock PyTorch, is not published. Two rules make a step the same on every machine: every elementwise operation is a single IEEE operation (addition, subtraction, multiplication, division, comparison or integer bit operation), which every device rounds the same way; and every reduction is computed in integers, which add the same way in any order. Two sums are not integer sums: the backward pass of the image-patch convolution and the gradients of weights used more than once (the LSTM's 32 steps) are float additions in a fixed order, which is deterministic on every device but not exact. The model runs eagerly, so no compiler fuses a multiply and an add into one rounding step on one device and not on another.

Transcendental functions from additions and multiplications

  • exp. is reduced to with and , where is split into a high part with few significant bits and a low correction, so that times the high part is exact (Cody and Waite's reduction). Then , and is its Taylor polynomial evaluated by Horner's rule, degree 7 in float32 and 13 in float64 (truncation error at most about relative in float32). is built directly from the integer bits of the floating-point exponent field. Inputs are clamped to the representable range first.
  • expm1, tanh, sigmoid. uses its own Taylor polynomial for , where subtracting 1 would lose digits, and exp otherwise. with , with the sign of restored. The sigmoid is for and otherwise, so the exponential never overflows. GELU uses the standard tanh form built from these.
  • Reciprocal square root. starts from the integer bit-pattern estimate (the constant 0x5F3759DF for float32) and takes 3 Newton steps in float32, 5 in float64. This replaces the library roots in LayerNorm, BatchNorm and Adam, which are not correctly rounded on every CPU.
  • The log appears only in the reported loss value. The cross-entropy gradient is computed directly as from the softmax probabilities, so the log never enters training.

Exact matrix products

Every matrix product (linear layers, convolutions as matrix products, and the two attention products) runs on integers, in the forward pass and in both gradient products.

  1. Power-of-two scales. Each operand is scaled per row or per column, along the dimension the product sums over, by a power of two chosen from its largest element so that the largest value lands just below (int8) or (int16); values are then clipped to or , the int16 limit that two int8 limbs can hold. Scaling by a power of two is exact; the losses are the rounding to integers and, for the largest elements, that clip. The headline exact mode (int16) rounds to nearest everywhere.
  2. Stochastic rounding without a device random generator. In the int8 variants, the incoming gradient (not the saved activations or weights) is rounded down after adding a uniform number from a counter-based integer hash of the element's index and a seed, computed with 64-bit integer operations only. The same element gets the same random number on every device.
  3. Integer products. int8 products use the vendor int8 matrix product with int32 accumulation, which is exact. An int16 value is split into two int8 limbs, , with and ; the four limb products are combined as in float64, which is exact because every value stays below . The int32 accumulation is exact while (about 133,000 terms); the CNN's weight gradient sums over 262,144 terms, past that bound in the worst case, and the code does not check it. Batched attention products use float32 products of int8-valued operands, which are exact while for int8, and () for int16 limbs; the runs here have .
  4. Back to floating point. The exact integer result is multiplied by the product of the two power-of-two scales.

Exact sums

Every reduction in the step (bias, gain and embedding gradients, softmax denominators, normalisation statistics, losses) is an exact fixed-point sum: all elements are multiplied by one power of two, chosen from the largest magnitude and the number of terms so the total stays below , rounded once to 64-bit integers, added as integers (exact and independent of order, including atomic additions on a GPU), and scaled back once. Embedding gradients are accumulated the same way with integer index-adds.

The rational variants

The different-function variants use odd rational fits of the form for tanh and for , the GELU form (maximum absolute errors 1.3 × 10⁻³ and 3.3 × 10⁻³), a second-order polynomial in place of exp in attention and at the output with the Brier score as the loss, mean absolute deviation in place of the standard deviation in the norms, and the mean of in place of Adam's root. They use no transcendental function and no root. Combined with exact integer products and sums (the fully rational exact mode) they are bit-identical too; on their own they are not. Their accuracy costs are in the results below.

Setup

Models

Table 2. The four models. The same initial weights (per parameter name and seed) and batches in every variant and on every machine.
modeldatatraining
MLP 784–1024–1024–10MNIST3 epochs, batch 128, Adam 1e-3
CNN: 3 × (3×3 conv, BatchNorm, ReLU, max-pool), 64/128/256 channelsCIFAR-10 with flips10 epochs, batch 256, AdamW 2e-3
Character GPT: 4 layers, width 256, 4 heads, context 128, GELU, pre-LayerNorm (3.2M parameters)TinyShakespeare2,000 steps, batch 64, AdamW 1e-3
LSTM, hidden 6432-step windows of 1-minute BTC features500 steps, MSE, Adam

Machines

RunPod: one GeForce RTX 4090 pod and three H100 SXM 80 GB pods. AWS EC2 us-west-2: c7i.4xlarge (Intel Xeon Platinum 8488C, Sapphire Rapids), c7a.4xlarge (AMD EPYC 9R14, Genoa) and c8g.4xlarge (AWS Graviton4). PyTorch 2.13.0 everywhere, CUDA 12.9 builds on the GPUs, TF32 off for float32.

Measures

  • Accuracy: final test accuracy, validation loss or MSE, mean ± standard deviation over 3 seeds, on the RTX 4090.
  • Speed: median step time from step 20 on, two runs per cell, eager and torch.compile (stock also max-autotune). Each replacement is compared with a hand-written control that is the same implementation with only that piece changed, and with stock's fastest mode on the same machine.
  • Bit identity: SHA-256 of the final weights after MLP 300, CNN 60, GPT 100 and LSTM 500 steps, seed 0.
  • Function error: fixed float32 inputs per function against float64, plus a hash of every output set per device.
  • Energy: GPU board power sampled every 100 ms times the median step time.

What was replaced

Each replacement is one of two kinds. A same-function replacement computes the same mathematical function in a way every device rounds identically. A different-function replacement swaps in another function (a rational activation, a polynomial softmax, an L1 norm). The exact mode also replaces float matrix products with exact integer ones and float reductions with exact sums.

Results

One set of weights on every machine

Grouped bars per model: stock PyTorch 6 or 7 distinct weight hashes, exact matrix products alone 4 or 5, both exact modes 1
Figure 1. Distinct SHA-256 hashes of the final weights over the runs on each machine.
Table 3. Distinct final-weight hashes / runs. Stock runs: RTX 4090, two H100 pods, Xeon at 16 threads and at 1 thread, EPYC, Graviton4.
modelstock PyTorchexact matrix products onlyexact, standard mathsexact, rational maths
MLP6 / 74 / 71 / 51 / 7
CNN7 / 75 / 61 / 51 / 6
GPT6 / 75 / 71 / 51 / 6
LSTM6 / 74 / 71 / 51 / 7

Stock PyTorch is repeatable on one machine (the two H100 pods agree) but not across machines, and not across thread counts on one CPU. Exact matrix products alone make the two GPU models agree; exact sums and device-independent functions bring the three CPU families in.

The library functions are what differ

Bars: library exp, tanh and log give 4 output sets over 5 devices, sigmoid and 1/sqrt 2, sqrt 3, GELU 3; Riptide's versions give 1 each
Figure 2. How many different float32 output sets each function gives over 5 devices.
Table 4. Largest error in float32 units in the last place (ulp) over inputs, and distinct output sets over 5 devices.
functionlibrary, NVIDIA GPUslibrary, CPUslibrary outputsRiptide device-independentRiptide outputs
exp1.860.56–0.9641.21
tanh1.810.51–1.042.751
sigmoid3.021.9922.311
1/√x1.51.4921.951
√x0.50.5–0.753——
log0.860.54–0.894——

Even torch.sqrt is not correctly rounded on the x86 CPUs measured: 0.554 ulp on the Xeon 8488C and 0.75 ulp on the EPYC 9R14, where IEEE 754 requires 0.5. That alone split a first exact version into three groups of machines, until the square root in normalisation and in Adam was replaced by a device-independent version.

What each replacement costs

Horizontal bars of the change in GPT validation loss per replacement: near zero for rational GELU, exact int8 with stochastic rounding and the exact standard-maths mode; +0.154 nats for polynomial plus Brier output
Figure 3. GPT validation loss change against stock, mean of 3 seeds.
Table 5. Accuracy against stock (RTX 4090, 3 seeds; "=" means within one standard deviation) and compiled step time against the hand-written control.
piecereplacementkindaccuracy vs stockstep vs control, RTX 4090 / H100
exp in softmax, cross-entropy, attentiondevice-independent expsame function= (GPT 1.5279 vs 1.5279)0.93 / 1.03
tanh, sigmoid (LSTM, GELU)device-independent tanh, sigmoidsame function=0.93 / 1.01
1/√ in LayerNorm, BatchNormdevice-independent 1/√xsame function=0.97 / 0.98
√ in Adamdevice-independent 1/√xsame functionGPT +0.004 nats, others =1.32 / 1.09
GELUrational functiondifferent= (GPT −0.001)0.92 / 0.97
GELU, LSTM gatespiecewise lineardifferentGPT +0.010, LSTM =—
LSTM gatesrational sigmoid and tanhdifferent=0.97 / 0.98
attention softmaxdifferentGPT +0.0081.01 / 1.01
attention softmaxbounded weightsdifferentGPT +0.0090.98 / 1.05
softmax + cross-entropy at the outputpolynomial + Brier loss (no exp, no log)differentMNIST =, CIFAR +0.18 pt, GPT +0.154 nats0.99 / 0.98
LayerNorm / BatchNormmean absolute deviationdifferentCIFAR +0.40 pt, GPT +0.0271.00 / 1.00
Adam's differentCIFAR +1.18 pt, MNIST =, GPT +0.0210.98 / 0.98
AdamLion (learning rate / 3, untuned)differentCIFAR +1.0 pt, MNIST −0.28, GPT +0.100.83 / 0.94
float32 matrix products, forward and both gradientsexact int8, stochastic roundinginteger= (CNN +0.04 pt, GPT +0.0001)5.7 / 3.9
sameexact int8, round to nearestintegerCNN −4.8 pt, GPT +0.0265.7 / 3.8
sameexact int16integer=9.7 / 5.5
everything, standard mathsexact modeexact= on all four modelseager only: 16.6 (RTX 4090 GPT)
everything, rational mathsexact mode, rational functions onlyexactMNIST =, CIFAR +0.8 pt, GPT +0.15eager only: 12.5 / 6.1

On the CIFAR CNN "+" is better (accuracy points); on the GPT "+" is worse (nats per character). The L1 norm and in Adam improve the CNN by 0.4 and 1.2 points and cost the GPT 0.027 and 0.021 nats. The Brier loss matches cross-entropy on MNIST and CIFAR but costs the language model 0.15 nats. Exact int8 matrix products train to stock accuracy on all four models with stochastic rounding; rounding gradients to nearest costs the CNN 4.8 points.

Validation loss curves of the GPT: stock and the exact standard-maths mode overlap; the rational mode settles near 1.67 nats; int8 round-to-nearest sits slightly above stock
Figure 4. GPT validation loss over training, seed 0.

Speed

Horizontal bars of compiled GPT step time over the control for each single replacement: 0.92 to 1.03 on both GPUs, except Adam's 1/sqrt at 1.32 and 1.09; stock's fused kernels at 0.71 and 0.78
Figure 5. Each single replacement, compiled, against the same step without it.
  • Elementwise functions are free once fused. At floats compiled, exp, the device-independent exp, a rational tanh and a multiply all take 0.63 ms on the RTX 4090 and 0.21 ms on the H100, the time of a copy. Uncompiled, a function built from basic arithmetic costs one kernel per operation (17.8 ms for the device-independent exp on the RTX 4090), so it needs compilation or a fused kernel.
  • Single replacements are noise. GPT on the RTX 4090: control 9.64 ms, replacements 8.85–9.92 ms; on the H100 13.78 ms against 12.97–15.07 ms. CPUs: within 1.03–1.15× of the control, compiled. The exception is the optimiser's 1/√x, which runs unfused per parameter (1.32× on the RTX 4090).
  • Stock's fused kernels are the real lever. Stock's best GPT step on the RTX 4090 is 6.88 ms, 0.71× of the hand-written control, from fused attention, LayerNorm, cross-entropy and Adam: kernel fusion, not maths.
  • Attention. In a Triton causal-attention kernel that differs only in exp against (bf16, gradients checked against float64), the forward is 4–11% faster on the H100 and 0.91–1.04× on the RTX 4090; forward plus backward is a wash. PyTorch's FlashAttention is 1.6–2.0× faster than both in the H100 forward. The exp is not what limits a kernel below that level.
  • Energy follows time. GPU board power is within a few percent for every float variant, so energy per step tracks step time. H100 GPT: stock compiled 2.8 J per step, control 3.7, rational GELU 3.6, all-rational 3.7, exact int8 11.7.
Bars at 16384 by 8192 by 8192: H100 float32 127 ms, TF32 23, bf16 11, exact int8 40, exact int16 131; RTX 4090 135, 78, 44, 87, 262
Figure 6. One large linear layer, forward and backward, quantisation included.

At large shapes exact int8 overtakes strict float32 (H100: 40.2 against 126.6 ms, 3.1× faster), but not TF32 (22.9 ms) or bf16 (11.0 ms).

Error against float64

Integer training rounds to an integer grid at different points than a float64 run, so the trajectories separate: the exact modes end 3.6e-3 to 9.6e-2 from their own float64 runs, against 2.7–3.7e-5 for stock on the GPT. The MLP and CNN separate even in float (stock MLP 3.9e-2 after 300 steps): Adam's per-coordinate normalisation turns one-ulp differences in tiny gradients into learning-rate-sized steps. Because the exact runs are equal on every device, their distance from float64 is one number, not one per machine.

What is known and what is new

Rational activations (Padé Activation Units; rational neural networks), polynomial and Taylor softmax, softmax-free and bounded attention, the Brier and spherical scores as losses, int8 training with stochastic rounding, L1 normalisation, AdaMax and Lion are all published. FlashAttention-4 already computes part of its exp with a polynomial, as a speed technique on Blackwell GPUs.

Not found in published work, as far as this check went:

  • the split into same-function and different-function replacements, measured one change at a time on four models with three seeds;
  • the backward-pass accounting above and its measured cost;
  • exact integer matrix products in all three training matrix products, the weight gradient included;
  • whole-run bit identity across NVIDIA GPU models and x86 and Arm CPU families at stock accuracy, with the measured reason that library transcendentals, and x86 torch.sqrt, are what differ once products and sums are exact.

Limitations and next steps

The limits of these results, each with its cause and, where one is planned, the next step.

  • The bit-identical mode is slow. It runs uncompiled today: on the RTX 4090 the GPT step takes 160 ms, 16.6× the hand-written control and 23× stock's best (6.88 ms). Cause: the exact pieces run as separate uncompiled operations rather than fused kernels, and the extra conversion kernels around the integer products, not the products themselves, dominate the cost.
  • Exact integer matrix products are slower on these models. 3.9–7.8× slower per step with int8 and 5.5–9.7× with int16. At large shapes int8 beats strict float32 but is 1.75× slower than TF32 and 3.6× slower than bf16 on the H100. Cause: same as above, at small sizes; at large sizes under investigation.
  • No speed gain from removing transcendentals. At these sizes on every device the functions run at memory speed, so replacing them saves nothing measurable; the attention forward gains 4–11% on the H100 only, and FlashAttention remains 1.6–2.0× faster. Cause: the kernels are memory-bound.
  • Riptorch's exact mode does not yet match CPU to GPU. With exact matrix products Riptorch gives one weights hash on the RTX 4090 and the H100, but the EPYC CPU gives another. Cause: Riptorch's CPU path does not yet have the exact sums and device-independent functions used in this paper. Its rational activations and optimiser are also far slower than its fused core operations (GPT 1.16 s per step against 21 ms), because they are composed in Python, not built into the core.
  • Small models only. The largest model here has 3.2M parameters. Earlier internal work found the rational recipes lose accuracy at 14M parameters; the standard-maths exact mode was not tested at that size.
  • Different-function costs. The polynomial + Brier output costs the language model 0.15 nats, and Lion at an untuned learning rate 0.10 nats. Cause: under investigation (no learning-rate tuning was done).

Reproduce it yourself

Run kits/bit-identical-training from the public riptide-reproduce repository: one command, a few minutes on a laptop, public software only. It reproduces the same seed and data trained with stock PyTorch, printing a final-weights hash per thread count and GPU so you can compare machines (the exact recipe ships in the next Riptorch release). Every baseline's value and its error against the exact answer are printed and saved to errors.csv, and the exact results print the same hash on every machine: if your float hash differs from ours or a colleague's, that is precision drift in your pipeline.

Reproduction notes

  • Software. The exact-training prototype runs on stock PyTorch 2.13.0 and is not published; Riptorch 0.4.0 is on the Riptorch page, and evaluation builds of the exact mode are available through Request an evaluation.
  • Records. Run no-transcendental-training-2026-12-01: one record per run (1,763 training runs and 34 Riptorch runs) with per-step medians, evaluation curves, weight hashes and configurations, plus per-function error files, profiles, machine records and GPU power logs. Evaluation partners can have the raw files on request.
  • Cost. About $35 of rented machine time: $17.47 on RunPod and about $17 on EC2.

References

  • Molina, Schramowski and Kersting, Padé Activation Units, ICLR 2020.
  • Boullé, Nakatsukasa and Townsend, Rational neural networks, NeurIPS 2020.
  • de Brébisson and Vincent, An exploration of softmax alternatives belonging to the spherical loss family, 2016.
  • Gneiting and Raftery, Strictly proper scoring rules, prediction, and estimation, JASA 2007.
  • Hui and Belkin, Evaluation of neural architectures trained with square loss vs cross-entropy, ICLR 2021.
  • Gupta, Agrawal, Gopalakrishnan and Narayanan, Deep learning with limited numerical precision, ICML 2015.
  • Hoffer, Banner, Golan and Soudry, Norm matters: efficient and accurate normalization schemes in deep networks, NeurIPS 2018.
  • Chen et al., Symbolic discovery of optimization algorithms (Lion), NeurIPS 2023.
  • Shah et al., FlashAttention-3, 2024; FlashAttention-4, 2025.
  • W. J. Cody and W. Waite, Software Manual for the Elementary Functions, Prentice-Hall, 1980.
  • C. Lomont, Fast inverse square root, technical report, Purdue University, 2003.

Date and version

Version 1.3, 1 December 2026. Measurements from 1 December 2026. Updated 1 December 2026: added Method section. Updated 1 December 2026: limitations section retitled. Updated 1 December 2026: added "Reproduce it yourself".

Working with Riptide

Riptide works with a small number of teams. Each engagement starts with 4 weeks inside your systems, learning how your models, data and infrastructure work. Only then does Riptide apply its software to them. Contact samario@riptidecompute.com or riptidecompute.com/evaluate.