RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Whitepapers · Riptide · Reinforcement learning

Reinforcement learning, exactly: one set of weights on every machine

A reinforcement-learning result that changes when it moves to another GPU is hard to validate, audit or reproduce. This paper measures what it costs to train a policy that ends with exactly the same weights on any machine, against the fastest public ways to train the same policy.

Version
1.1
Date
2 December 2026
Author
Samario Torres, Riptide
Software
PyTorch 2.15.0+cu132 (CUDA 13.2; 2.15.0+cpu on Graviton4); JAX 0.12.1 (jax[cuda12]) with optax 0.2.9; NVIDIA driver 620.70.06; Riptide's exact environment and exact learner (not published)
Download PDFOpen in new tabriptidecompute.com/whitepapers/exact-rl-market-making

Abstract

On 1–2 December 2026 Riptide trained a market-making policy with proximal policy optimisation (PPO) six ways on AWS: Riptide's exact pipeline end to end; Riptide's exact environment with a compiled PyTorch learner; JAX with the environment and the whole PPO update compiled into one program (the PureJaxRL layout); PyTorch eager; PyTorch with torch.compile (max-autotune, CUDA graphs); and the CleanRL layout (environment on the CPU, PPO on the GPU). The task, network, hyperparameters and number of environment steps were the same for all. The order book is held as integer ticks and lots, and every random draw in the exact environment comes from a counter-based hash, so a rollout is the same bits on any device.

