You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
StandardScaler output differs across platforms enough to move downstream diagnostics #461
Observed during the #437 investigation; recording so the next person comparing local diagnostics against committed evidence does not chase a phantom.
The observation
The committed sklearn_results_v2.txt records RandomForest digits unanimity 0.197222; the same measurement locally (macOS/Accelerate) gives 0.205556 — 3 of 360 test rows — while the per-tree node counts match exactly. Identical fitted trees producing different vote patterns means the inputs differ: StandardScaler's scaled test matrix is not bit-identical across platforms, and rows near a split threshold land on different sides.
Most likely cause: f32 accumulation order in the mean/variance passes differing between platforms/compilers, the same reassociation class as #397/#377 established for BLAS — but this is scalar library code, so it is Flow codegen or libm differences rather than a BLAS vendor.
The canonical fixtures were built specifically so both sides consume byte-identical inputs; a platform-dependent scaler quietly re-introduces the divergence downstream of the fixture.
What would settle it
Instrument standard_scaler_fit/transform to dump mean/std/first-row bits on both platforms and confirm where the first ulp difference enters.
If it is summation order: accumulate mean/variance in f64 (the pattern feat: Newton / IRLS solver for logistic regression, LBFGS stays the default #443 used for its line-search objective, where f32 accumulation demonstrably changed decisions), which should make the scaler bit-stable across platforms at negligible cost.
Re-freeze evidence once, and note in benchmarks/README.md that pre-fix snapshots carry the artifact.
Low urgency, real payoff: it converts "diagnostics differ, is that a bug?" from a recurring investigation into a non-event.
Correcting the diagnosis I filed this issue with, before the PR closes it.
The premise was wrong on two counts, established by PR #465's investigation:
standard_scaler_fit was already f64 two-pass accumulation (since commit 9b12016, predating this issue). All 64 digits columns produce the correctly rounded f32 mean and std, verified against exact rational arithmetic — the tightest column sits 4.9e-10 relative from a rounding boundary, four orders of magnitude beyond what an f64 sum can disturb.
The 0.197222 vs 0.205556 unanimity difference is not cross-platform drift. 0.197222 comes from sklearn_results_v2.txt — the Python side — and reproduces exactly on macOS. The cause: bench_sklearn_v2.py casts to float32 before fitting, so sklearn's StandardScaler.transform evaluates (x - mean_)/scale_ in f32 with one rounding, while an f64-scale-then-round path differs in 7412 of 23040 test cells' last bits, flipping 3 rows. Same machine, two precision paths. The committed snapshot is correct as recorded and needs no re-freeze.
What the PR delivers anyway, and why it still merges: four other reductions in preprocessing.flow had exactly the hazard this issue described and are widened to f64 — normalizer_transform L1/L2 norms, power_transformer_transform mean/variance, the Yeo-Johnson log-likelihood in power_transformer_fit (where a drifting total picks a different lambda, not just a different last bit), and kbins_discretizer_fit sums. Order-independence of MinMax/MaxAbs/Robust is now asserted by a permutation test rather than assumed. All 165 canonical records unchanged; KMeans bit-identical.
Lesson recorded for the next reader: identical trees + different votes means different inputs, but "different inputs" has more than one cause — check which side of the comparison produced the committed number before assuming the platform.
Activity
godofecht commentedon Aug 20, 2026
Correcting the diagnosis I filed this issue with, before the PR closes it.
The premise was wrong on two counts, established by PR #465's investigation:
standard_scaler_fitwas already f64 two-pass accumulation (since commit 9b12016, predating this issue). All 64 digits columns produce the correctly rounded f32 mean and std, verified against exact rational arithmetic — the tightest column sits 4.9e-10 relative from a rounding boundary, four orders of magnitude beyond what an f64 sum can disturb.The 0.197222 vs 0.205556 unanimity difference is not cross-platform drift.
0.197222comes fromsklearn_results_v2.txt— the Python side — and reproduces exactly on macOS. The cause:bench_sklearn_v2.pycasts to float32 before fitting, so sklearn'sStandardScaler.transformevaluates(x - mean_)/scale_in f32 with one rounding, while an f64-scale-then-round path differs in 7412 of 23040 test cells' last bits, flipping 3 rows. Same machine, two precision paths. The committed snapshot is correct as recorded and needs no re-freeze.What the PR delivers anyway, and why it still merges: four other reductions in
preprocessing.flowhad exactly the hazard this issue described and are widened to f64 —normalizer_transformL1/L2 norms,power_transformer_transformmean/variance, the Yeo-Johnson log-likelihood inpower_transformer_fit(where a drifting total picks a different lambda, not just a different last bit), andkbins_discretizer_fitsums. Order-independence of MinMax/MaxAbs/Robust is now asserted by a permutation test rather than assumed. All 165 canonical records unchanged; KMeans bit-identical.Lesson recorded for the next reader: identical trees + different votes means different inputs, but "different inputs" has more than one cause — check which side of the comparison produced the committed number before assuming the platform.
Merge pull request #465 from godofecht/fix/461-scaler-f64-accumulation