Problems when loading PT files und Linux - Duda which are created under Mac Apple Silicon MPS
Labels: triaged, module: mps

### 🐛 Describe the bug

We trained a Model under Apple-Silicon and are not able to reload the model under Linux. 

```

raceback (most recent call last):
  File "/home/automatum/automatum-data-v3/scripts/playPeter.py", line 116, in <module>
    model = pipeUrbanClassificator.UrbanClassifierNet.init_from_pt_file('/home/automatum/automatum-data-v3/src/recording_pipeline/urban_classifier_weights.pt', torch.device('cpu'))
  File "/home/automatum/automatum-data-v3/src/recording_pipeline/pipeUrbanClassificator.py", line 51, in init_from_pt_file
    model.load_state_dict(torch.load(path_to_pt_file))
  File "/home/automatum/automatum-data-v3/env/lib/python3.10/site-packages/torch/serialization.py", line 809, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/automatum/automatum-data-v3/env/lib/python3.10/site-packages/torch/serialization.py", line 1172, in _load
    result = unpickler.load()
  File "/home/automatum/automatum-data-v3/env/lib/python3.10/site-packages/torch/_utils.py", line 266, in _rebuild_device_tensor_from_numpy
    tensor = torch.from_numpy(data).to(dtype=dtype, device=device)
NotImplementedError: Could not run 'aten::empty_strided' with arguments from the 'MPS' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'aten::empty_strided' is only available for these backends: [CPU, CUDA, Meta, QuantizedCPU, QuantizedCUDA, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradHIP, AutogradXLA, AutogradMPS, AutogradIPU, AutogradXPU, AutogradHPU, AutogradVE, AutogradLazy, AutogradMeta, AutogradMTIA, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, AutogradNestedTensor, Tracer, AutocastCPU, AutocastCUDA, FuncTorchBatched, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PythonDispatcher].

CPU: registered at aten/src/ATen/RegisterCPU.cpp:31034 [kernel]
CUDA: registered at aten/src/ATen/RegisterCUDA.cpp:43986 [kernel]
Meta: registered at aten/src/ATen/RegisterMeta.cpp:26824 [kernel]
QuantizedCPU: registered at aten/src/ATen/RegisterQuantizedCPU.cpp:929 [kernel]
QuantizedCUDA: registered at aten/src/ATen/RegisterQuantizedCUDA.cpp:459 [kernel]
BackendSelect: registered at aten/src/ATen/RegisterBackendSelect.cpp:726 [kernel]
Python: registered at ../aten/src/ATen/core/PythonFallbackKernel.cpp:144 [backend fallback]
FuncTorchDynamicLayerBackMode: registered at ../aten/src/ATen/functorch/DynamicLayer.cpp:491 [backend fallback]
Functionalize: registered at ../aten/src/ATen/FunctionalizeFallbackKernel.cpp:280 [backend fallback]
Named: registered at ../aten/src/ATen/core/NamedRegistrations.cpp:7 [backend fallback]
Conjugate: fallthrough registered at ../aten/src/ATen/ConjugateFallback.cpp:21 [kernel]
Negative: fallthrough registered at ../aten/src/ATen/native/NegateFallback.cpp:23 [kernel]
ZeroTensor: fallthrough registered at ../aten/src/ATen/ZeroTensorFallback.cpp:90 [kernel]
ADInplaceOrView: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:63 [backend fallback]
AutogradOther: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradCPU: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradCUDA: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradHIP: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradXLA: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradMPS: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradIPU: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradXPU: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradHPU: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradVE: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradLazy: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradMeta: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradMTIA: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradPrivateUse1: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradPrivateUse2: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradPrivateUse3: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
AutogradNestedTensor: registered at ../torch/csrc/autograd/generated/VariableType_2.cpp:17472 [autograd kernel]
Tracer: registered at ../torch/csrc/autograd/generated/TraceType_2.cpp:16726 [kernel]
AutocastCPU: fallthrough registered at ../aten/src/ATen/autocast_mode.cpp:487 [backend fallback]
AutocastCUDA: fallthrough registered at ../aten/src/ATen/autocast_mode.cpp:354 [backend fallback]
FuncTorchBatched: registered at ../aten/src/ATen/functorch/LegacyBatchingRegistrations.cpp:815 [backend fallback]
FuncTorchVmapMode: fallthrough registered at ../aten/src/ATen/functorch/VmapModeRegistrations.cpp:28 [backend fallback]
Batched: registered at ../aten/src/ATen/LegacyBatchingRegistrations.cpp:1073 [backend fallback]
VmapMode: fallthrough registered at ../aten/src/ATen/VmapModeRegistrations.cpp:33 [backend fallback]
FuncTorchGradWrapper: registered at ../aten/src/ATen/functorch/TensorWrapper.cpp:210 [backend fallback]
PythonTLSSnapshot: registered at ../aten/src/ATen/core/PythonFallbackKernel.cpp:152 [backend fallback]
FuncTorchDynamicLayerFrontMode: registered at ../aten/src/ATen/functorch/DynamicLayer.cpp:487 [backend fallback]
PythonDispatcher: registered at ../aten/src/ATen/core/PythonFallbackKernel.cpp:148 [backend fallback]
```


