pytorch - 💡(How to fix) Fix [AOTI] fail to run inference on GPU

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

warnings.warn(

Root Cause

import os
import torch
os.environ["AOTI_RUNTIME_CHECK_INPUTS"] = "1"
os.environ["TORCHINDUCTOR_NAN_ASSERTS"] = "1"
os.environ["PYTORCH_NO_CUDA_MEMORY_CACHING"] = "1"
os.environ["CUDA_LAUNCH_BLOCKING"] = "1"
os.environ["AOT_INDUCTOR_DEBUG_INTERMEDIATE_VALUE_PRINTER"] = "3"
class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = torch.nn.Linear(10, 16)
        self.relu = torch.nn.ReLU()
        self.fc2 = torch.nn.Linear(16, 1)
        self.sigmoid = torch.nn.Sigmoid()
    def forward(self, x):
        x = self.fc1(x)
        x = self.relu(x)
        x = self.fc2(x)
        x = self.sigmoid(x)
        return x
with torch.no_grad():
    #device = "cpu" #test
    device = "cuda"
    model = Model().to(device=device)
    example_inputs=(torch.randn(8, 10, device=device),)
    batch_dim = torch.export.Dim("batch", min=1, max=1024)
    # [Optional] Specify the first dimension of the input x as dynamic.
    exported = torch.export.export(model, example_inputs, dynamic_shapes={"x": {0: batch_dim}})
    print("Model exported successfully.", flush=True)
    # [Note] In this example we directly feed the exported module to aoti_compile_and_package.
    # Depending on your use case, e.g. if your training platform and inference platform
    # are different, you may choose to save the exported model using torch.export.save and
    # then load it back using torch.export.load on your inference platform to run AOT compilation.
    output_path = torch._inductor.aoti_compile_and_package(
        exported,
        # [Optional] Specify the generated shared library path. If not specified,
        # the generated artifact is stored in your system temp directory.
        package_path=os.path.join(os.getcwd(), "model.pt2"),
    )
    print(f"Saved compiled artifact to {output_path}", flush=True)
    model = torch._inductor.aoti_load_package(os.path.join(os.getcwd(), "model.pt2"))
    print("Compiled model loaded successfully.", flush=True)
    print(model(torch.randn(8, 10, device=device)), flush=True)

This is exactly the same code as in the example and can be run on CPU xorrectly. However, when I try run it with GPU, I get:

Model exported successfully.
/home/twsvqtx771/miniconda3/envs/unifolm-wma/lib/python3.10/site-packages/torch/_inductor/compile_fx.py:312: UserWarning: TensorFloat32 tensor cores for float32 matrix multiplication available but not enabled. Consider setting `torch.set_float32_matmul_precision('high')` for better performance.
  warnings.warn(
Saved compiled artifact to /home/twsvqtx771/2026-SC/model.pt2
Compiled model loaded successfully.
[ before_launch: aoti_torch_cuda_mm_out ]
[ after_launch: aoti_torch_cuda_mm_out ]
[ before_launch: triton_poi_fused_addmm_relu_0 ]
Segmentation fault (core dumped)

Note that the last three lines with [] will not even show up when using slurm (because of block buffer, maybe?).

Code Example

This is exactly the same code as in the example and can be run on CPU xorrectly. However, when I try run it with GPU, I get:
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Trying to run the official example at https://docs.pytorch.org/docs/2.9/torch.compiler_aot_inductor.html#torch._inductor.aoti_load_package but still get segfault without useful information to fix it.

Environment Pytorch version: 2.9.1 / 2.6.0 CUDA: 12.6 / 12.1

import os
import torch
os.environ["AOTI_RUNTIME_CHECK_INPUTS"] = "1"
os.environ["TORCHINDUCTOR_NAN_ASSERTS"] = "1"
os.environ["PYTORCH_NO_CUDA_MEMORY_CACHING"] = "1"
os.environ["CUDA_LAUNCH_BLOCKING"] = "1"
os.environ["AOT_INDUCTOR_DEBUG_INTERMEDIATE_VALUE_PRINTER"] = "3"
class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = torch.nn.Linear(10, 16)
        self.relu = torch.nn.ReLU()
        self.fc2 = torch.nn.Linear(16, 1)
        self.sigmoid = torch.nn.Sigmoid()
    def forward(self, x):
        x = self.fc1(x)
        x = self.relu(x)
        x = self.fc2(x)
        x = self.sigmoid(x)
        return x
with torch.no_grad():
    #device = "cpu" #test
    device = "cuda"
    model = Model().to(device=device)
    example_inputs=(torch.randn(8, 10, device=device),)
    batch_dim = torch.export.Dim("batch", min=1, max=1024)
    # [Optional] Specify the first dimension of the input x as dynamic.
    exported = torch.export.export(model, example_inputs, dynamic_shapes={"x": {0: batch_dim}})
    print("Model exported successfully.", flush=True)
    # [Note] In this example we directly feed the exported module to aoti_compile_and_package.
    # Depending on your use case, e.g. if your training platform and inference platform
    # are different, you may choose to save the exported model using torch.export.save and
    # then load it back using torch.export.load on your inference platform to run AOT compilation.
    output_path = torch._inductor.aoti_compile_and_package(
        exported,
        # [Optional] Specify the generated shared library path. If not specified,
        # the generated artifact is stored in your system temp directory.
        package_path=os.path.join(os.getcwd(), "model.pt2"),
    )
    print(f"Saved compiled artifact to {output_path}", flush=True)
    model = torch._inductor.aoti_load_package(os.path.join(os.getcwd(), "model.pt2"))
    print("Compiled model loaded successfully.", flush=True)
    print(model(torch.randn(8, 10, device=device)), flush=True)

This is exactly the same code as in the example and can be run on CPU xorrectly. However, when I try run it with GPU, I get:

Model exported successfully.
/home/twsvqtx771/miniconda3/envs/unifolm-wma/lib/python3.10/site-packages/torch/_inductor/compile_fx.py:312: UserWarning: TensorFloat32 tensor cores for float32 matrix multiplication available but not enabled. Consider setting `torch.set_float32_matmul_precision('high')` for better performance.
  warnings.warn(
Saved compiled artifact to /home/twsvqtx771/2026-SC/model.pt2
Compiled model loaded successfully.
[ before_launch: aoti_torch_cuda_mm_out ]
[ after_launch: aoti_torch_cuda_mm_out ]
[ before_launch: triton_poi_fused_addmm_relu_0 ]
Segmentation fault (core dumped)

Note that the last three lines with [] will not even show up when using slurm (because of block buffer, maybe?).

Versions

Collecting environment information... PyTorch version: 2.9.1+cu126 Is debug build: False CUDA used to build PyTorch: 12.6 ROCM used to build PyTorch: N/A

OS: Red Hat Enterprise Linux release 8.10 (Ootpa) (x86_64) GCC version: (GCC) 8.5.0 20210514 (Red Hat 8.5.0-28) Clang version: 20.1.8 ( 20.1.8-2.module+el8.10.0+23372+3f2ea6fa) CMake version: version 3.20.2 Libc version: glibc-2.28

Python version: 3.10.18 (main, Jun 5 2025, 13:14:17) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-4.18.0-513.24.1.el8_9.x86_64-x86_64-with-glibc2.28 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: GPU models and configuration: GPU 0: NVIDIA H100 PCIe GPU 1: NVIDIA H100 PCIe

Nvidia driver version: 550.127.08 cuDNN version: Could not collect Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True Caching allocator config: N/A

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 224 On-line CPU(s) list: 0-223 Thread(s) per core: 2 Core(s) per socket: 56 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 143 Model name: Intel(R) Xeon(R) Platinum 8480+ Stepping: 8 CPU MHz: 2000.000 CPU max MHz: 3800.0000 CPU min MHz: 800.0000 BogoMIPS: 4000.00 Virtualization: VT-x L1d cache: 48K L1i cache: 32K L2 cache: 2048K L3 cache: 107520K NUMA node0 CPU(s): 0-55,112-167 NUMA node1 CPU(s): 56-111,168-223 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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities

Versions of relevant libraries: [pip3] mypy_extensions==1.1.0 [pip3] numpy==1.24.2 [pip3] nvidia-cublas-cu12==12.6.4.1 [pip3] nvidia-cuda-cupti-cu12==12.6.80 [pip3] nvidia-cuda-nvrtc-cu12==12.6.77 [pip3] nvidia-cuda-runtime-cu12==12.6.77 [pip3] nvidia-cudnn-cu12==9.10.2.21 [pip3] nvidia-cufft-cu12==11.3.0.4 [pip3] nvidia-curand-cu12==10.3.7.77 [pip3] nvidia-cusolver-cu12==11.7.1.2 [pip3] nvidia-cusparse-cu12==12.5.4.2 [pip3] nvidia-cusparselt-cu12==0.7.1 [pip3] nvidia-nccl-cu12==2.27.5 [pip3] nvidia-nvjitlink-cu12==12.6.85 [pip3] nvidia-nvtx-cu12==12.6.77 [pip3] open-clip-torch==2.22.0 [pip3] optree==0.18.0 [pip3] pytorch-lightning==1.9.3 [pip3] torch==2.9.1+cu126 [pip3] torch_c_dlpack_ext==0.1.4 [pip3] torchmetrics==1.8.2 [pip3] torchvision==0.24.1+cu126 [pip3] triton==3.5.1 [conda] numpy 1.24.2 pypi_0 pypi [conda] nvidia-cublas-cu12 12.6.4.1 pypi_0 pypi [conda] nvidia-cuda-cupti-cu12 12.6.80 pypi_0 pypi [conda] nvidia-cuda-nvrtc-cu12 12.6.77 pypi_0 pypi [conda] nvidia-cuda-runtime-cu12 12.6.77 pypi_0 pypi [conda] nvidia-cudnn-cu12 9.10.2.21 pypi_0 pypi [conda] nvidia-cufft-cu12 11.3.0.4 pypi_0 pypi [conda] nvidia-curand-cu12 10.3.7.77 pypi_0 pypi [conda] nvidia-cusolver-cu12 11.7.1.2 pypi_0 pypi [conda] nvidia-cusparse-cu12 12.5.4.2 pypi_0 pypi [conda] nvidia-cusparselt-cu12 0.7.1 pypi_0 pypi [conda] nvidia-nccl-cu12 2.27.5 pypi_0 pypi [conda] nvidia-nvjitlink-cu12 12.6.85 pypi_0 pypi [conda] nvidia-nvtx-cu12 12.6.77 pypi_0 pypi [conda] open-clip-torch 2.22.0 pypi_0 pypi [conda] optree 0.18.0 pypi_0 pypi [conda] pytorch-lightning 1.9.3 pypi_0 pypi [conda] torch 2.9.1+cu126 pypi_0 pypi [conda] torch-c-dlpack-ext 0.1.4 pypi_0 pypi [conda] torchmetrics 1.8.2 pypi_0 pypi [conda] torchvision 0.24.1+cu126 pypi_0 pypi [conda] triton 3.5.1 pypi_0 pypi

cc @ptrblck @msaroufim @eqy @jerryzh168 @tinglvv @nWEIdia @chauhang @penguinwu @avikchaudhuri @zhxchen17 @tugsbayasgalan @angelayi @ydwu4 @desertfire @yushangdi @benjaminglass1 @jataylo @iupaikov-amd

extent analysis

TL;DR

The segmentation fault when running the PyTorch model on GPU may be related to the CUDA or cuDNN versions, and setting torch.set_float32_matmul_precision('high') might improve performance but may not resolve the issue.

Guidance

  • Verify that the CUDA and cuDNN versions are compatible with the PyTorch version.
  • Check the NVIDIA driver version and ensure it is up-to-date.
  • Consider setting torch.set_float32_matmul_precision('high') as suggested in the warning message to see if it improves performance.
  • Try running the model on CPU to isolate the issue to the GPU.

Example

No specific code example is provided as the issue seems to be related to the environment and library versions rather than the code itself.

Notes

The issue may be related to the specific hardware or environment setup, and further debugging may be required to identify the root cause.

Recommendation

Apply workaround: Try setting torch.set_float32_matmul_precision('high') and verify if the issue persists. If the issue remains, consider upgrading or downgrading the CUDA or cuDNN versions to ensure compatibility with the PyTorch version.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING