Skip to content

Improve numerical stability of batch normalization on CPUs#3113

Merged
davisking merged 4 commits into
davisking:masterfrom
reunanen:improve-numerical-stability-of-batch-normalization-on-CPUs
Sep 29, 2025
Merged

Improve numerical stability of batch normalization on CPUs#3113
davisking merged 4 commits into
davisking:masterfrom
reunanen:improve-numerical-stability-of-batch-normalization-on-CPUs

Conversation

@reunanen

@reunanen reunanen commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Problem: Calculating mean and variance in the CPU implementation of batch normalization is prone to losing some numerical precision (when the data is not zero mean, for example).

Solution: Use Welford's algorithm that is numerically more stable.

Note that the CUDA implementation should already be doing this (or something similar at least), so this change should make the CPU implementation better match the CUDA one.

…_normalize_conv` by computing variances using Welford's algorithm
@reunanen

reunanen commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

Note that the CI error is addressed separately in PR #3112.

smu-sc-gj and others added 2 commits September 28, 2025 10:24
…#3090)

* Use CUDAToolkit, fix davisking#2833

* make cuda optional

* Setting CUDA_ARCHITECTURES to native to remove warning message about Policy CMP0104

* Changed CUDA_ARCHITECTUERS to - all - as suggested.

* cuDNN not found on Windows 10, added to FindCUDNN based on find_cudnn.txt in test_for_cudnn. Now working on Windows 10 with default install paths.

* Fixed the test_for_cuda to use CUDAToolkit

* Fixed test_for_cudnn to use CUDAToolkit, removed reference to find_packaage(CUDA ...

* Cleaned up tests and added a note regarding CUDA_PROPAGATE_HOST_FLAGS, do we still need this?

* Cleaned up tests and added a note regarding CUDA_PROPAGATE_HOST_FLAGS, do we still need this?

* I need to test this on a machine which doesn't have CUDA setup, I wonder if there's any easy way to run that?

* Fix cudnn finding on windows

* fix the path finding on windows

* Make sure cmake knows how to find nvcc

* set cuda arch to something appropriate by default in a portable way

* Make the installed version of dlib work too

* change back to this version

* update CI to use cmake 3.17

* remove unused files

---------

Co-authored-by: Tobias Fischer <info@tobiasfischer.info>
Co-authored-by: Davis King <davis@dlib.net>
@davisking davisking merged commit 2ac06f9 into davisking:master Sep 29, 2025
9 checks passed
@davisking

Copy link
Copy Markdown
Owner

Nice, thanks for another PR :)

@reunanen reunanen deleted the improve-numerical-stability-of-batch-normalization-on-CPUs branch September 29, 2025 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants