Repository: pytorch
Issue: Error occurred when trying to call "torch::jit::load"method for loading ".pt" file on IOS
Labels: oncall: jit,oncall: mobile

## ❓c10::Error: Could not find schema for aten::empty.memory_format.

### Problem description
- Hi, I am using this depth estimation algorithm [BTS](https://github.com/cogaplex-bts/bts) to predict my pics and it works well on my Ubuntu 18,04.
-  PyTorch 1.8 binary is builded from source that includes the Metal backend. https://pytorch.org/tutorials/prototype/ios_gpu_workflow.html?highlight=from_blob
- But I have encountered a problem trying to load the Metal model on IOS.
```
 torch::jit::script::Module _impl = torch::jit::load(path.UTF8String);
```
- Hope for all of your replies. THANKS A LOT !
### System Info
- python 3.7
- opencv 4.4
- pytorch 1.8
- Xcode 12.1
### Exporting code on Ubuntu
```
traced_model = torch.jit.trace(model.module, image)          
optimized_model = optimize_for_mobile(traced_model,backend='Metal')
print(torch.jit.export_opnames(optimized_model))        
torch.jit.save(optimized_model, './bts_1result_1.8_512_256_metal.pt')
```
### Loading code on IOS
```
#import "../LibTorch/include/LibTorch.h"

NSString *path = [[NSBundle mainBundle] pathForResource:@"bts_1result_1.8_512_256_metal" ofType:@"pt"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        torch::jit::script::Module _impl = torch::jit::load(path.UTF8String);
        _impl.eval();
        at::Tensor tensor;
        tensor.metal();
    }
```

### Error info
```
libc++abi.dylib: terminating with uncaught exception of type c10::Error: Could not find schema for aten::empty.memory_format
Exception raised from findSchemaOrThrow at /Users/liyixian/Desktop/pytorch/aten/src/ATen/core/dispatch/Dispatcher.cpp:81 (most recent call first):
frame #0: _ZN3c1010Dispatcher17findSchemaOrThrowEPKcS2_ + 620 (0x102b1495c in LibTorch_ImportTest)
frame #1: _ZN2at5emptyEN3c108ArrayRefIxEERKNS0_13TensorOptionsENS0_8optionalINS0_12MemoryFormatEEE + 184 (0x102bdf560 in LibTorch_ImportTest)
frame #2: _ZN5torch3jit9Unpickler15readInstructionEv + 4296 (0x103048f38 in LibTorch_ImportTest)
frame #3: _ZN5torch3jit9Unpickler3runEv + 68 (0x103047b0c in LibTorch_ImportTest)
frame #4: _ZN5torch3jit9Unpickler12parse_ivalueEv + 32 (0x1030478a4 in LibTorch_ImportTest)
frame #5: _ZN5torch3jit21readArchiveAndTensorsERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEN3c108optionalINS1_8functionIFNSA_13StrongTypePtrERKNSA_13QualifiedNameEEEEEENSB_INSC_IFNSA_13intrusive_ptrINSA_6ivalue6ObjectENSA_6detail34intrusive_target_default_null_typeISM_EEEESD_NSA_6IValueEEEEEENSB_INSA_6DeviceEEERN6caffe29serialize19PyTorchStreamReaderE + 816 (0x102ff5e10 in LibTorch_ImportTest)
frame #6: _ZN5torch3jit12_GLOBAL__N_124ScriptModuleDeserializer11readArchiveERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE + 276 (0x102ff84e4 in LibTorch_ImportTest)
frame #7: _ZN5torch3jit12_GLOBAL__N_124ScriptModuleDeserializer11deserializeEN3c108optionalINS3_6DeviceEEERNSt3__113unordered_mapINS7_12basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEESE_NS7_4hashISE_EENS7_8equal_toISE_EENSC_INS7_4pairIKSE_SE_EEEEEE + 516 (0x102ff6698 in LibTorch_ImportTest)
frame #8: _ZN5torch3jit4loadENSt3__110unique_ptrIN6caffe29serialize20ReadAdapterInterfaceENS1_14default_deleteIS5_EEEEN3c108optionalINS9_6DeviceEEERNS1_13unordered_mapINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEESJ_NS1_4hashISJ_EENS1_8equal_toISJ_EENSH_INS1_4pairIKSJ_SJ_EEEEEE + 344 (0x102ff7338 in LibTorch_ImportTest)
frame #9: _ZN5torch3jit4loadERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEN3c108optionalINSA_6DeviceEEERNS1_13unordered_mapIS7_S7_NS1_4hashIS7_EENS1_8equal_toIS7_EENS5_INS1_4pairIS8_S7_EEEEEE + 116 (0x102ff7610 in LibTorch_ImportTest)
frame #10: -[ViewController + + (0x102ae8acc in LibTorch_ImportTest)
frame #11: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 4089432 (0x1b43e1658 in UIKitCore)
frame #12: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 4108520 (0x1b43e60e8 in UIKitCore)
frame #13: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 4109552 (0x1b43e64f0 in UIKitCore)
frame #14: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10902512 (0x1b4a60bf0 in UIKitCore)
frame #15: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10900268 (0x1b4a6032c in UIKitCore)
frame #16: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10904204 (0x1b4a6128c in UIKitCore)
frame #17: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10973456 (0x1b4a72110 in UIKitCore)
frame #18: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 13046956 (0x1b4c6c4ac in UIKitCore)
frame #19: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 269784 (0x1b403cdd8 in UIKitCore)
frame #20: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10657812 (0x1b4a25014 in UIKitCore)
frame #21: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10658740 (0x1b4a253b4 in UIKitCore)
frame #22: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 6071704 (0x1b45c5598 in UIKitCore)
frame #23: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 50716 (0x1b5afc61c in FrontBoardServices)
frame #24: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 201108 (0x1b5b21194 in FrontBoardServices)
frame #25: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 93180 (0x1b5b06bfc in FrontBoardServices)
frame #26: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 200272 (0x1b5b20e50 in FrontBoardServices)
frame #27: _dispatch_client_callout + 16 (0x1039b3730 in libdispatch.dylib)
frame #28: _dispatch_block_invoke_direct + 232 (0x1039b6bb0 in libdispatch.dylib)
frame #29: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 350288 (0x1b5b45850 in FrontBoardServices)
frame #30: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 349468 (0x1b5b4551c in FrontBoardServices)
frame #31: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 350788 (0x1b5b45a44 in FrontBoardServices)
frame #32: 707F86B5-2929-3667-B42C-3004C5E0C87D + 690904 (0x1b08f3ad8 in CoreFoundation)
frame #33: 707F86B5-2929-3667-B42C-3004C5E0C87D + 690736 (0x1b08f3a30 in CoreFoundation)
frame #34: 707F86B5-2929-3667-B42C-3004C5E0C87D + 688660 (0x1b08f3214 in CoreFoundation)
frame #35: 707F86B5-2929-3667-B42C-3004C5E0C87D + 668136 (0x1b08ee1e8 in CoreFoundation)
frame #36: CFRunLoopRunSpecific + 424 (0x1b08edba8 in CoreFoundation)
frame #37: GSEventRunModal + 160 (0x1baa64344 in GraphicsServices)
frame #38: UIApplicationMain + 1932 (0x1b4a293e4 in UIKitCore)
frame #39: main + 140 (0x102aedbf4 in LibTorch_ImportTest)
frame #40: BB016284-6E8E-3E1A-BA06-DC365DDF014A + 6384 (0x1b07758f0 in libdyld.dylib)

terminating with uncaught exception of type c10::Error: Could not find schema for aten::empty.memory_format
Exception raised from findSchemaOrThrow at /Users/liyixian/Desktop/pytorch/aten/src/ATen/core/dispatch/Dispatcher.cpp:81 (most recent call first):
frame #0: _ZN3c1010Dispatcher17findSchemaOrThrowEPKcS2_ + 620 (0x102b1495c in LibTorch_ImportTest)
frame #1: _ZN2at5emptyEN3c108ArrayRefIxEERKNS0_13TensorOptionsENS0_8optionalINS0_12MemoryFormatEEE + 184 (0x102bdf560 in LibTorch_ImportTest)
frame #2: _ZN5torch3jit9Unpickler15readInstructionEv + 4296 (0x103048f38 in LibTorch_ImportTest)
frame #3: _ZN5torch3jit9Unpickler3runEv + 68 (0x103047b0c in LibTorch_ImportTest)
frame #4: _ZN5torch3jit9Unpickler12parse_ivalueEv + 32 (0x1030478a4 in LibTorch_ImportTest)
frame #5: _ZN5torch3jit21readArchiveAndTensorsERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEN3c108optionalINS1_8functionIFNSA_13StrongTypePtrERKNSA_13QualifiedNameEEEEEENSB_INSC_IFNSA_13intrusive_ptrINSA_6ivalue6ObjectENSA_6detail34intrusive_target_default_null_typeISM_EEEESD_NSA_6IValueEEEEEENSB_INSA_6DeviceEEERN6caffe29serialize19PyTorchStreamReaderE + 816 (0x102ff5e10 in LibTorch_ImportTest)
frame #6: _ZN5torch3jit12_GLOBAL__N_124ScriptModuleDeserializer11readArchiveERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE + 276 (0x102ff84e4 in LibTorch_ImportTest)
frame #7: _ZN5torch3jit12_GLOBAL__N_124ScriptModuleDeserializer11deserializeEN3c108optionalINS3_6DeviceEEERNSt3__113unordered_mapINS7_12basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEESE_NS7_4hashISE_EENS7_8equal_toISE_EENSC_INS7_4pairIKSE_SE_EEEEEE + 516 (0x102ff6698 in LibTorch_ImportTest)
frame #8: _ZN5torch3jit4loadENSt3__110unique_ptrIN6caffe29serialize20ReadAdapterInterfaceENS1_14default_deleteIS5_EEEEN3c108optionalINS9_6DeviceEEERNS1_13unordered_mapINS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEESJ_NS1_4hashISJ_EENS1_8equal_toISJ_EENSH_INS1_4pairIKSJ_SJ_EEEEEE + 344 (0x102ff7338 in LibTorch_ImportTest)
frame #9: _ZN5torch3jit4loadERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEN3c108optionalINSA_6DeviceEEERNS1_13unordered_mapIS7_S7_NS1_4hashIS7_EENS1_8equal_toIS7_EENS5_INS1_4pairIS8_S7_EEEEEE + 116 (0x102ff7610 in LibTorch_ImportTest)
frame #10: -[ViewController + + (0x102ae8acc in LibTorch_ImportTest)
frame #11: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 4089432 (0x1b43e1658 in UIKitCore)
frame #12: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 4108520 (0x1b43e60e8 in UIKitCore)
frame #13: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 4109552 (0x1b43e64f0 in UIKitCore)
frame #14: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10902512 (0x1b4a60bf0 in UIKitCore)
frame #15: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10900268 (0x1b4a6032c in UIKitCore)
frame #16: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10904204 (0x1b4a6128c in UIKitCore)
frame #17: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10973456 (0x1b4a72110 in UIKitCore)
frame #18: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 13046956 (0x1b4c6c4ac in UIKitCore)
frame #19: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 269784 (0x1b403cdd8 in UIKitCore)
frame #20: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10657812 (0x1b4a25014 in UIKitCore)
frame #21: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 10658740 (0x1b4a253b4 in UIKitCore)
frame #22: 96D45309-8A6B-3139-B091-DCDEB4863DBA + 6071704 (0x1b45c5598 in UIKitCore)
frame #23: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 50716 (0x1b5afc61c in FrontBoardServices)
frame #24: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 201108 (0x1b5b21194 in FrontBoardServices)
frame #25: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 93180 (0x1b5b06bfc in FrontBoardServices)
frame #26: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 200272 (0x1b5b20e50 in FrontBoardServices)
frame #27: _dispatch_client_callout + 16 (0x1039b3730 in libdispatch.dylib)
frame #28: _dispatch_block_invoke_direct + 232 (0x1039b6bb0 in libdispatch.dylib)
frame #29: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 350288 (0x1b5b45850 in FrontBoardServices)
frame #30: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 349468 (0x1b5b4551c in FrontBoardServices)
frame #31: 8622E6E2-CB6A-30C5-A94B-4A4989ADA451 + 350788 (0x1b5b45a44 in FrontBoardServices)
frame #32: 707F86B5-2929-3667-B42C-3004C5E0C87D + 690904 (0x1b08f3ad8 in CoreFoundation)
frame #33: 707F86B5-2929-3667-B42C-3004C5E0C87D + 690736 (0x1b08f3a30 in CoreFoundation)
frame #34: 707F86B5-2929-3667-B42C-3004C5E0C87D + 688660 (0x1b08f3214 in CoreFoundation)
frame #35: 707F86B5-2929-3667-B42C-3004C5E0C87D + 668136 (0x1b08ee1e8 in CoreFoundation)
frame #36: CFRunLoopRunSpecific + 424 (0x1b08edba8 in CoreFoundation)
frame #37: GSEventRunModal + 160 (0x1baa64344 in GraphicsServices)
frame #38: UIApplicationMain + 1932 (0x1b4a293e4 in UIKitCore)
frame #39: main + 140 (0x102aedbf4 in LibTorch_ImportTest)
frame #40: BB016284-6E8E-3E1A-BA06-DC365DDF014A + 6384 (0x1b07758f0 in libdyld.dylib)
```

cc @gmagogsfm