Improve numerical stability of batch normalization on CPUs#3113
Merged
davisking merged 4 commits intoSep 29, 2025
Merged
Conversation
…` fail by introducing non-zero mean
…_normalize_conv` by computing variances using Welford's algorithm
Contributor
Author
|
Note that the CI error is addressed separately in PR #3112. |
…#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>
…ility-of-batch-normalization-on-CPUs
Owner
|
Nice, thanks for another PR :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.