Repository: pytorch
Issue: unstable test_GroupNorm_general_cpu in test/test_nn.py
Labels: module: nn,triaged

### 🐛 Describe the bug

`test_GroupNorm_general_cpu` computes `nn.GroupNorm()` from random inputs in `bfloat16` and `float` precision. Then asserts the outputs are "close enough" which is not true for specific random seeds. For example, add this line on line 8052 in `test/test_nn.py` from branch `release/2.1` (right before `torch.randn()` call):

```
torch.manual_seed(5789119567394461641)
```

Then run this single test e.g. by `python test/test_nn.py -k test_GroupNorm_general_cpu` and it fails:

```
F
======================================================================
FAIL: test_GroupNorm_general_cpu (__main__.TestNNDeviceTypeCPU)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mkrizan/.local/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2388, in wrapper
    method(*args, **kwargs)
  File "/home/mkrizan/.local/lib/python3.10/site-packages/torch/testing/_internal/common_device_type.py", line 415, in instantiated_test
    result = test(self, **param_kwargs)
  File "/home/mkrizan/.local/lib/python3.10/site-packages/torch/testing/_internal/common_device_type.py", line 1120, in only_fn
    return fn(self, *args, **kwargs)
  File "/home/mkrizan/pytorch/test/test_nn.py", line 8546, in test_GroupNorm_general
    self._test_GroupNorm_cpu_mixed_dtype()
  File "/home/mkrizan/pytorch/test/test_nn.py", line 8093, in _test_GroupNorm_cpu_mixed_dtype
    helper(self, (4, 40, 40, 40), 2, torch.contiguous_format)
  File "/home/mkrizan/pytorch/test/test_nn.py", line 8083, in helper
    self.assertEqual(m_bf.weight.grad.float(), m_f.weight.grad, atol=1e-3, rtol=1.2e-1)
  File "/home/mkrizan/.local/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 3285, in assertEqual
    raise error_metas.pop()[0].to_error(
AssertionError: Tensor-likes are not close!

Mismatched elements: 2 / 40 (5.0%)
Greatest absolute difference: 0.1851346492767334 at index (13,) (up to 0.001 allowed)
Greatest relative difference: 0.3529515862464905 at index (35,) (up to 0.12 allowed)

To execute this test, run the following from the base repo dir:
     python test/test_nn.py -k test_GroupNorm_general_cpu

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0

----------------------------------------------------------------------
Ran 1 test in 0.052s

FAILED (failures=1)
```

I wasn't able to run this test from branch `release/2.2` nor `main` because of missing features in latest pytorch 2.1 build, but the absolute and relative tolerances look the same.

I suggest to un-randomize this test -- either hardcode sample inputs or manual seed.

### Versions

Collecting environment information...
PyTorch version: 2.1.2+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-91-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      45 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             4
On-line CPU(s) list:                0-3
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Xeon(R) Gold 6242 CPU @ 2.80GHz
CPU family:                         6
Model:                              85
Thread(s) per core:                 1
Core(s) per socket:                 4
Socket(s):                          1
Stepping:                           7
BogoMIPS:                           5586.87
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
Hypervisor vendor:                  VMware
Virtualization type:                full
L1d cache:                          128 KiB (4 instances)
L1i cache:                          128 KiB (4 instances)
L2 cache:                           4 MiB (4 instances)
L3 cache:                           22 MiB (1 instance)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-3
Vulnerability Gather data sampling: Unknown: Dependent on hypervisor status
Vulnerability Itlb multihit:        KVM: Mitigation: VMX unsupported
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Retbleed:             Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.2
[pip3] torch==2.1.2+cpu
[conda] Could not collect

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki