Could not run 'aten::empty_strided' with arguments from the 'CUDA' backend

I tried to load model in c++ with jit but the error raised:
error raised in this line :
model = torch::jit::load("Resource/model.pt");

Could not run 'aten::empty_strided' with arguments from the 'CUDA' 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, BackendSelect, Named, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradNestedTensor, UNKNOWN_TENSOR_TYPE_ID, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, Autocast, Batched, VmapMode].

CPU: registered at aten\src\ATen\RegisterCPU.cpp:5925 [kernel]
BackendSelect: registered at aten\src\ATen\RegisterBackendSelect.cpp:596 [kernel]
Named: registered at ..\..\aten\src\ATen\core\NamedRegistrations.cpp:7 [backend fallback]
AutogradOther: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
AutogradCPU: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
AutogradCUDA: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
AutogradXLA: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
AutogradNestedTensor: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
UNKNOWN_TENSOR_TYPE_ID: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
AutogradPrivateUse1: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
AutogradPrivateUse2: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
AutogradPrivateUse3: registered at ..\..\torch\csrc\autograd\generated\VariableType_0.cpp:9273 [autograd kernel]
Tracer: registered at ..\..\torch\csrc\autograd\generated\TraceType_0.cpp:10499 [kernel]
Autocast: fallthrough registered at ..\..\aten\src\ATen\autocast_mode.cpp:250 [backend fallback]
Batched: registered at ..\..\aten\src\ATen\BatchingRegistrations.cpp:1016 [backend fallback]
VmapMode: fallthrough registered at ..\..\aten\src\ATen\VmapModeRegistrations.cpp:33 [backend fallback]

Exception raised from reportError at ..\..\aten\src\ATen\core\dispatch\OperatorEntry.cpp:397 (most recent call first):
00007FFB821E0F9200007FFB821E0F30 c10.dll!c10::Error::Error [<unknown file> @ <unknown line number>]
00007FFB821E0C0E00007FFB821E0BC0 c10.dll!c10::detail::torchCheckFail [<unknown file> @ <unknown line number>]
00007FFB3E0C357E00007FFB3E0C33C0 torch_cpu.dll!c10::impl::OperatorEntry::reportError [<unknown file> @ <unknown line number>]
00007FFB3E55517D00007FFB3E4D6FA0 torch_cpu.dll!at::native::mkldnn_sigmoid_ [<unknown file> @ <unknown line number>]
00007FFB3E749A6900007FFB3E72BAB0 torch_cpu.dll!at::zeros_outf [<unknown file> @ <unknown line number>]
00007FFB3E74625D00007FFB3E72BAB0 torch_cpu.dll!at::zeros_outf [<unknown file> @ <unknown line number>]
00007FFB3E53A67900007FFB3E4D6FA0 torch_cpu.dll!at::native::mkldnn_sigmoid_ [<unknown file> @ <unknown line number>]
00007FFB3E68127700007FFB3E681150 torch_cpu.dll!at::empty_strided [<unknown file> @ <unknown line number>]
00007FFB3E3469A300007FFB3E346630 torch_cpu.dll!at::native::to_dense_backward [<unknown file> @ <unknown line number>]
00007FFB3E34658100007FFB3E346470 torch_cpu.dll!at::native::to [<unknown file> @ <unknown line number>]
00007FFB3E94A9CD00007FFB3E72BAB0 torch_cpu.dll!at::zeros_outf [<unknown file> @ <unknown line number>]
00007FFB3E913B0200007FFB3E72BAB0 torch_cpu.dll!at::zeros_outf [<unknown file> @ <unknown line number>]
00007FFB3E99239400007FFB3E985C80 torch_cpu.dll!at::is_custom_op [<unknown file> @ <unknown line number>]
00007FFB3E9E4E8B00007FFB3E9E4DE0 torch_cpu.dll!at::Tensor::to [<unknown file> @ <unknown line number>]
00007FFB400693F000007FFB400680A0 torch_cpu.dll!torch::jit::Unpickler::readInstruction [<unknown file> @ <unknown line number>]
00007FFB4006BBE800007FFB4006BA60 torch_cpu.dll!torch::jit::Unpickler::run [<unknown file> @ <unknown line number>]
00007FFB40066CF200007FFB40066CC0 torch_cpu.dll!torch::jit::Unpickler::parse_ivalue [<unknown file> @ <unknown line number>]
00007FFB4003A0E500007FFB40039D00 torch_cpu.dll!torch::jit::readArchiveAndTensors [<unknown file> @ <unknown line number>]
00007FFB40039CD300007FFB40038460 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FFB40036B3600007FFB400247C0 torch_cpu.dll!torch::jit::hasGradientInfoForSchema [<unknown file> @ <unknown line number>]
00007FFB4003868200007FFB40038460 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FFB4003810400007FFB40037FE0 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FF6C222A2E500007FF6C222A270 BgRemover.exe!U2Net::U2Net [D:\MyWorks\C++\BgRemover\BgRemover\U2Net.cpp @ 75]
00007FF6C222509100007FF6C2224E00 BgRemover.exe!SegmentationNextDetection [D:\MyWorks\C++\BgRemover\BgRemover\BgRemover.cpp @ 53]
00007FF6C2225B0900007FF6C2225B00 BgRemover.exe!main [D:\MyWorks\C++\BgRemover\BgRemover\BgRemover.cpp @ 117]
00007FF6C222B57400007FF6C222B468 BgRemover.exe!__scrt_common_main_seh [D:\agent\_work\13\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288]
00007FFB97AD703400007FFB97AD7020 KERNEL32.DLL!BaseThreadInitThunk [<unknown file> @ <unknown line number>]
00007FFB98FA265100007FFB98FA2630 ntdll.dll!RtlUserThreadStart [<unknown file> @ <unknown line number>]

