fix: fixed-order fp32 tree reductions (zerfoo T135.2)#175
Merged
Conversation
Float32Ops.Sum and Float64Ops.Sum now accumulate in a recursive pairwise (tree) order whose split points depend only on length, not on chunking. Bitwise-stable run to run and O(log n) rather than O(n) rounding error, without narrowing the accumulation dtype. Verifies UC-H2-003 / UC-GH-5.
…135.2) Non-arm64 RMSNormF32 fallback now sums x^2 in fixed-order pairwise float32, matching the fp32 accumulation of the arm64 NEON path while shrinking the naive-fold error. The arm64 SIMD path is already fixed-order fp32 (8-way strided) and is unchanged. Verifies UC-GH-5.
…foo T135.2) Sum/ReduceSum/ReduceMean (via Sum) and the Softmax denominator now use a fixed-order pairwise tree reduction (compute/reduce_pairwise.go). The accumulation order is a pure function of the reduced length, so results are bitwise-identical across GOMAXPROCS and run to run, and agreement with the PyTorch oracle tightens (16-940x lower float32 relerr for ReduceSum) with no dtype change. Verifies UC-H2-003 / UC-GH-5.
…p32 (zerfoo T135.2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
zerfoo T135.2 / UC-H2-003, UC-GH-5 -- fixed-order fp32 tree reductions
Audits every CPU reduction in ztensor for accumulation order and dtype and
converts the naive left-to-right folds to fixed-order pairwise (tree)
accumulation. The tree shape is a pure function of the reduced length (recursive
halving snapped to a 128-element base block, numpy-style), so results are
bitwise-identical across
GOMAXPROCSand run to run, and agreement with thePyTorch oracle tightens. Accumulation dtype is preserved per site (no narrowing).
Reductions converted
Sum/ReduceSum(all-axis)compute/cpu_engine.goSum/ReduceSum(per-axis stripe)compute/cpu_engine.goReduceMeancompute/cpu_engine.goSumSoftmaxdenominator (generic path)compute/cpu_engine.gointernal/xblas/rmsnorm_generic.goArithmetic.Sum(float32/float64)numeric/native_ops.goAccuracy (measured, float32 vs Kahan-float64 ground truth)
Relative-error tightening; no input regresses:
Explicitly NOT converted (feeds T135.5 ZTENSOR_DETERMINISTIC / out of scope)
internal/cuda/kernels/*.cu: rmsnorm, fused_softmax_vmul, flash_*, reductions usingatomicAdd/warp-shuffle): cannot build/run on the darwin dev host; GPU priority held by a concurrent task this wave. Cross-blockatomicAddorder is the real run-to-run nondeterminism source -> T135.5.RMSNormF32(internal/xblas/rmsnorm_arm64.s): already fixed-order fp32 (8-way strided + horizontal reduce), deterministic; a pairwise/float64 SIMD rewrite is deferred. This is the GB10 (aarch64) production path, so the RMSNorm oracle diff is unchanged by this PR.SoftmaxF32(softmax_generic.go): already accumulates the denominator in float64 (single sequential loop, deterministic); float64 naive error (~1e-16*n) is orders below the fp32 oracle tolerance, so no change needed.Arithmetic.Sum: left pairwise-in-type; widening to a float32 accumulator (aten AccumulateType) deferred to T135.5.training/); flagged for a zerfoo-side follow-up.Tests (run on Linux CI -- authoritative)
compute/reduce_pairwise_test.go: base-case == naive for n<=block; run-to-run determinism; tighter-than-naive vs float64 ref;ReduceSumbitwise-identical across GOMAXPROCS 1/2/4/8; softmax determinism.numeric/reduce_pairwise_test.go,internal/xblas/reduce_pairwise_test.go: determinism + tightening + RMSNorm scale accuracy.Docs: reduction accumulation policy added to
docs/design.md.Local verification limited to
go build/go vet/golangci-lint+ a standalone numeric proof: ztensor test binaries SIGSEGV at cuda device-init on the darwin host (ztensor#171, being fixed concurrently). GB10 oracle sweep recorded as follow-up evidence for T135.3.