BatchNorm1d / Reduce: float32 sums over batch×time use one sequential accumulator
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 54/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- machine-learning
Research direction
Read meanOverTrailingAxesFloat32 and varianceBiasedOverTrailingAxesFloat32 in src/arithmetic/Reduce.c, then inspect bnBackward in src/layer/BatchNorm1d.c. Compare pairwise or blocked float32 summation approaches and check the existing BatchNorm and Reduce tests against their current tolerances; done means the sums use the chosen approach while those tests still pass.
Written by the indexing model from the issue text.
Description
Problem
BatchNorm1d sums over batch × time with one float32 accumulator, element by element:
- forward statistics:
meanOverTrailingAxesFloat32andvarianceBiasedOverTrailingAxesFloat32insrc/arithmetic/Reduce.c(onefloat accper channel); - backward:
sumDy/sumDyXhatinsrc/layer/BatchNorm1d.c(bnBackward, same pattern).
For a TC-ResNet8 stem on 12-class keyword spotting (batch 100, T = 98) that is N = 9,800 terms per channel. The rounding error of a running float32 sum grows with N (worst case ~N·ε, typically ~√N·ε), while a pairwise or blocked sum grows with log N.
Evidence
Same start, C vs a PyTorch float32 twin of the same model (identical initial weights, data order, Dropout off):
- step 1 losses agree to < 1e-4 relative;
- the per-step loss then drifts above 1e-4 relative at step 4–13 (4 seeds), while PyTorch float32 vs float64 drifts only at step 7–61;
- a PyTorch twin that copies C's sequential BN summation reproduces C's departure steps, so the BN sums are the main source.
The effect on final accuracy is within seed noise (10-seed comparison), so this is precision, not a correctness bug.
Options
- Pairwise (or fixed-size blocked) summation in the Reduce float32 kernels and the BN backward sums. Same op count, a small stack or loop change; helps every Reduce user (LayerNorm, GroupNorm, PPCA replay).
- Kahan summation: ~4× the adds per element; costly on an MCU.
- Leave as is and document it.
Option 1 looks like the right cost/benefit for an MCU. Any change re-captures no goldens by itself; the existing BN/Reduce tests must stay within their tolerances.
- Dominant language
- C
- Stars
- 2
- Forks
- 3
- Avg merge
- 13h 6m
- Merged PRs (30d)
- 9
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from es-ude/OnDeviceTraining
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
es-ude/OnDeviceTraining#549 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
es-ude/OnDeviceTraining#547 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
es-ude/OnDeviceTraining#536 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
es-ude/OnDeviceTraining#478 ·
Maintainers usually reply within 1 day
-
bug documentation
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
es-ude/OnDeviceTraining#459 ·
Maintainers usually reply within 1 day
All issues in es-ude/OnDeviceTraining
Similar issues
-
issue: bug report
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
BasedHardware/omi#26486 ·
Maintainers usually reply within 1 day
-
The LLVM object can build before collection_config.h is generatedPossibly taken @Vonng claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
aws/pgcollection#51 ·
-
area/docdb kind/failing-test priority/medium status/awaiting-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
yugabyte/yugabyte-db#39462 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
libreswan/libreswan#3185 · 1 comment ·
Maintainers usually reply within 1 day