Same weights everywhere. With the same seed, the exact pipeline ended with the same final-weights SHA-256 on three GPUs (NVIDIA L4, A10G, H100) and on the CPUs of four machines (AWS Graviton4, AMD EPYC 7R32, AMD EPYC 7R13 twice): 1 distinct result on 7 devices. The same exact environment with an fp32 eager learner gave 6, and JAX 5. Three full 60-update exact runs, on the L4, A10G and H100, ended with identical weights (maximum absolute difference 0) and the same final return, 183.7; per-update fingerprints show the L4 and A10G rollouts identical for all 60 updates. The stock stacks did not: their rollouts differed between the A10G and the L4 from update 0 (PyTorch eager and torch.compile), update 1 (JAX) or update 2 (JAX with XLA's deterministic GPU ops), and the same seed's final return spread 39.3 across the three GPUs with PyTorch eager, 14.6 with torch.compile and 7.7 with JAX. Run twice on one GPU, PyTorch eager and JAX with deterministic ops reproduced themselves exactly; JAX with default settings and torch.compile (max-autotune) did not.

The price is speed. The exact pipeline ran at 67k, 86k and 147k environment steps per second on the L4, A10G and H100. JAX ran at 5.76M, 8.04M and 26.82M (85–182× faster), torch.compile at 3.37M–4.82M and PyTorch eager at 1.23M–1.51M. JAX with XLA's deterministic GPU ops ran at 0.70–0.74× of default JAX (5.63M on the A10G, 4.26M on the L4), still 63–65× the exact pipeline (1 December exact speeds). Combining the exact environment with a compiled PyTorch learner ran at 2.89M–4.00M, 83–86% of torch.compile, but it is not reproducible across GPUs: the compiled learner's action probabilities differ in the last bits by GPU, so the rollouts diverged in the first update and the final return spread 82.0 across the three GPUs. Every full-length run reached the target return of −1,000 in 8.4M–18.9M environment steps.

What this lets you do

  • Reproduce a reinforcement-learning run bit for bit on whatever machine is available, CPU or GPU, and re-run a published policy to its exact weights: on the seven devices tested here, one result.
  • Separate a real improvement from device noise. With the stock stacks the same seed moved the final return by up to 39.3 between GPUs, 46–79% of the difference between two seeds (49.5–85.1 for PyTorch eager); with the exact pipeline that term is zero.
  • Use the exact environment on its own as a market that gives the same order flow and noise for the same actions on any device, at 72–86% of the compiled float environment's speed. On its own it does not make training reproducible: the learner has to be exact too.

Results

Speed

Bar chart, log scale: environment steps per second during training on NVIDIA L4, A10G and H100. JAX is highest (5.76M, 8.04M, 26.82M), then torch.compile (3.37M, 3.79M, 4.82M), Riptide exact env with a compiled learner (2.89M, 3.23M, 4.00M), PyTorch eager (1.31M, 1.23M, 1.51M) and Riptide exact end to end (67k, 86k, 147k).
Figure 1. Training throughput, median over 60 updates, seed 1.
Table 1. Median environment steps per second over 60 updates (524,288 environment steps per update), seed 1; update 0 (which includes any compile) is excluded for every method. The CleanRL layout ran 4 updates for throughput only. JAX with XLA's deterministic GPU ops: 5,626,057 (A10G) and 4,258,256 (L4); no H100 capacity for that rerun.
MethodNVIDIA L4NVIDIA A10GNVIDIA H100
JAX, environment and PPO in one jit5,763,9698,036,77826,817,357
PyTorch fp32, torch.compile max-autotune + CUDA graphs3,372,4563,786,1844,823,710
Riptide exact environment + compiled PyTorch learner2,891,6103,230,7653,999,751
PyTorch fp32, eager1,306,6471,225,5661,507,433
CleanRL layout (environment on the CPU)800,680525,539568,288
Riptide exact, end to end67,42086,363147,075
Table 2. Return and cost, seed 1. Return: mean episode return over the last three logged episodes (higher is better; a random policy scores about −2,200 to −2,300). Steps to target: first logged episode with mean return ≥ −1,000. Cost: steady state for every method, 60 updates at the median update time × price (L4 $0.805/h, A10G $1.006/h on demand; H100 one eighth of the p5.48xlarge spot price, $31.15/h); compile time is excluded for all (torch.compile's first-run compile took 19–94 s, JAX's 5–24 s).
MethodFinal return L4 / A10G / H100Env steps to −1,000 (millions) L4 / A10G / H100$ per 60-update run L4 / A10G / H100
JAX214.6 / 207.0 / 207.810.5 / 10.5 / 12.60.0012 / 0.0011 / 0.0013
PyTorch torch.compile195.6 / 210.2 / 204.414.7 / 12.6 / 14.70.0021 / 0.0023 / 0.0071
Riptide exact env + compiled learner214.5 / 190.9 / 132.612.6 / 14.7 / 18.90.0024 / 0.0027 / 0.0085
PyTorch eager171.5 / 163.8 / 203.114.7 / 16.8 / 14.70.0054 / 0.0072 / 0.0226
Riptide exact183.7 / 183.7 / 183.716.8 / 16.8 / 16.80.1043 / 0.1018 / 0.2313

With a second seed the exact pipeline reached −1,000 in 8.4M steps (A10G) and PyTorch eager in 8.4M–10.5M: the spread between seeds is larger than the spread between methods.

What each run returned: errors against reruns, seeds, devices and the exact run

Bar chart: distinct final-weight hashes over seven devices for the same seed and code: Riptide exact 1 of 7, Riptide exact environment with a PyTorch fp32 eager learner 6 of 7, JAX 5 of 7.
Figure 2. Small configuration: 1,024 environments, 6 updates, seed 1, on three GPUs and the CPUs of four machines.
Table 3. Full-length runs (60 updates, seed 1): the final weights and returns compared. "Max abs weight difference" is the largest difference between corresponding parameters. "Rollouts" gives the first update whose rollout (observations, actions, rewards) or mid-episode environment state differs, from per-update fingerprints (A10G and L4 reruns of 2 December; "never" = identical for all 60 updates).
ComparisonWeights identicalMax abs weight differenceFinal-return differenceRollouts
Riptide exact: L4 vs A10G vs H100yes (all three)00never differ (L4 vs A10G)
PyTorch eager: same GPU, run twiceyes (each GPU)00never differ
JAX, default XLA: same GPU, run twiceno (each GPU)0.056–0.229 (1 Dec runs 0.056–0.068; 2 Dec reruns up to 0.229 on the L4)−11.4 to +5.0 (both days)differ from update 7 (A10G), 3 (L4)
JAX, deterministic XLA ops: same GPU, run twiceyes (A10G, L4)00never differ
PyTorch torch.compile: same GPU, two runs a day apartno (A10G, L4)0.017–0.077+0.6 to +0.7not compared (first run had no fingerprints)
PyTorch eager: across the three GPUsno0.13–0.17up to 39.3differ from update 0
PyTorch torch.compile: across the three GPUsno0.18–0.21up to 14.6differ from update 0
JAX: across the three GPUsno0.10–0.21up to 7.7differ from update 1 (deterministic ops: update 2)
Riptide exact env + compiled learner: across the three GPUsno0.16–0.17up to 82.0differ from update 0
Each other method vs Riptide exact, same seed and GPUno0.11–1.44−51.1 to +31.0 (stock methods only: −19.8 to +31.0)not compared (different environments or learners)
Table 4. Small configuration (1,024 environments, 6 updates, seed 1): distinct final-weight hashes over the same seven devices. CPUs: AWS Graviton4 (c8g.2xlarge), AMD EPYC 7R32 (the A10G machine), AMD EPYC 7R13 (the L4 and H100 machines).
MethodDistinct results on 7 devicesWhich devices agree
Riptide exact1all seven
Riptide exact environment + PyTorch fp32 eager learner6only the CPUs of the A10G and L4 machines
JAX5the CPUs of the A10G, L4 and H100 machines (all AMD EPYC)

The exact environment alone gives the same market for the same actions: driven by a fixed action sequence, its 256-step rollout hash was the same on all seven devices, eager or compiled. In training, the actions come from the learner. With a compiled float learner, the action probabilities differ in the last bits between GPUs, the integer action draw picks a different action for some environments in the first rollout, and from then on the rollouts, the environment states and the weights all differ: the final return spread 82.0 between GPUs for the same seed. Bit-identical results need both halves exact.

What each piece contributed

Table 5. Ablation, NVIDIA A10G unless noted. Environment speeds are environment-only steps per second at 4,096 environments; learner rows are training runs on the exact environment, read at update 20 (the int16 row's speed is the median of the 60-update exact run, and its return is that run at update 20).
PieceMeasuredEffect
Integer environment vs float32 environmenteager 624,163 vs 1,788,284 (0.35×); torch.compile 5,443,869 vs 7,428,908 (0.73×); H100, 65,536 envs, compiled: 97.5M vs 130.0M (0.75×)the same market for the same actions on 7 devices, compile on or off
Exact int16 learner vs PyTorch fp32 learner86,363 vs 534,655 steps/s (0.16×); return at update 20 −1,267 vs −1,252weights identical on 7 devices; learns at the same pace
Exact int8 learner120,104 steps/s; return at update 20 −2,240does not learn at this precision
bf16 autocast learner531,014 vs 534,655 steps/s; return −1,161no speed gain at this network size
CPU vs GPU environmentat 64 envs: CPU 27k–39k, GPU eager 10k–12k, GPU compiled 86k–100k steps/sthe compiled GPU environment is faster from 64 environments up
Float bookkeeping of P&L (dollars, tick $0.01)float32 and float64 right to the cent on 100% of 4,186,112 steps, every deviceat these sizes the exact environment's gain is reproducibility, not reward accuracy

Method

Environment. One instrument, 32 price levels per side. Each side of the book is a polynumber whose coefficient is the resting lots ticks from the mid. Each step: four limit orders per side arrive at distances drawn from a fixed table and add 1–4 lots (); resting volume decays by ; one market buy and one market sell of 0–7 lots walk their sides from the touch (the new side is the difference of the clipped cumulative sums ); the agent's one-lot quote at distance , queued behind the resting volume there, fills when ; the mid moves one tick when the order-flow imbalance plus a noise in reaches ±4, which shifts both polynumbers by one level (multiplying or dividing by ). The reward is the change in mark-to-market, cash plus inventory times mid, minus . Everything is an integer. The observation is 16 small integers (inventory, cumulative depth at 1, 2, 4, 8 and 16 ticks on each side, the imbalance at 8 ticks, the last three mid moves, time), scaled by a power of two into float32, which is exact. The market-making setting follows Avellaneda and Stoikov [1].

Random numbers. Every draw is a counter-based hash of (seed, environment index, step, stream), as in counter-based generators such as Philox [2]: a fixed 32-bit avalanche (xor-shift and multiply) applied in 64-bit integer arithmetic whose every product stays below . A draw does not depend on the batch size, the device or the order of evaluation. Actions are sampled from the policy's probabilities converted to -scaled integers: the integer cumulative sum is compared with for a hashed . Minibatch order is the argsort of unique integer keys (hash × + index).

Exact learner. The bit-identical-training recipe of "Training that gives the same weights on every machine" applied to PPO [3, 4]. Every matrix product is an int16 product: each operand is scaled by a power of two per row or column to at most 32,512, split into two int8 limbs, the four limb products are computed with exact int32 accumulation and recombined in float64 (exact below ), then rescaled once. Activations and softmax use multiply-add-only tanh and exp (Cody–Waite reduction and a Horner polynomial [5]); reductions (softmax denominators, loss means, advantage normalisation, the gradient norm) are exact int64 fixed-point sums; Adam's square root is a bit-trick seed with Newton steps [6]. The model runs eagerly, so each elementwise operation is one IEEE operation on every device.

One device-dependent operation. The first exact runs gave the same weights on every CPU but differed on two GPUs by up to . Hashing every stage of one update on both devices located the first difference in the Adam step: on the GPU, PyTorch divides a tensor by a Python scalar by multiplying by the scalar's reciprocal, one more rounding than the CPU's true division. Dividing by a tensor filled with the scalar makes both devices perform the same IEEE division; after that change all seven devices gave one result.

Baselines. JAX follows the PureJaxRL layout [7]: environment step, rollout (lax.scan), GAE, epochs and minibatches compiled into one jax.jit program, vmap over environments, optax Adam with global-norm clipping; its environment holds the book as int32 with jax.random keys and float32 cash. The PyTorch baselines are a CleanRL-style PPO [8] with the same float32 dynamics and torch's random-number generator, run eagerly, with torch.compile (mode="max-autotune", CUDA graphs on the acting step; environment step compiled too), and with the environment on the CPU and the learner on the GPU (the CleanRL layout). TF32 was off for all PyTorch runs. JAX ran with default XLA settings and, in a rerun on the A10G and L4, with XLA_FLAGS="--xla_gpu_exclude_nondeterministic_ops=true --xla_gpu_deterministic_ops=true".

Setup

  • Machines: AWS EC2 us-east-1: g6.xlarge (NVIDIA L4, AMD EPYC 7R13), g5.xlarge (NVIDIA A10G, AMD EPYC 7R32), p5.48xlarge spot (NVIDIA H100 80GB HBM3, AMD EPYC 7R13; one GPU per job group), c8g.2xlarge (AWS Graviton4). Ubuntu 24.04; NVIDIA driver 620.70.06.
  • Software: PyTorch 2.15.0+cu132 (CUDA 13.2) on the GPU machines, 2.15.0+cpu on Graviton4; JAX 0.12.1 (jax[cuda12]) with optax 0.2.9.
  • Task and PPO settings (all methods): 4,096 environments × 128 steps per update (524,288 environment steps), 60 updates (31.5M steps); 512-step episodes; 25 actions (bid and ask distance 1–5 ticks); inventory limit ±20 lots; 4 epochs × 4 minibatches; Adam, learning rate , ; , ; clip 0.2; value coefficient 0.5; entropy coefficient 0; gradient-norm clip 0.5; separate actor and critic networks 16-64-64-out with tanh. The PyTorch runs share the same initial weights (generated from the hash); JAX uses its own initialiser with the same scales.
  • Reproducibility runs: 1,024 environments, 6 updates, seed 1, on every GPU and on each machine's CPU.
  • Measured: steps per second per update (median, update 0 excluded); mean episode return at each episode end (every 4 updates); the SHA-256 of the final weights and of the first rollout; in the 2 December reruns, a per-update 64-bit fingerprint of the rollout and of the environment state at mid-rollout (integer arithmetic mod on the device, so independent of reduction order); and, for every pair of runs compared, the maximum absolute weight difference. The final environment state is not used: 60 updates of 128 steps end exactly at an episode boundary, where every book has just been reset. The raw per-update values and the final weights of every run are kept.
  • Cost: about $28 of AWS time for the whole campaign, including reruns ($0.91 for the 2 December divergence check).

Limitations and next steps

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

  • Training throughput: 0.011–0.012× of JAX on the L4 and A10G and 0.0055× on the H100; 0.05–0.10× of PyTorch eager. Cause: the exact learner runs as many small eager operations per minibatch (quantise, four limb products, rescale, polynomial tanh and exp, exact sums), and keeping each elementwise operation a single IEEE operation rules out fusing the float parts. Next step: fused exact kernels that perform the same IEEE operations in the same order, and the whole update in one compiled program.
  • The exact environment: 0.72–0.86× of the compiled float environment at 4,096 environments (0.75× at 65,536 on the H100). Cause: 64-bit integer state and the hash draws cost more than float32 state and the device generator.
  • torch.compile was not reproducible run to run here. Two max-autotune runs a day apart on the same GPU ended with different weights (A10G and L4), while eager PyTorch reproduced itself. Cause: not established; max-autotune benchmarks candidate kernels on each run and can pick different ones. Next step: per-update fingerprints across two same-day torch.compile runs.
  • int8 learning fails. The exact int8 learner did not improve on the random policy in 20 updates, while int16 learned at the same pace as float32. Cause: int8 keeps 7 bits of each weight and activation after per-row scaling, too coarse for the small PPO updates (which change weights by far less than one int8 step); this is our reading of the result, not yet measured directly. Next step: measure the update-to-step ratio, and try int8 forward with int16 gradients.
  • One task and small networks. One market-making environment and 64-wide networks. Cause: the campaign was sized to fit one day and a $40 budget (about $28 spent). Next step: larger networks, where integer tensor-core products could pay off, and a second environment.
  • Not all baselines and GPUs. EnvPool [9] was not run, no L40S, B200 or deterministic-JAX H100 run was made, and the CleanRL layout ran 4 updates for throughput only. Cause: EnvPool needs the environment written in C++; AWS had no L40S or H100 capacity when the runs were made, and B200 is offered only as an 8-GPU instance; the CleanRL layout was kept to a throughput check to save time. Next step: a C++ port of the environment for EnvPool, and the missing GPUs when capacity allows.
  • The Raya compiler did not contribute. Cause: the environment's inner loops are prefix sums, scatters and shifts, which are not loop shapes the compiler's kernels recognise.
  • CPU and GPU routing changed nothing here. Cause: the compiled GPU environment was faster than the CPU from 64 environments up, so only very small batches would go to the CPU.

References

  1. M. Avellaneda and S. Stoikov, "High-frequency trading in a limit order book", Quantitative Finance 8(3), 2008, 217–224. doi:10.1080/14697680701381228
  2. J. K. Salmon, M. A. Moraes, R. O. Dror and D. E. Shaw, "Parallel random numbers: as easy as 1, 2, 3", Proc. SC11, 2011. doi:10.1145/2063384.2063405
  3. J. Schulman, F. Wolski, P. Dhariwal, A. Radford and O. Klimov, "Proximal policy optimization algorithms", arXiv:1707.06347, 2017.
  4. J. Schulman, P. Moritz, S. Levine, M. Jordan and P. Abbeel, "High-dimensional continuous control using generalized advantage estimation", arXiv:1506.02438, 2015.
  5. W. J. Cody and W. Waite, Software Manual for the Elementary Functions, Prentice-Hall, 1980.
  6. C. Lomont, "Fast inverse square root", technical report, Purdue University, 2003.
  7. C. Lu, J. Kuba, A. Letcher, L. Metz, C. Schroeder de Witt and J. Foerster, "Discovered policy optimisation", Advances in Neural Information Processing Systems 35, 2022. arXiv:2210.05639
  8. S. Huang, R. F. J. Dossa, C. Ye, J. Braga, D. Chakraborty, K. Mehta and J. G. M. Araújo, "CleanRL: high-quality single-file implementations of deep reinforcement learning algorithms", Journal of Machine Learning Research 23(274), 2022, 1–18.
  9. J. Weng, M. Lin, S. Huang, B. Liu, D. Makoviichuk, V. Makoviychuk, Z. Liu, Y. Song, T. Luo, Y. Jiang, Z. Xu and S. Yan, "EnvPool: a highly parallel reinforcement learning environment execution engine", Advances in Neural Information Processing Systems 35, 2022. arXiv:2206.10558
  10. D. P. Kingma and J. Ba, "Adam: a method for stochastic optimization", arXiv:1412.6980, 2014.

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.

Date and version

Version 1.1, 2 December 2026. Version 1.1: per-update rollout fingerprints replace the final env-state hash (which cannot show divergence); the exact environment with a compiled learner is not reproducible across GPUs; JAX rerun with deterministic XLA ops; steady-state cost for every method.