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.
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.
| function | where | forward | backward |
|---|---|---|---|
| attention softmax | every transformer layer | exp per score | exp again: fused attention recomputes the probabilities |
| GELU (erf or tanh form) | transformer MLP | erf or tanh | again: the GELU gradient evaluates exp or tanh |
| SiLU / Swish | Llama-style MLPs | sigmoid | again: the SiLU gradient recomputes the sigmoid |
| sigmoid / tanh gates | LSTM, GRU | exp per gate | none: from the saved outputs |
| softmax + cross-entropy | classifiers, language-model head | exp and log | exp again; the log never reaches a gradient |
| LayerNorm, RMSNorm, BatchNorm | every block | one 1/√ per row | none: the saved value is reused |
| Adam / AdamW | every 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.
- 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.
- 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.
- 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 .
- 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
| model | data | training |
|---|---|---|
| MLP 784–1024–1024–10 | MNIST | 3 epochs, batch 128, Adam 1e-3 |
| CNN: 3 × (3×3 conv, BatchNorm, ReLU, max-pool), 64/128/256 channels | CIFAR-10 with flips | 10 epochs, batch 256, AdamW 2e-3 |
| Character GPT: 4 layers, width 256, 4 heads, context 128, GELU, pre-LayerNorm (3.2M parameters) | TinyShakespeare | 2,000 steps, batch 64, AdamW 1e-3 |
| LSTM, hidden 64 | 32-step windows of 1-minute BTC features | 500 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

| model | stock PyTorch | exact matrix products only | exact, standard maths | exact, rational maths |
|---|---|---|---|---|
| MLP | 6 / 7 | 4 / 7 | 1 / 5 | 1 / 7 |
| CNN | 7 / 7 | 5 / 6 | 1 / 5 | 1 / 6 |
| GPT | 6 / 7 | 5 / 7 | 1 / 5 | 1 / 6 |
| LSTM | 6 / 7 | 4 / 7 | 1 / 5 | 1 / 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

| function | library, NVIDIA GPUs | library, CPUs | library outputs | Riptide device-independent | Riptide outputs |
|---|---|---|---|---|---|
| exp | 1.86 | 0.56–0.96 | 4 | 1.2 | 1 |
| tanh | 1.81 | 0.51–1.0 | 4 | 2.75 | 1 |
| sigmoid | 3.02 | 1.99 | 2 | 2.31 | 1 |
| 1/√x | 1.5 | 1.49 | 2 | 1.95 | 1 |
| √x | 0.5 | 0.5–0.75 | 3 | — | — |
| log | 0.86 | 0.54–0.89 | 4 | — | — |
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

| piece | replacement | kind | accuracy vs stock | step vs control, RTX 4090 / H100 |
|---|---|---|---|---|
| exp in softmax, cross-entropy, attention | device-independent exp | same function | = (GPT 1.5279 vs 1.5279) | 0.93 / 1.03 |
| tanh, sigmoid (LSTM, GELU) | device-independent tanh, sigmoid | same function | = | 0.93 / 1.01 |
| 1/√ in LayerNorm, BatchNorm | device-independent 1/√x | same function | = | 0.97 / 0.98 |
| √ in Adam | device-independent 1/√x | same function | GPT +0.004 nats, others = | 1.32 / 1.09 |
| GELU | rational function | different | = (GPT −0.001) | 0.92 / 0.97 |
| GELU, LSTM gates | piecewise linear | different | GPT +0.010, LSTM = | — |
| LSTM gates | rational sigmoid and tanh | different | = | 0.97 / 0.98 |
| attention softmax | different | GPT +0.008 | 1.01 / 1.01 | |
| attention softmax | bounded weights | different | GPT +0.009 | 0.98 / 1.05 |
| softmax + cross-entropy at the output | polynomial + Brier loss (no exp, no log) | different | MNIST =, CIFAR +0.18 pt, GPT +0.154 nats | 0.99 / 0.98 |
| LayerNorm / BatchNorm | mean absolute deviation | different | CIFAR +0.40 pt, GPT +0.027 | 1.00 / 1.00 |
| Adam's | different | CIFAR +1.18 pt, MNIST =, GPT +0.021 | 0.98 / 0.98 | |
| Adam | Lion (learning rate / 3, untuned) | different | CIFAR +1.0 pt, MNIST −0.28, GPT +0.10 | 0.83 / 0.94 |
| float32 matrix products, forward and both gradients | exact int8, stochastic rounding | integer | = (CNN +0.04 pt, GPT +0.0001) | 5.7 / 3.9 |
| same | exact int8, round to nearest | integer | CNN −4.8 pt, GPT +0.026 | 5.7 / 3.8 |
| same | exact int16 | integer | = | 9.7 / 5.5 |
| everything, standard maths | exact mode | exact | = on all four models | eager only: 16.6 (RTX 4090 GPT) |
| everything, rational maths | exact mode, rational functions only | exact | MNIST =, CIFAR +0.8 pt, GPT +0.15 | eager 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.

Speed

- 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.

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.