pytorch - 💡(How to fix) Fix [Inductor] LoweringException: NotImplementedError: View when compiling model with in-place mul_ and cat operations on view tensors

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

import torch import torch.nn as nn import torch.nn.functional as F

class TestModel(nn.Module):

def __init__(self):
    super().__init__()
    self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
    self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
    self.fc1 = nn.Linear(64 * 14 * 14, 128)
    self.fc2 = nn.Linear(128, 10)
    self.loss_fn = nn.CrossEntropyLoss()

def forward(self, x):
    x = self.conv1(x)
    x = F.relu(x)
    x = F.max_pool2d(x, kernel_size=2)
    x = self.conv2(x)
    x = F.sigmoid(x)
    x = x.view(x.size(0), -1)
    a = x
    param1 = nn.Parameter(a)
    with torch.no_grad():
        a.mul_(1.4386868137611386)
    b = torch.cat([x, x], dim=1)
    param2 = nn.Parameter(b)
    c = torch.zeros_like(x)
    c = c + x
    param3 = nn.Parameter(c)
    y = torch.randint(0, 10, (x.size(0),), dtype=torch.long)
    loss = self.loss_fn(x, y)
    return (loss, param1, param2, param3)

def get_default_model(): return TestModel()

def get_sample_inputs(): return (torch.randn(32, 1, 28, 28),)

def main(): model = get_default_model() model.eval() inputs = get_sample_inputs() try: with torch.no_grad(): output_eager = model(*inputs) print(f'Eager: {output_eager}') except Exception as e: print(f'Eager: {e}') try: compiled_model = torch.compile(model, fullgraph=True) with torch.no_grad(): output_compile = compiled_model(*inputs) print(f'Compile: {output_compile}') except Exception as e: print(f'\nOriginal exception:\n {e}') if name == 'main': main()

Fix Action

Fix / Workaround

Vulnerability Reg file data sampling: Mitigation; Clear Register File

Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl

Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization

Code Example

import torch
import torch.nn as nn
import torch.nn.functional as F

class TestModel(nn.Module):

    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
        self.fc1 = nn.Linear(64 * 14 * 14, 128)
        self.fc2 = nn.Linear(128, 10)
        self.loss_fn = nn.CrossEntropyLoss()

    def forward(self, x):
        x = self.conv1(x)
        x = F.relu(x)
        x = F.max_pool2d(x, kernel_size=2)
        x = self.conv2(x)
        x = F.sigmoid(x)
        x = x.view(x.size(0), -1)
        a = x
        param1 = nn.Parameter(a)
        with torch.no_grad():
            a.mul_(1.4386868137611386)
        b = torch.cat([x, x], dim=1)
        param2 = nn.Parameter(b)
        c = torch.zeros_like(x)
        c = c + x
        param3 = nn.Parameter(c)
        y = torch.randint(0, 10, (x.size(0),), dtype=torch.long)
        loss = self.loss_fn(x, y)
        return (loss, param1, param2, param3)

def get_default_model():
    return TestModel()

def get_sample_inputs():
    return (torch.randn(32, 1, 28, 28),)

def main():
    model = get_default_model()
    model.eval()
    inputs = get_sample_inputs()
    try:
        with torch.no_grad():
            output_eager = model(*inputs)
        print(f'Eager: {output_eager}')
    except Exception as e:
        print(f'Eager: {e}')
    try:
        compiled_model = torch.compile(model, fullgraph=True)
        with torch.no_grad():
            output_compile = compiled_model(*inputs)
        print(f'Compile: {output_compile}')
    except Exception as e:
        print(f'\nOriginal exception:\n {e}')
if __name__ == '__main__':
    main()

---