Implementation of the Model: 


```
class UrbanClassifierNet(nn.Module):
    """Urban Classifier Net:
        Input: 224x224x3 image
        Output: Class label as Number for each class. """
    def __init__(self):

    
        super(UrbanClassifierNet, self).__init__()
        self.get_number_of_classes_from_pipe_config()
        self.model = resnet50(weights='ResNet50_Weights.DEFAULT')
        self.model.fc = nn.Linear(self.model.fc.in_features, self.model.fc.out_features)
        self.relu = nn.ReLU()
        self.fc_x = nn.Linear(self.model.fc.out_features, NUM_CLASSES)
     
    def forward(self, x):

        x_model = self.model(x)
        x = self.relu(x_model)
        x = self.fc_x(x)

        return x
    
    @staticmethod 
    def init_from_pt_file(path_to_pt_file, device):

        model = UrbanClassifierNet()
        
        model.load_state_dict(torch.load(path_to_pt_file))
        model.to(device)
        model.eval()

        return model
    
    @staticmethod
    def get_number_of_classes_from_pipe_config():
        global NUM_CLASSES
        obj_class_dict = cfgMgmt('recording_pipline.cfg').get('object_class_labels')
        NUM_CLASSES = len(obj_class_dict)
```



### Versions

```
wget https://raw.githubusercontent.com/pytorch/pytorch/main/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
--2023-09-23 17:48:50--  https://raw.githubusercontent.com/pytorch/pytorch/main/torch/utils/collect_env.py
Auflösen des Hostnamens raw.githubusercontent.com (raw.githubusercontent.com) … 185.199.111.133, 185.199.110.133, 185.199.109.133, ...
Verbindungsaufbau zu raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 200 OK
Länge: 21709 (21K) [text/plain]
Wird in ‘collect_env.py’ gespeichert.

collect_env.py                                                                            100%[=====================================================================================================================================================================================================================================>]  21,20K  --.-KB/s    in 0,004s  

2023-09-23 17:48:50 (5,37 MB/s) - ‘collect_env.py’ gespeichert [21709/21709]

Collecting environment information...
PyTorch version: 2.0.1+cu117
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.27.5
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.19.0-50-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1080 Ti
Nvidia driver version: 525.125.06
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architektur:                     x86_64
CPU Operationsmodus:             32-bit, 64-bit
Adressgrößen:                    46 bits physical, 48 bits virtual
Byte-Reihenfolge:                Little Endian
CPU(s):                          32
Liste der Online-CPU(s):         0-31
Anbieterkennung:                 GenuineIntel
Modellname:                      Intel(R) Xeon(R) CPU E5-2687W v2 @ 3.40GHz
Prozessorfamilie:                6
Modell:                          62
Thread(s) pro Kern:              2
Kern(e) pro Socket:              8
Sockel:                          2
Stepping:                        4
Maximale Taktfrequenz der CPU:   4000,0000
Minimale Taktfrequenz der CPU:   1200,0000
BogoMIPS:                        6783.49
Markierungen:                    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 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts md_clear flush_l1d
Virtualisierung:                 VT-x
L1d Cache:                       512 KiB (16 instances)
L1i Cache:                       512 KiB (16 instances)
L2 Cache:                        4 MiB (16 instances)
L3 Cache:                        50 MiB (2 instances)
NUMA-Knoten:                     2
NUMA-Knoten0 CPU(s):             0-7,16-23
NUMA-Knoten1 CPU(s):             8-15,24-31
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:   Unknown: No mitigations
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:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.25.1
[pip3] torch==2.0.1
[pip3] torchaudio==2.0.2
[pip3] torchmetrics==1.0.1
[pip3] torchvision==0.15.2
[pip3] triton==2.0.0
[conda] Could not collect
```

cc @kulinseth @albanD @malfet @DenisVieriu97 @razarmehr @abhudev