Yolov5 model not loading if CUDA enabled

ccas007: <p>I am trying to get a Yolov5 model to run with CUDA in C++ using the LibTorch library.  The model was converted to a torchscript model by using the python converter script.  I was able to get the model to work in CPU mode without a problem.  In all cases I am just preloading parameters not doing any training.</p>
<p>With CUDA enabled, however, I get this result:</p>
<blockquote>
<p>Blockquote<br>
[ObjectDetector()] torch::jit::load( yolov5s.torchscript.pt ); …<br>
Could not run ‘aten::empty_strided’ with arguments from the ‘CUDA’ backend. ‘aten::empty_strided’ is only available for these backends: [CPU, BackendSelect, Named, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, Autocast, Batched, VmapMode].</p>
</blockquote>
<p>CPU: registered at aten\src\ATen\CPUType.cpp:2127 [kernel]<br>
BackendSelect: registered at aten\src\ATen\BackendSelectRegister.cpp:761 [kernel]<br>
Named: registered at …..\aten\src\ATen\core\NamedRegistrations.cpp:7 [backend fallback]<br>
AutogradOther: registered at …..\torch\csrc\autograd\generated\VariableType_0.cpp:7974 [autograd kernel]<br>
AutogradCPU: registered at …..\torch\csrc\autograd\generated\VariableType_0.cpp:7974 [autograd kernel]<br>
AutogradCUDA: registered at …..\torch\csrc\autograd\generated\VariableType_0.cpp:7974 [autograd kernel]<br>
AutogradXLA: registered at …..\torch\csrc\autograd\generated\VariableType_0.cpp:7974 [autograd kernel]<br>
AutogradPrivateUse1: registered at …..\torch\csrc\autograd\generated\VariableType_0.cpp:7974 [autograd kernel]<br>
AutogradPrivateUse2: registered at …..\torch\csrc\autograd\generated\VariableType_0.cpp:7974 [autograd kernel]<br>
AutogradPrivateUse3: registered at …..\torch\csrc\autograd\generated\VariableType_0.cpp:7974 [autograd kernel]<br>
Tracer: registered at …..\torch\csrc\autograd\generated\TraceType_0.cpp:9341 [kernel]<br>
Autocast: fallthrough registered at …..\aten\src\ATen\autocast_mode.cpp:254 [backend fallback]<br>
Batched: registered at …..\aten\src\ATen\BatchingRegistrations.cpp:511 [backend fallback]<br>
VmapMode: fallthrough registered at …..\aten\src\ATen\VmapModeRegistrations.cpp:33 [backend fallback]</p>
<p>Exception raised from reportError at …..\aten\src\ATen\core\dispatch\OperatorEntry.cpp:363 (most recent call first):<br>
00007FFE6357A7B200007FFE6357A750 c10.dll!c10::Error::Error [ @ ]<br>
00007FFDF269D4E500007FFDF269D2F0 torch_cpu.dll!c10::impl::OperatorEntry::reportError [ @ ]<br>
00007FFDF2A69C9700007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2A8E36A00007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2A8C07900007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2A69B9600007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2C3D3C900007FFDF2C3D1C0 torch_cpu.dll!at::empty_strided [ @ ]<br>
00007FFDF3B4F19300007FFDF3B42EE0 torch_cpu.dll!torch::autograd::GraphRoot::apply [ @ ]<br>
00007FFDF2A8C07900007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2A69B9600007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2A8E36A00007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2A8C07900007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2A69B9600007FFDF2A63920 torch_cpu.dll!at::native::mkldnn_sigmoid_ [ @ ]<br>
00007FFDF2C3D3C900007FFDF2C3D1C0 torch_cpu.dll!at::empty_strided [ @ ]<br>
00007FFDF28E8EFE00007FFDF28E8BD0 torch_cpu.dll!at::native::to_dense_backward [ @ ]<br>
00007FFDF28E8AF500007FFDF28E89C0 torch_cpu.dll!at::native::to [ @ ]<br>
00007FFDF2D3D3CF00007FFDF2C9B090 torch_cpu.dll!at::zeros_out [ @ ]<br>
00007FFDF262086500007FFDF260AE70 torch_cpu.dll!at::BatchedTensorImpl::strides [ @ ]<br>
00007FFDF2D53EDB00007FFDF2D46BB0 torch_cpu.dll!at::is_custom_op [ @ ]<br>
00007FFDF2D8E61D00007FFDF2D8E4F0 torch_cpu.dll!at::Tensor::to [ @ ]<br>
00007FFDF4153E4B00007FFDF4152980 torch_cpu.dll!torch::jit::Unpickler::readInstruction [ @ ]<br>
00007FFDF4156BF000007FFDF4156B20 torch_cpu.dll!torch::jit::Unpickler::run [ @ ]<br>
00007FFDF415145200007FFDF4151420 torch_cpu.dll!torch::jit::Unpickler::parse_ivalue [ @ ]<br>
00007FFDF4125DD300007FFDF41259E0 torch_cpu.dll!torch::jit::readArchiveAndTensors [ @ ]<br>
00007FFDF41259AF00007FFDF41240E0 torch_cpu.dll!torch::jit::load [ @ ]<br>
00007FFDF412329400007FFDF41125A0 torch_cpu.dll!torch::jit::hasGradientInfoForSchema [ @ ]<br>
00007FFDF412429300007FFDF41240E0 torch_cpu.dll!torch::jit::load [ @ ]<br>
00007FFDF41240CB00007FFDF4124050 torch_cpu.dll!torch::jit::load [ @ ]<br>
00007FF6E7FC8A5F00007FF6E7FC87E0 PytorchTestTwo.exe!main [C:\Leidos\SW\PytorchTestTwo\PytorchTestTwo.cpp @ 495]<br>
00007FF6E7FD4B4400007FF6E7FD4A38 PytorchTestTwo.exe!__scrt_common_main_seh [d:\agent_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288]<br>
00007FFEA509703400007FFEA5097020 KERNEL32.DLL!BaseThreadInitThunk [ @ ]<br>
00007FFEA6CA265100007FFEA6CA2630 ntdll.dll!RtlUserThreadStart [ @ ]</p>
<p>I have tried different versions of libTorch and different CUDAs but things don’t seem to change.  Is there any advice on what might be giving this error and how to fix it?</p>
<p>I also did get this model to run in Python using CUDA previously, though it was not exported to torchscript for that.</p>