#192510·pytorch

[inductor][aot_autograd] user defined triton kernels view output buffer storages are not preserved

Author: kundaMwizaCreated Aug 7, 2026Updated Sep 17, 2026
Labelsmodule: crashtriagedmodule: correctness (silent)module: functionalizationoncall: pt2module: pt2-dispatchermodule: user tritonbot-triaged

Describe the bug

For torch compiled user defined triton kernels, views of tensors that are passed as output buffers e.g.

backing = torch.empty(1024)
view = backing[:256]
triton_kernel(..., view)

do not have their backing storage preserved during functionalisation: see https://github.com/pytorch/pytorch/blob/b318b41aa5230e0be571b71ff2f27663e5e22809/torch/_higher_order_ops/triton_kernel_wrap.py#L1713. The consequence of this is that the python wrapper will use an output buffer that is smaller than that written to in the triton kernel i.e. the padding is effectively removed. For CUDA, this does not surface with a segfault, but other triton backends e.g. Triton CPU segfault.

The above pattern is done in https://github.com/triton-lang/triton/blob/5bcfc513ddbbc64f2688dfb15a4d824c56a9649a/python/triton_kernels/triton_kernels/tensor_details/ragged_tensor.py#L183, with padding done in https://github.com/triton-lang/triton/blob/5bcfc513ddbbc64f2688dfb15a4d824c56a9649a/python/triton_kernels/triton_kernels/tensor_details/ragged_tensor.py#L192 to avoid masking stores.

Small CUDA repro showing that the kernel does not write to the full extent of the backing storage with torch compile:

#!/usr/bin/env python3
from __future__ import annotations

import os
from pathlib import Path

import torch
import triton
import triton.language as tl


VIEW_ELEMS = 2053
PADDED_ELEMS = ((2053 + 255) // 256) * 256
BLOCK = 256

# Simplified repro based on 
# https://github.com/triton-lang/triton/blob/5bcfc513ddbbc64f2688dfb15a4d824c56a9649a/python/triton_kernels/triton_kernels/tensor_details/ragged_tensor.py#L183
@triton.jit
def padded_write_kernel(x, padded, BLOCK: tl.constexpr):
    base = 0
    while base < padded:
        offs = base + tl.arange(0, BLOCK)
        tl.store(x + offs, 1.0)
        base += BLOCK


def fn(base: torch.Tensor) -> torch.Tensor:
    view = base[:VIEW_ELEMS]
    padded_write_kernel[(1,)](view, PADDED_ELEMS, BLOCK=BLOCK)
    return base


def main() -> None:
    base = torch.zeros(PADDED_ELEMS, dtype=torch.float32).to("cuda")

    print("eager start", flush=True)
    eager_out = fn(base.clone())
    print(
        "eager tail updated",
        bool(torch.all(eager_out[VIEW_ELEMS:PADDED_ELEMS] == 1)),
        flush=True,
    )

    compiled = torch.compile(fn, backend="inductor", fullgraph=True)
    print("compiled start", flush=True)
    compiled_out = compiled(base.clone())
    print(
        "compiled tail updated",
        bool(torch.all(compiled_out[VIEW_ELEMS:PADDED_ELEMS] == 1)),
        flush=True,
    )


if __name__ == "__main__":
    main()

A fix is to clone and preserve the backing storage size for views, however this might lead to performance regressions in cases when clone + generalized_scatter ops are not removed during the reinplace pass. Another alternative is to modify the triton kernel, however this then highlights a difference between eager and torch compile execution of the same code.

Versions

PyTorch version: 2.14.0.dev20260806+cu132
Is debug build: False
CUDA used to build PyTorch: 13.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jan 26 2026, 14:55:28) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.8.0-1046-nvidia-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.8.93
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: NVIDIA A100-SXM4-40GB
Nvidia driver version: 595.91.07
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: False
Caching allocator config: N/A

CPU:
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           48 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  30
On-line CPU(s) list:                     0-29
Vendor ID:                               AuthenticAMD
Model name:                              AMD EPYC 7J13 64-Core Processor
CPU family:                              25
Model:                                   1
Thread(s) per core:                      1
Core(s) per socket:                      1
Socket(s):                               30
Stepping:                                1
BogoMIPS:                                4899.99
Flags:                                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy svm cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw perfctr_core ssbd ibrs ibpb stibp vmmcall fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr wbnoinvd arat npt nrip_save umip pku ospke vaes vpclmulqdq rdpid fsrm arch_capabilities
Virtualization:                          AMD-V
Hypervisor vendor:                       KVM
Virtualization type:                     full
L1d cache:                               1.9 MiB (30 instances)
L1i cache:                               1.9 MiB (30 instances)
L2 cache:                                15 MiB (30 instances)
L3 cache:                                480 MiB (30 instances)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-29
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Vulnerable: Safe RET, no microcode
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; Retpolines; IBPB conditional; IBRS_FW; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Vulnerable: Clear CPU buffers attempted, no microcode
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Versions of relevant libraries:
[pip3] numpy==2.2.6
[pip3] nvidia-cublas==13.4.0.1
[pip3] nvidia-cuda-cupti==13.2.75
[pip3] nvidia-cuda-nvrtc==13.2.78
[pip3] nvidia-cuda-runtime==13.2.75
[pip3] nvidia-cudnn-cu13==9.24.0.43
[pip3] nvidia-cufft==12.2.0.46
[pip3] nvidia-curand==10.4.2.55
[pip3] nvidia-cusolver==12.2.0.1
[pip3] nvidia-cusparse==12.7.10.1
[pip3] nvidia-cusparselt-cu13==0.8.1
[pip3] nvidia-nccl-cu13==2.30.7
[pip3] nvidia-nvjitlink==13.3.33
[pip3] nvidia-nvtx==13.2.75
[pip3] torch==2.14.0.dev20260806+cu132
[pip3] triton==3.8.0+git10f6be36
[pip3] triton_kernels==1.0.0
[conda] Could not collect

cc @bdhirsh @ezyang @chauhang @penguinwu @bobrenjc93 @aorenste @oulgen @aakhundov @davidberard98