Repository: pytorch
Issue: Expanded weights tests broken
Labels: triaged,module: functorch

### 🐛 Describe the bug

```
$ python pytorch/test/run_test.py -i test_expanded_weights -v
<omitted>
Ran 495 tests in 26.571s

FAILED (failures=29, errors=82, skipped=34)
FINISHED PRINTING LOG FILE of test_expanded_weights (/home/sclarkson/pytorch/test/test-reports/test_expanded_weights_24ydgznv.log)

test_expanded_weights failed!
Traceback (most recent call last):
  File "/home/sclarkson/pytorch/test/run_test.py", line 1394, in <module>
    main()
  File "/home/sclarkson/pytorch/test/run_test.py", line 1352, in main
    raise RuntimeError(
RuntimeError: test_expanded_weights failed!

Tip: You can keep running tests even on failure by passing --keep-going to run_test.py.
If running on CI, add the 'keep-going' label to your PR and rerun your jobs.
```

The errors all look like the example below

```
======================================================================
ERROR: test_Conv1d_cuda (__main__.TestExpandedWeightModuleCUDA)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sclarkson/miniconda3/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2069, in wrapper
    method(*args, **kwargs)
  File "/home/sclarkson/miniconda3/lib/python3.10/site-packages/torch/testing/_internal/common_device_type.py", line 401, in instantiated_test
    result = test(self, **param_kwargs)
  File "/home/sclarkson/pytorch/test/test_expanded_weights.py", line 695, in <lambda>
    setattr(TestExpandedWeightModule, test_name, lambda self, test=test: test.test_context_manager(self, 'cpu'))
  File "/home/sclarkson/pytorch/test/test_expanded_weights.py", line 661, in test_context_manager
    test_case._do_test(module, input)
  File "/home/sclarkson/pytorch/test/test_expanded_weights.py", line 412, in _do_test
    actual_grads.append(input.grad.clone())
AttributeError: 'NoneType' object has no attribute 'clone'
```

And the failures all look like the example below.

```
======================================================================
FAIL: test_Conv1d_multiple_inputs_cuda (__main__.TestExpandedWeightModuleCUDA)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sclarkson/miniconda3/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2069, in wrapper
    method(*args, **kwargs)
  File "/home/sclarkson/miniconda3/lib/python3.10/site-packages/torch/testing/_internal/common_device_type.py", line 401, in instantiated_test
    result = test(self, **param_kwargs)
  File "/home/sclarkson/pytorch/test/test_expanded_weights.py", line 697, in <lambda>
    lambda self, test=test: test.test_context_manager_multiple_inputs(self, 'cpu'))
  File "/home/sclarkson/pytorch/test/test_expanded_weights.py", line 670, in test_context_manager_multiple_inputs
    test_case._do_test_multi_input(module, input)
  File "/home/sclarkson/pytorch/test/test_expanded_weights.py", line 476, in _do_test_multi_input
    assert [self.assertEqual(actual, 2 * expected) for (actual, expected) in zip(actual_grads, expected_grads)]
  File "/home/sclarkson/pytorch/test/test_expanded_weights.py", line 476, in <listcomp>
    assert [self.assertEqual(actual, 2 * expected) for (actual, expected) in zip(actual_grads, expected_grads)]
  File "/home/sclarkson/miniconda3/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 2967, in assertEqual
    raise error_metas[0].to_error(
AssertionError: Tensor-likes are not close!

Mismatched elements: 80 / 80 (100.0%)
Greatest absolute difference: 2.188215970993042 at index (0, 0, 2) (up to 1e-05 allowed)
Greatest relative difference: 1.0000067267518076 at index (0, 2, 1) (up to 1.3e-06 allowed)
```

This didn't occur in the 1.13 release. I was able to bisect it back to #91807

It looks like the `TestExpandedWeightModule` is now overloaded to run two fundamentally different types of tests, some that are parameterized manually [here](https://github.com/pytorch/pytorch/blob/116a4f23016ecea430c947785d07702f20290bbd/test/test_expanded_weights.py#L679-L701) and others parameterized by device type [here](https://github.com/pytorch/pytorch/blob/116a4f23016ecea430c947785d07702f20290bbd/test/test_expanded_weights.py#L778)

This conflict is apparent in test names like `test_Conv1d_cuda_double_cpu (__main__.TestExpandedWeightModuleCPU)`

### Versions

```
PyTorch version: 2.0.0
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.19.0-37-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce GTX 1080 Ti
GPU 1: NVIDIA GeForce GTX 1080 Ti

Nvidia driver version: 525.89.02
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.7.0
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:                   46 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          24
On-line CPU(s) list:             0-23
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
CPU family:                      6
Model:                           79
Thread(s) per core:              2
Core(s) per socket:              12
Socket(s):                       1
Stepping:                        1
CPU max MHz:                     2900.0000
CPU min MHz:                     1200.0000
BogoMIPS:                        4400.12
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d
Virtualization:                  VT-x
L1d cache:                       384 KiB (12 instances)
L1i cache:                       384 KiB (12 instances)
L2 cache:                        3 MiB (12 instances)
L3 cache:                        30 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-23
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.23.5
[pip3] torch==2.0.0
[pip3] torchaudio==2.0.0
[pip3] torchvision==0.15.0
[pip3] triton==2.0.0
[conda] blas                      1.0                         mkl  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0           py310h7f8727e_0  
[conda] mkl_fft                   1.3.1           py310hd6ae3a3_0  
[conda] mkl_random                1.2.2           py310h00e6091_0  
[conda] numpy                     1.23.5          py310hd5efca6_0  
[conda] numpy-base                1.23.5          py310h8e6c178_0  
[conda] pytorch                   2.0.0           py3.10_cuda11.8_cudnn8.7.0_0    pytorch
[conda] pytorch-cuda              11.8                 h7e8668a_3    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                2.0.0               py310_cu118    pytorch
[conda] torchtriton               2.0.0                     py310    pytorch
[conda] torchvision               0.15.0              py310_cu118    pytorch
```

cc @zou3519 @Chillee @samdow @soumith @kshitij12345 @janeyx99