Original exception:
 LoweringException: NotImplementedError: View
  target: aten.set_.source_Tensor
  args[0]: TensorBox(StorageBox(
    InputBuffer(name='arg5_1', layout=FixedLayout('cpu', torch.float32, size=[32, 12544], stride=[12544, 1]))
  ))
  args[1]: TensorBox(
    View(
      View(
        StorageBox(
          ComputedBuffer(name='buf4', layout=FixedLayout('cpu', torch.float32, size=[32, 12544], stride=[12544, 1]))
        ),
        size=[32, 64, 14, 14],
        reindex=lambda i0, i1, i2, i3: [i0, 196*i1 + 14*i2 + i3],
        origins=OrderedSet([view_2, mul])
      ),
      size=[32, 12544],
      reindex=lambda i0, i1: [i0, ModularIndexing(i1, 196, 64), ModularIndexing(i1, 14, 14), ModularIndexing(i1, 1, 14)],
      origins=OrderedSet([view_7])
    )
  )
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

When compiling a model that performs in-place operations (mul_) on view tensors followed by cat operations, Inductor fails with LoweringException: NotImplementedError: View during the lowering phase. The eager mode executes successfully. code:

import torch
import torch.nn as nn
import torch.nn.functional as F

class TestModel(nn.Module):

    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
        self.fc1 = nn.Linear(64 * 14 * 14, 128)
        self.fc2 = nn.Linear(128, 10)
        self.loss_fn = nn.CrossEntropyLoss()

    def forward(self, x):
        x = self.conv1(x)
        x = F.relu(x)
        x = F.max_pool2d(x, kernel_size=2)
        x = self.conv2(x)
        x = F.sigmoid(x)
        x = x.view(x.size(0), -1)
        a = x
        param1 = nn.Parameter(a)
        with torch.no_grad():
            a.mul_(1.4386868137611386)
        b = torch.cat([x, x], dim=1)
        param2 = nn.Parameter(b)
        c = torch.zeros_like(x)
        c = c + x
        param3 = nn.Parameter(c)
        y = torch.randint(0, 10, (x.size(0),), dtype=torch.long)
        loss = self.loss_fn(x, y)
        return (loss, param1, param2, param3)

def get_default_model():
    return TestModel()

def get_sample_inputs():
    return (torch.randn(32, 1, 28, 28),)

def main():
    model = get_default_model()
    model.eval()
    inputs = get_sample_inputs()
    try:
        with torch.no_grad():
            output_eager = model(*inputs)
        print(f'Eager: {output_eager}')
    except Exception as e:
        print(f'Eager: {e}')
    try:
        compiled_model = torch.compile(model, fullgraph=True)
        with torch.no_grad():
            output_compile = compiled_model(*inputs)
        print(f'Compile: {output_compile}')
    except Exception as e:
        print(f'\nOriginal exception:\n {e}')
if __name__ == '__main__':
    main()

output:

Original exception:
 LoweringException: NotImplementedError: View
  target: aten.set_.source_Tensor
  args[0]: TensorBox(StorageBox(
    InputBuffer(name='arg5_1', layout=FixedLayout('cpu', torch.float32, size=[32, 12544], stride=[12544, 1]))
  ))
  args[1]: TensorBox(
    View(
      View(
        StorageBox(
          ComputedBuffer(name='buf4', layout=FixedLayout('cpu', torch.float32, size=[32, 12544], stride=[12544, 1]))
        ),
        size=[32, 64, 14, 14],
        reindex=lambda i0, i1, i2, i3: [i0, 196*i1 + 14*i2 + i3],
        origins=OrderedSet([view_2, mul])
      ),
      size=[32, 12544],
      reindex=lambda i0, i1: [i0, ModularIndexing(i1, 196, 64), ModularIndexing(i1, 14, 14), ModularIndexing(i1, 1, 14)],
      origins=OrderedSet([view_7])
    )
  )

Versions

Environment Information PyTorch Build Details:

PyTorch version: 2.10.0.dev20251124+cpu

Is debug build: False

CUDA used to build PyTorch: Could not collect

ROCM used to build PyTorch: N/A

OS and Compilers:

OS: Ubuntu 24.04.1 LTS (x86_64)

GCC version: (Ubuntu 10.5.0-4ubuntu2) 10.5.0

Clang version: 18.1.3 (1)

CMake version: version 3.28.3

Libc version: glibc-2.39

Python Environment:

Python version: 3.12.3 (main, Nov 6 2025, 13:44:16) [GCC 13.3.0] (64-bit runtime)

