Skip to content

[inductor] [cpu] torch.nn.Fold throws assertionerror in codegen #147848

@shaoyuyoung

Description

@shaoyuyoung

🐛 Describe the bug

description: when compiling torch.nn.Fold, eager pass the check while inductor throws assertion error on CPU.
device backend: only CPP

import torch
import torch.nn as nn
import torch.nn.functional as F
from torch._inductor import config

config.fallback_random = True
torch.set_grad_enabled(False)


class Model(torch.nn.Module):

    def __init__(self):
        super().__init__()
        self.fold = torch.nn.Fold(output_size=(4, 4), kernel_size=(2, 2), stride=(2, 2))

    def forward(self, x):
        x = self.fold(x)
        return x


model = Model()


x = torch.randn(1, 4, 4)

inputs = [x]


def run_test(model, inputs, backend):
    torch.manual_seed(0)
    if backend != "eager":
        model = torch.compile(model, backend=backend)
    try:
        c_output = model(*inputs)
        print(c_output)
    except Exception as e:
        print(e)


run_test(model, inputs, 'eager')
run_test(model, inputs, 'inductor')

Error logs

tensor([[[[-1.4824,  0.3560, -0.1719,  0.8068],
          [ 0.1535,  1.0522, -0.2272,  0.0148],
          [-1.4766, -0.4049, -0.1608,  0.3579],
          [ 0.5846, -1.5835, -0.9422, -0.3230]]]])
C0225 20:16:07.828000 162414 site-packages/torch/_inductor/scheduler.py:1163] [0/0] Error in codegen for ComputedBuffer(name='buf1', layout=MutationLayoutSHOULDREMOVE('cpu', torch.float32, size=[1, 1, 4, 4], stride=[16, 16, 4, 1]), data=Scatter(device=device(type='cpu'), dtype=torch.float32, inner_fn=<function ReinterpretView.make_loader.<locals>.loader at 0x7f078c1b3060>, ranges=[1, 1, 2, 2, 2, 2], output_indexer=<function index_output_size_and_inner_fn.<locals>.fn at 0x7f078c1b2fc0>, scatter_mode='atomic_add'))
AssertionError: 

Versions

nightly 20250225

cc @chauhang @penguinwu

Metadata

Metadata

Labels

oncall: cpu inductorCPU Inductor issues for Intel team to triageoncall: pt2triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions