FAILURE MAP
← Case archive

FA-98841 / Gradient accumulation weighting / Open access

Unequal example batches receive equal mean-gradient weight · case 01

Unequal example batches receive equal mean-gradient weight.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Each microbatch is represented by a summed gradient and its example count; the implementation averages microbatch means instead of weighting by examples.

THE FAILURE

Each microbatch is represented by a summed gradient and its example count; the implementation averages microbatch means instead of weighting by examples.

Unsuccessful approach: Weighting each batch mean equally only matches the contract when batch sizes are equal.

Case contract

Gradient sums and example counts describe microbatches. Return their global example-weighted mean; zero total examples returns zero.

Why this case matters

A deterministic toy model isolates one local accumulation contract.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(sums, counts):
    return sum(s / max(1, c) for s, c in zip(sums, counts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('unequal batches',solve([2*N,12*N],[N,3*N]),3.5)
check('equal batches',solve([2*N,4*N],[N,N]),3)
check('single batch',solve([7*N],[N]),7)
check('empty window',solve([],[]),0)
check('zero numerator',solve([0,9*N],[N,3*N]),2.25)
check('one large batch',solve([12*N],[4*N]),3)
check('three batches',solve([N,6*N,8*N],[1,2,4]),15*N/7)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
unequal batches6.03.5Failed
equal batches6.03Failed
single batch7.07Passed
empty window00Passed
zero numerator3.02.25Failed
one large batch3.03Passed
three batches6.02.142857142857143Failed

SHA-256 / 3e6d17b77c9a172ed11f6907e093bb9b84b5685d3eaca38a3ee1437a914b20fa

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(sums, counts):
    return sum(s / c for s, c in zip(sums, counts) if c) / max(1, len(sums))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('unequal batches',solve([2*N,12*N],[N,3*N]),3.5)
check('equal batches',solve([2*N,4*N],[N,N]),3)
check('single batch',solve([7*N],[N]),7)
check('empty window',solve([],[]),0)
check('zero numerator',solve([0,9*N],[N,3*N]),2.25)
check('one large batch',solve([12*N],[4*N]),3)
check('three batches',solve([N,6*N,8*N],[1,2,4]),15*N/7)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
unequal batches3.03.5Failed
equal batches3.03Passed
single batch7.07Passed
empty window0.00Passed
zero numerator1.52.25Failed
one large batch3.03Passed
three batches2.02.142857142857143Failed

SHA-256 / 647fe9a2a2d27e8bf125a4ecb8bf419c20a2f99215990c25dc189448f198937d

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 7 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

Inputs are scalar or short-list summaries and do not model autodiff, devices, or an optimizer. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-30T16:48:17.605217+00:00.

Case digest / 495faca851ccd317ff9373e1212e905e6f24e08c6bc5ccd686ebfd4618c24543