Python platform: Linux-6.14.0-36-generic-x86_64-with-glibc2.39

Is CUDA available: False

CUDA runtime version: Could not collect

CUDA_MODULE_LOADING set to: N/A

GPU Information:

GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4060 Laptop GPU

Nvidia driver version: 580.95.05

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 Information:

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): 32

On-line CPU(s) list: 0-31

Vendor ID: GenuineIntel

Model name: Intel(R) Core(TM) i9-14900HX

CPU family: 6

Model: 183

Thread(s) per core: 2

Core(s) per socket: 24

Socket(s): 1

Stepping: 1

CPU(s) scaling MHz: 33%

CPU max MHz: 5800.0000

CPU min MHz: 800.0000

BogoMIPS: 4838.40

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 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 epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities

Virtualization: VT-x

L1d cache: 896 KiB (24 instances)

L1i cache: 1.3 MiB (24 instances)

L2 cache: 32 MiB (12 instances)

L3 cache: 36 MiB (1 instance)

NUMA node(s): 1

NUMA node0 CPU(s): 0-31

Vulnerability Gather data sampling: Not affected

Vulnerability Ghostwrite: 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: Mitigation; Clear Register File

Vulnerability Retbleed: Not affected

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; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S

Vulnerability Srbds: Not affected

Vulnerability Tsa: Not affected

Vulnerability Tsx async abort: Not affected

Vulnerability Vmscape: Mitigation; IBPB before exit to userspace

Versions of Relevant Libraries:

[pip3] numpy==2.3.3

[pip3] nvidia-cublas-cu12==12.1.3.1

[pip3] nvidia-cuda-cupti-cu12==12.1.105

[pip3] nvidia-cuda-nvrtc-cu12==12.1.105

[pip3] nvidia-cuda-runtime-cu12==12.1.105

[pip3] nvidia-cudnn-cu12==9.1.0.70

[pip3] nvidia-cufft-cu12==11.0.2.54

[pip3] nvidia-curand-cu12==10.3.2.106

[pip3] nvidia-cusolver-cu12==11.4.5.107

[pip3] nvidia-cusparse-cu12==12.1.0.106

[pip3] nvidia-nccl-cu12==2.21.5

[pip3] nvidia-nvjitlink-cu12==12.9.86

[pip3] nvidia-nvtx-cu12==12.1.105

[pip3] optree==0.18.0

[pip3] pytorch-triton-rocm==3.5.0

[pip3] torch==2.10.0.dev20251124+cpu

[pip3] torchao==0.15.0.dev20251124+cpu

[pip3] torchdata==0.12.0.dev20250909+cpu

[pip3] torchtext==0.17.0.dev20240912+cpu

[pip3] triton==3.1.0

[conda] Could not collect

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo

extent analysis

TL;DR

The issue is likely due to the in-place operation mul_ on a view tensor, which is not supported by the PyTorch compiler, and can be fixed by avoiding in-place operations on view tensors.

Guidance

  • Identify the line of code where the mul_ operation is performed on a view tensor and consider rewriting it to avoid in-place operations.
  • Verify that the issue is resolved by checking if the compiled model runs without errors.
  • Consider using the torch.compile option fullgraph=False to disable the compiler's graph optimization, which may help avoid the issue.
  • If the issue persists, try updating PyTorch to a newer version, as the bug may have been fixed in a later release.

Example

# Instead of this:
a = x.view(x.size(0), -1)
param1 = nn.Parameter(a)
with torch.no_grad():
    a.mul_(1.4386868137611386)

# Try this:
a = x.view(x.size(0), -1)
param1 = nn.Parameter(a * 1.4386868137611386)

Notes

The provided code snippet and error message suggest that the issue is related to the PyTorch compiler's handling of in-place operations on view tensors. However, without further information or a minimal reproducible example, it is difficult to provide a more specific solution.

Recommendation

Apply workaround: Avoid in-place operations on view tensors by rewriting the code to use out-of-place operations, as shown in the example above. This should resolve the issue and allow the compiled model to run without errors.

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