Repository: pytorch
Issue: Bazel target all_tests improperly reports failures on CPU-only (non-CUDA) build
Labels: module: bootcamp,module: tests,triaged,module: bazel

Running:

```
tools/bazel test :all_tests 
```

on a CPU only machine gives:

```
//:functional_test                                                       FAILED in 2.2s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/functional_test/test.log
//:integration_test                                                      FAILED in 155.4s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/integration_test/test.log
//:module_test                                                           FAILED in 1.3s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/module_test/test.log
//:modulelist_test                                                       FAILED in 1.3s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/modulelist_test/test.log
//:modules_test                                                          FAILED in 60.4s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/modules_test/test.log
//:rnn_test                                                              FAILED in 90.5s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/rnn_test/test.log
//:sequential_test                                                       FAILED in 2.0s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/sequential_test/test.log
//:serialize_test                                                        FAILED in 5.7s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/serialize_test/test.log
//:tensor_test                                                           FAILED in 1.3s
  /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/tensor_test/test.log
```

The failed tests:

```
[  FAILED  ] FunctionalTest.isfinite_CUDA   
[  FAILED  ] FunctionalTest.isinf_CUDA
[  FAILED  ] FunctionalTest.AllClose_CUDA
                                                                                                        
[  FAILED  ] IntegrationTest.MNIST_CUDA                                                                                                                       
[  FAILED  ] IntegrationTest.MNISTBatchNorm_CUDA   
                                                              
[  FAILED  ] 1 test, listed below:                                                                                                                            
[  FAILED  ] ModuleListTest.CloneToDevice_CUDA                                                                                                                
                                                                                                                                                              
 1 FAILED TEST                                                                                                                                                
                                                                                                                                                              
==> /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/modules_test/test.log <==       
[----------] 257 tests from ModulesTest (59184 ms total)                                                                                                      
                                                                               
[----------] Global test environment tear-down                                                                                                                
[==========] 257 tests from 1 test suite ran. (59185 ms total)                                                                                                
[  PASSED  ] 255 tests.                                                                                                                                       
[  FAILED  ] 2 tests, listed below:                                                                                                                           
[  FAILED  ] ModulesTest.Linear_CUDA                                           
[  FAILED  ] ModulesTest.Linear2_CUDA                                          
                                                                               
 2 FAILED TESTS                                                                
                                                                                                                                                              
==> /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/module_test/test.log <==        
[  PASSED  ] 52 tests.                                                         
[  FAILED  ] 6 tests, listed below:                                                                                                                           
[  FAILED  ] ModuleTest.DeviceOrDtypeConversionSkipsUndefinedTensor_CUDA                                                                                      
[  FAILED  ] ModuleTest.Conversion_MultiCUDA                                                                                                                  
[  FAILED  ] ModuleTest.CloneCreatesDistinctParametersExplicitDevice_CUDA                                                                                     
[  FAILED  ] ModuleTest.CloneCreatesDistinctParametersExplicitDevice_MultiCUDA                                                                                [  FAILED  ] ModuleTest.CloneToDevicePreservesTheDeviceOfParameters_CUDA       
[  FAILED  ] ModuleTest.CloningToAParticularDevicePlacesAllParametersThere_MultiCUDA  

                   
==> /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/rnn_test/test.log <==           
[  FAILED  ] RNNTest.EndToEndGRU_CUDA                                                                                                                         
[  FAILED  ] RNNTest.EndToEndRNNRelu_CUDA                                      
[  FAILED  ] RNNTest.EndToEndRNNTanh_CUDA                                                                                                                     
[  FAILED  ] RNNTest.BidirectionalGRUReverseForward_CUDA                                                                                                      
[  FAILED  ] RNNTest.BidirectionalLSTMReverseForward_CUDA                                                                                                     
[  FAILED  ] RNNTest.BidirectionalMultilayerGRU_CPU_vs_CUDA                                                                                                   
[  FAILED  ] RNNTest.BidirectionalMultilayerLSTM_CPU_vs_CUDA                   
[  FAILED  ] RNNTest.BidirectionalMultilayerLSTMProj_CPU_vs_CUDA               
                                                                               
12 FAILED TESTS                                                                
                                                                                                                                                              
==> /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/sequential_test/test.log <==    
[       OK ] SequentialTest.ModuleForwardMethodOptionalArg (81 ms)             
[----------] 20 tests from SequentialTest (105 ms total)                                                                                                      
                                                                                                                                                              
[----------] Global test environment tear-down                                                                                                                
[==========] 20 tests from 1 test suite ran. (106 ms total)                                                                                                   
[  PASSED  ] 19 tests.                                                                                                                                        [  FAILED  ] 1 test, listed below:                                             
[  FAILED  ] SequentialTest.CloneToDevice_CUDA                                                                                                                
                                                                                                                                                               1 FAILED TEST                                                                                                                                                
                                                                                                                                                              
==> /home/ezyang/.cache/bazel/_bazel_ezyang/57017727cbef3ee89fd88130e4612819/execroot/pytorch/bazel-out/k8-fastbuild/testlogs/serialize_test/test.log <== 
[       OK ] SerializeTest.UnserializableSubmoduleIsIgnoredWhenLoadingModule (3 ms)
[----------] 23 tests from SerializeTest (4336 ms total)                                                                                                      
                                                                               
[----------] Global test environment tear-down                                 
[==========] 23 tests from 1 test suite ran. (4336 ms total)                                                                                                  
[  PASSED  ] 22 tests.                                                                                                                                        
[  FAILED  ] 1 test, listed below:                                                                                                                            
[  FAILED  ] SerializeTest.XOR_CUDA  

                                                                                                                
[  FAILED  ] TensorTest.TorchTensorCtorMultiDim_CUDA                           
[  FAILED  ] TensorTest.Item_CUDA   
```

These are clearly all CUDA tests. They should be skipped on a CPU-only build.

cc @mruberry