I found solution in this link

Hey, can you describe the solution. The link you provided is not working anymore.

2 Likes

This is the error I’m getting in android while loading the model.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example.cataractdetectionapp/com.android.example.cataractdetectionapp.InferenceActivity}:

com.facebook.jni.CppException: Could not run 'aten::empty_strided' with arguments from the 'CUDA' 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, Vulkan, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].

CPU: registered at aten/src/ATen/RegisterCPU.cpp:18433 [kernel]

Vulkan: registered at ../aten/src/ATen/native/vulkan/ops/Factory.cpp:47 [kernel]

BackendSelect: registered at aten/src/ATen/RegisterBackendSelect.cpp:665 [kernel]

Python: registered at ../aten/src/ATen/core/PythonFallbackKernel.cpp:47 [backend fallback]

Named: registered at ../aten/src/ATen/core/NamedRegistrations.cpp:7 [backend fallback]

Conjugate: fallthrough registered at ../aten/src/ATen/ConjugateFallback.cpp:22 [kernel]

Negative: fallthrough registered at ../aten/src/ATen/native/NegateFallback.cpp:22 [kernel]

ADInplaceOrView: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:64 [backend fallback]

AutogradOther: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:35 [backend fallback]

AutogradCPU: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:39 [backend fallback]

AutogradCUDA: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:47 [backend fallback]

AutogradXLA: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:51 [backend fallback]

AutogradLazy: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:55 [backend fallback]

AutogradXPU: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:43 [backend fallback]

AutogradMLC: fallthrough registered at ../aten/src/ATen/core/VariableFallbackKernel.cpp:59 [backend fallback]

UNKNOWN_TENSOR_TYPE_ID: fallthrough registered at ../aten/src/ATen/autocast_mode.cpp:466 [backend fallback]

Autocast: fallthrough registered at ../aten/src/ATen/autocast_mode.cpp:305 [backend fallback]

Batched: registered at ../aten/src/ATen/BatchingRegistrations.cpp:1016 [backend fallback]

VmapMode: fallthrough registered at ../aten/src/ATen/VmapModeRegistrations.cpp:33 [backend fallback]

I used the below code for loading the module:

Module module = LiteModuleLoader.load(assetFilePath(getApplicationContext(),
"Model.ptl"));

The dependencies I’m using for Pytorch are as follows:

implementation 'org.pytorch:pytorch_android_lite:1.10.0'

implementation 'org.pytorch:pytorch_android_torchvision:1.10.0'