Repository navigation
Fix BatchNorm cleanup after failed precise statistics updates - #161
Linxiushen wants to merge 1 commit into
Conversation
|
Hi @Linxiushen! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
update_bn_statsrestores BatchNorm momentum and removes its temporary forward pre-hooks only on success. If the loader ends early, iteration raises, or forward raises after BatchNorm, the caller's layers retainmomentum=1.0and stale hooks. A later normal forward can then raise the reused-BN assertion.Move restoration and hook removal into
finally, retaining the original exception and the existing statistics calculation. The regressions cover insufficient input, a forward exception, and a loader exception; they also check distinct layer momenta (includingNone), preservation of caller hooks, and subsequent normal forward/recalibration. Running statistics and other model state are not rolled back on failure.Validation on Windows, Python 3.12.14, CPU PyTorch 2.9.1:
python -m unittest discover -s tests -v: 118 passed, 2 CUDA tests skipped, withtabulate==0.9.0.python -m unittest discover -s tests/param_scheduler -v: 20 passed.git diff --checkpasses.Retained environment/base limitations: with tabulate 0.10.0,
test_model_stats_tablefails identically on the pristine base and this patch. Repository-wide Black has existing formatting differences, and repository-wide Flake8 reports an unchanged B950 intests/test_checkpoint.py:291; both were checked against the pristine base. This patch formats the two existing assertions in the affected function as required by Black, and does not change those unrelated files. No GPU, distributed execution, pretrained model, or training-quality result is claimed.AI assistance: the patch and regression tests were prepared with Codex.