Repository navigation
Accumulate low-precision average pooling in float32 - #914
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek wants to merge 1 commit into
Conversation
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
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.
Summary
Accumulate float16/bfloat16 window sums and SAME-padding counts in float32, then return the original dtype after division. This prevents premature half-precision sum overflow when the pooled mean is representable and improves bfloat16 averaging.
Float32/float64 inputs, max pooling, shape inference and padding semantics are unchanged. The change is separate from the shape-handling proposal in #824. Float32 accumulator overflow and accelerator performance are outside this correction.
Reproduction
Unchanged main returns infinity instead of 256.
Validation
python -m pytest -q haiku/_src/pool_test.py haiku/_src/pool_precision_test.pyAll 20 existing pooling tests and 16 new cases pass. Coverage includes independent NumPy window means, positive/negative constant activations, nonuniform values, both layouts and padding modes, float16/bfloat16/float32, eager/JIT execution, vmap, and a real
AvgPoolmodule with a finite loss and gradients. Eight new tests fail on unchanged upstream and eight controls pass.Eight existing shape-inference deprecation warnings were emitted. No trained model, image dataset or GPU/TPU execution was used; no performance claim is made.
Tested locally on macOS CPU using real module imports. New test formatting, scoped static checks, syntax checks and
git diff --checkpass. No dependency or workflow changes.