torch.batch_norm
shows inconsistent error behavior between CPU and GPU
#153137
Labels
module: edge cases
Adversarial inputs unlikely to occur in practice
module: error checking
Bugs related to incorrect/lacking error checking
module: nn
Related to torch.nn
module: norms and normalization
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
🐛 Describe the bug
Description
When
torch.batch_norm
is called with one ofrunning_mean
orrunning_var
as a tensor and the other asNone
, an internal assertionExpected has_running_mean == has_running_var to be true, but got false
is triggered on CUDA-enabled GPUs. However, this error is not triggered when the same code is run on the CPU.Ideally, the behavior should be consistent across devices, meaning either both CPU and GPU should raise this specific error.
To Reproduce:
The following code demonstrates the issue. It tests two scenarios:
running_mean
is a Tensor,running_var
isNone
.running_mean
isNone
,running_var
is a Tensor.Expected behavior:
The error RuntimeError: Expected has_running_mean == has_running_var to be true, but got false. should either be raised consistently on both CPU and GPU
Actual behavior ):
PyTorch Version: 2.6.0+cu124
--- Scenario 1: running_mean is Tensor, running_var is None ---
CPU (Scenario 1):
CPU: Error not triggered.
GPU (Scenario 1):
GPU Error: Expected has_running_mean == has_running_var to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)
GPU: Successfully triggered the target error.
--- Scenario 2: running_mean is None, running_var is Tensor ---
CPU (Scenario 2):
CPU: Error not triggered.
GPU (Scenario 2):
GPU Error: Expected has_running_mean == has_running_var to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)
GPU: Successfully triggered the target error.
The full code used for testing can be found at:
https://colab.research.google.com/drive/17xWrbcKvMTpDTHcz_XSrnb5esLCUh970?usp=sharing
Versions
cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki @malfet
The text was updated successfully, but these errors were encountered: