Description
🐛 Describe the bug
There are some strange failure cases for running inference on different tensors for an AOTI compiled model.
I compiled the model to run on a dynamic batch size and 36 fixed channels, 1024 height, and 1024 width.
This succeeds when run on it's own
Inference on 9 channels sliced from 36 channels
import torch
import fsspec
import io
model_uri = 's3://wherobots-ai/models/professional/semantic-segmentation/solar-satlas-sentinel2/inductor/gpu/model.pt2'
with fsspec.open(model_uri, "rb") as f:
if model_uri.endswith(".pt2"):
with io.BytesIO(f.read()) as buffer:
model = torch._inductor.aoti_load_package(buffer)
t = torch.rand(1, 36, 1024, 1024).to('cuda')
print("Input shape", t[:,0:9,...].shape)
model(t[:,0:9,...])
this fails when run on its own
Inference on new 9 channels tensor
import torch
import fsspec
import io
model_uri = 's3://wherobots-ai/models/professional/semantic-segmentation/solar-satlas-sentinel2/inductor/gpu/model.pt2'
with fsspec.open(model_uri, "rb") as f:
if model_uri.endswith(".pt2"):
with io.BytesIO(f.read()) as buffer:
model = torch._inductor.aoti_load_package(buffer)
t = torch.rand(1, 9, 1024, 1024).to('cuda')
print("Input shape", t.shape)
model(t)
But when I run the example that succeeds and then run the example above that fails on it's own, both succeed
import torch
import fsspec
import io
model_uri = 's3://model-uri/model.pt2'
with fsspec.open(model_uri, "rb") as f:
if model_uri.endswith(".pt2"):
with io.BytesIO(f.read()) as buffer:
model = torch._inductor.aoti_load_package(buffer)
t = torch.rand(1, 36, 1024, 1024).to('cuda')
print("Input shape", t[:,0:9,...].shape)
model(t[:,0:9,...])
import torch
import fsspec
import io
model_uri = 's3://model-uri/model.pt2'
with fsspec.open(model_uri, "rb") as f:
if model_uri.endswith(".pt2"):
with io.BytesIO(f.read()) as buffer:
model = torch._inductor.aoti_load_package(buffer)
t = torch.rand(1, 9, 1024, 1024).to('cuda')
print("Input shape", t.shape)
model(t)
It'd be helpful to have more consistent behavior and more helpful error logs that are easier to interpret. The
CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)
error indicates that there is a shape mismatch between the input and what the model expects I think.
Error logs
traceback for the 9 channel slice
Input shape torch.Size([1, 9, 1024, 1024])
[E520 15:44:23.953122879 c_shim_cuda.cpp:1141] Exception in aoti_torch: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`
Exception raised from gemm_internal_cublas<float> at [/pytorch/aten/src/ATen/cuda/CUDABlas.cpp:866](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/pytorch/aten/src/ATen/cuda/CUDABlas.cpp:866) (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x98 (0x77f00ed785e8 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libc10.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libc10.so))
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0xe0 (0x77f00ed0d4a2 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libc10.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libc10.so))
frame #2: <unknown function> + 0x3aa2dab (0x77efb1ca2dab in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so))
frame #3: <unknown function> + 0x3b32f13 (0x77efb1d32f13 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so))
frame #4: at::native::structured_mm_out_cuda::impl(at::Tensor const&, at::Tensor const&, at::Tensor const&) + 0x4f (0x77efb1d342ff in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so))
frame #5: <unknown function> + 0x38ef8ee (0x77efb1aef8ee in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so))
frame #6: aoti_torch_cuda_mm_out + 0x77 (0x77efaf462b37 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so))
frame #7: torch::aot_inductor::AOTInductorModel::run_impl(AtenTensorOpaque**, AtenTensorOpaque**, CUstream_st*, AOTIProxyExecutorOpaque*) + 0x6021f (0x77eee6e8c8df in [/tmp/RDNtXT/data/aotinductor/model/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/tmp/RDNtXT/data/aotinductor/model/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.so))
frame #8: torch::aot_inductor::AOTInductorModelContainer::run(AtenTensorOpaque**, AtenTensorOpaque**, CUstream_st*, AOTIProxyExecutorOpaque*) + 0xf6 (0x77eee6f2a996 in [/tmp/RDNtXT/data/aotinductor/model/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/tmp/RDNtXT/data/aotinductor/model/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.so))
frame #9: AOTInductorModelContainerRun + 0x7f (0x77eee6f0a28f in [/tmp/RDNtXT/data/aotinductor/model/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/tmp/RDNtXT/data/aotinductor/model/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.so))
frame #10: torch::inductor::AOTIModelContainerRunner::run_impl(std::vector<AtenTensorOpaque*, std::allocator<AtenTensorOpaque*> >&, void*) + 0xf6 (0x77eff1a816c6 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so))
frame #11: torch::inductor::AOTIModelContainerRunnerCuda::run_impl(std::vector<AtenTensorOpaque*, std::allocator<AtenTensorOpaque*> >&, void*) + 0x1e (0x77efb1db1e1e in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cuda.so))
frame #12: torch::inductor::AOTIModelContainerRunner::boxed_run(std::vector<at::Tensor, std::allocator<at::Tensor> >&&, void*) + 0x78 (0x77eff1a81538 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so))
frame #13: torch::inductor::AOTIModelPackageLoader::boxed_run(std::vector<at::Tensor, std::allocator<at::Tensor> >&&, void*) + 0xe (0x77eff1a6cf6e in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so))
frame #14: <unknown function> + 0x8096a4 (0x77f00e2096a4 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_python.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_python.so))
frame #15: <unknown function> + 0x80a2f9 (0x77f00e20a2f9 in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_python.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_python.so))
frame #16: <unknown function> + 0x38a0cc (0x77f00dd8a0cc in [/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_python.so](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/home/rave/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/lib/libtorch_python.so))
<omitting python frames>
Error: aoti_torch_cuda_mm_out(buf2067, tmp_tensor_handle_1071_raii, tmp_tensor_handle_1072_raii) API call failed at [/tmp/torchinductor_runner/c4pm2ehn5ghyaxiv254gzv2odvkuskhwaeqgaqsxhqksjjrns3p7/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.cpp](https://vscode-remote+ssh-002dremote-002bchattyryan-002ecom.vscode-resource.vscode-cdn.net/tmp/torchinductor_runner/c4pm2ehn5ghyaxiv254gzv2odvkuskhwaeqgaqsxhqksjjrns3p7/cwxajztudm3k2rjeox6enjqeac73rrvwz57rfe2lmp4ybbh7jnbe.cpp), line 21705
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[1], line 11
9 t = torch.rand(1, 9, 1024, 1024).to('cuda')
10 print("Input shape", t.shape)
---> 11 model(t)
File ~/wherobots-executors-demo/.venv/lib/python3.11/site-packages/torch/_inductor/package/package.py:251, in AOTICompiledModel.__call__(self, *args, **kwargs)
249 flat_inputs = pytree.tree_flatten((args, reorder_kwargs(kwargs, in_spec)))[0]
250 flat_inputs = [x for x in flat_inputs if isinstance(x, torch.Tensor)]
--> 251 flat_outputs = self.loader.boxed_run(flat_inputs) # type: ignore[attr-defined]
252 return pytree.tree_unflatten(flat_outputs, out_spec)
RuntimeError: run_func_( container_handle_, input_handles.data(), input_handles.size(), output_handles.data(), output_handles.size(), reinterpret_cast<AOTInductorStreamHandle>(stream_handle), proxy_executor_handle_) API call failed at /pytorch/torch/csrc/inductor/aoti_runner/model_container_runner.cpp, line 106
after hitting this error I get illegal memory access errors when trying to do anything with torch cuda tensors
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 t = torch.rand(1, 9, 1024, 1024).to('cuda')
Ru
8000
ntimeError: CUDA error: an illegal memory access was encountered
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
Versions
→ uv run python collect_env.py
Collecting environment information...
PyTorch version: 2.7.0+cu126
Is debug build: False
CUDA used to build PyTorch: 12.6
ROCM used to build PyTorch: N/A
OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35
Python version: 3.11.11 (main, Mar 17 2025, 21:02:09) [Clang 20.1.0 ] (64-bit runtime)
Python platform: Linux-6.8.0-59-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 RTX 3090
Nvidia driver version: 550.144.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.0.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 12
On-line CPU(s) list: 0-11
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
CPU family: 6
Model: 158
Thread(s) per core: 2
Core(s) per socket: 6
Socket(s): 1
Stepping: 10
CPU max MHz: 4600.0000
CPU min MHz: 800.0000
BogoMIPS: 6399.96
Flags: 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 art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault pti ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp vnmi md_clear flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 192 KiB (6 instances)
L1i cache: 192 KiB (6 instances)
L2 cache: 1.5 MiB (6 instances)
L3 cache: 12 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-11
Vulnerability Gather data sampling: Mitigation; Microcode
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: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; IBRS
Vulnerability Spec rstack overflow: 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; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Mitigation; Microcode
Vulnerability Tsx async abort: Mitigation; TSX disabled
Versions of relevant libraries:
[pip3] Could not collect
[conda] No relevant packages
cc @chauhang @penguinwu @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4 @desertfire @chenyang78 @yushangdi @benjaminglass1