BatchNorm1d / Reduce: float32 sums over batch×time use one sequential accumulator

Aperta
#548 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

BatchNorm1d sums over batch × time with one float32 accumulator, element by element:

  • forward statistics: meanOverTrailingAxesFloat32 and varianceBiasedOverTrailingAxesFloat32 in src/arithmetic/Reduce.c (one float acc per channel);
  • backward: sumDy / sumDyXhat in src/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

  1. 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).
  2. Kahan summation: ~4× the adds per element; costly on an MCU.
  3. 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.

Lingua principale
C
Stelle
2
Fork
3
Merge medio
13h 6m
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di es-ude/OnDeviceTraining

Tutte le issue di es-ude/OnDeviceTraining

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.