Determinism as a contract#
The rule: model bytes are a function of the input, the config and the configured thread count. At a fixed thread count they are identical across runs and across CPU architectures. With u16 bins (a feature needs more than 256 bins, which requires max_bin > 256) they are also identical at any thread count; with u8 bins (every feature fits in 256 bins, always the case at the default max_bin of 255) the sparse nodes deeper in the tree reduce partial histograms in an order set by the thread count (parallelism and determinism). CI enforces the rule per commit by training a reference model serially and at eight threads on an arm64 Mac and an x86-64 Linux box and comparing file hashes.
The rule covers CPU training only, and GPU training promises less. GPU training adds each row's gradient and hessian into shared histogram cells with atomic adds (memory updates no other thread can interrupt), and the order of those adds depends on how the GPU schedules its threads. For its first year the same fit wrote different model bytes on every run: four repetitions of one cuda_depthwise fit at a single commit produced four different model hashes. The cells are now int64 fixed point, so the sum is the same integer in any order and a device fit is bit-identical to itself on one device and one build; the suite fits three times and compares bytes. The device plane still does not promise the rest of the CPU rule. A device fit can differ across devices and toolkits, because the gradient kernels use exp and log (transcendental functions) and fused multiply-adds (one rounding instead of two), and these round differently on different hardware and compilers. It also differs from the host fit, because the host sums histogram cells in float, not int64. In the tests, one tree grown on the host and on the device from the same gradients gives every row a value within an absolute 1e-4 of the other, and the release check on a 30-tree fit allows 1e-3 on predictions and 0.005 on R-squared.
A bit-exact contract turns "did this change alter behavior?" from a judgment call into a file comparison. The next two sections show bugs that comparison caught and changes it verified.
What the contract caught#
Compiler contraction across architectures. The cross-arch gate's first real catch: the same model trained to different bytes on arm64 and x86-64 (test pins 0.71719 vs 0.71725). The mappers were bit-identical; the divergence was clang fusing multiply-add into FMA on one architecture only. Fix: -ffp-contract=off on the host build, which stops that fusion. The flag moved interleaved five-repetition California fits of 2000 iterations by 0.002 s (1.736 s vs 1.738 s), within noise (decision 59). The contract is now the same model bytes on any host architecture.
A silent build-system fallback. Models differed between two supposedly identical builds; the cause was a missing OpenMP quietly downgrading to serial, which changes reduction order. A missing OpenMP is now a hard configure error (decision 60).
What the contract enables#
Refactoring with proof. A cleanup merged the three hand-written copies of the numerically sensitive softmax code into one helper (commit b9f016b8, 2026-07-13). Acceptance was not review confidence; it was np.array_equal against outputs captured before the change, and it passed.
Features that provably cost nothing when off. New per-row weighting leaves the unweighted path's arithmetic unchanged: most boosters skip the weight multiply when there are no weights, and the multiclass booster multiplies by 1.0, which is exact in IEEE arithmetic. Every existing model stays byte-identical and the hash gate verifies it. The pattern generalizes: design the off-state of a feature to be arithmetically inert, then let the gate prove it.
AI-assisted development without trust. bonsai is built by a human maintainer working with Claude. The reason that works is precisely this contract: CI trains the reference model on arm64 and x86-64 for every code change and fails the build if the two hashes differ, and a change that claims to preserve behavior must leave the scripts/model_hash.py hash unchanged. The reviewer checks the diff for intent, and the hash checks the numbers.
Transferring it#
Any numerical system can adopt these three practices: fix the reduction orders (deterministic parallelism need not cost speed: on the CPU tall scenario bonsai's deterministic depthwise fit finishes ahead of XGBoost's, with the numbers on the scenario panels), pin the floating-point environment (contraction, denormals), then hash a reference output in CI on more than one architecture. The gate is a 99-line workflow (cross-arch.yml) that trains the reference model on x86-64 Linux and arm64 macOS and fails if the hashes differ. With it, you can refactor numerical code and know whether any output changed.