pytorch - 💡(How to fix) Fix [Inductor] Incorrect stride calculation in convolution meta kernel when using torch.compile with GRU and Conv1d combination [1 comments, 2 participants]

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…
GitHub stats
pytorch/pytorch#178262Fetched 2026-04-08 01:20:52
View on GitHub
Comments
1
Participants
2
Timeline
57
Reactions
0
Timeline (top)
mentioned ×24subscribed ×24labeled ×7closed ×1

Error Message

AssertionError: expected size 150==150, stride 1==51 at dim=1; expected size 51==51, stride 150==1 at dim=2 Error in op: torch.ops.aten.convolution.default This error most often comes from a incorrect fake (aka meta) kernel for a custom op. Use torch.library.opcheck to test your custom op. See https://pytorch.org/docs/stable/library.html#torch.library.opcheck

Fix Action

Fix / Workaround

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): 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: 31% 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 Tsx async abort: Not affected

Code Example

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

class RandomActivation(nn.Module):
    def __init__(self):
        super().__init__()
    
    def forward(self, x):
        threshold = torch.rand(1, device=x.device)
        return (x > threshold).float()

class TestModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv1d(1, 150, kernel_size=50)
        self.pool = nn.MaxPool1d(4)
        self.gru = nn.GRU(150, 200, batch_first=True)
        self.dropout1 = nn.Dropout(0.25)
        self.fc1 = nn.Linear(200, 128)
        self.fc2 = nn.Linear(128, 35)
        self.dropout2 = nn.Dropout(0.25)
        self.fc3 = nn.Linear(35, 1)
        self.activation = RandomActivation()
    
    def forward(self, x):
        x = x.transpose(1, 2)
        x = F.relu(self.conv1(x))
        x = self.pool(x)
        x = x.transpose(1, 2)
        x, _ = self.gru(x)
        x = self.dropout1(x[:, -1, :])
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.dropout2(x)
        x = self.fc3(x)
        x = self.activation(x)
        return x

model = TestModel()
model.eval()
inputs = torch.randn(4, 100, 1)

# Eager mode works
with torch.no_grad():
    output = model(inputs)

# Compilation fails
compiled_model = torch.compile(model)
with torch.no_grad():
    output_compile = compiled_model(inputs)  # ERROR

---

AssertionError: expected size 150==150, stride 1==51 at dim=1; expected size 51==51, stride 150==1 at dim=2
Error in op: torch.ops.aten.convolution.default
This error most often comes from a incorrect fake (aka meta) kernel for a custom op.
Use torch.library.opcheck to test your custom op.
See https://pytorch.org/docs/stable/library.html#torch.library.opcheck
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Description: When using torch.compile() on a model that combines Conv1d, GRU, and linear layers, the meta kernel for aten.convolution returns incorrect stride information, causing an assertion error during compilation. The eager mode works correctly. code:

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

class RandomActivation(nn.Module):
    def __init__(self):
        super().__init__()
    
    def forward(self, x):
        threshold = torch.rand(1, device=x.device)
        return (x > threshold).float()

class TestModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv1d(1, 150, kernel_size=50)
        self.pool = nn.MaxPool1d(4)
        self.gru = nn.GRU(150, 200, batch_first=True)
        self.dropout1 = nn.Dropout(0.25)
        self.fc1 = nn.Linear(200, 128)
        self.fc2 = nn.Linear(128, 35)
        self.dropout2 = nn.Dropout(0.25)
        self.fc3 = nn.Linear(35, 1)
        self.activation = RandomActivation()
    
    def forward(self, x):
        x = x.transpose(1, 2)
        x = F.relu(self.conv1(x))
        x = self.pool(x)
        x = x.transpose(1, 2)
        x, _ = self.gru(x)
        x = self.dropout1(x[:, -1, :])
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.dropout2(x)
        x = self.fc3(x)
        x = self.activation(x)
        return x

model = TestModel()
model.eval()
inputs = torch.randn(4, 100, 1)

# Eager mode works
with torch.no_grad():
    output = model(inputs)

# Compilation fails
compiled_model = torch.compile(model)
with torch.no_grad():
    output_compile = compiled_model(inputs)  # ERROR

output:

AssertionError: expected size 150==150, stride 1==51 at dim=1; expected size 51==51, stride 150==1 at dim=2
Error in op: torch.ops.aten.convolution.default
This error most often comes from a incorrect fake (aka meta) kernel for a custom op.
Use torch.library.opcheck to test your custom op.
See https://pytorch.org/docs/stable/library.html#torch.library.opcheck

Versions

PyTorch version: 2.8.0+cu126 Is debug build: False CUDA used to build PyTorch: 12.6 ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64) GCC version: (Ubuntu 9.5.0-6ubuntu2) 9.5.0 Clang version: Could not collect CMake version: version 4.0.3 Libc version: glibc-2.39

Python version: 3.9.7 (default, Jul 16 2025, 16:34:47) [GCC 13.3.0] (64-bit runtime) Python platform: Linux-6.14.0-29-generic-x86_64-with-glibc2.39 Is CUDA available: False CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: N/A GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4060 Laptop GPU Nvidia driver version: 580.65.06 cuDNN version: Could not collect 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): 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: 31% 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 Tsx async abort: Not affected

cc @mikaylagawarecki @ezyang @eellison @bdhirsh @bobrenjc93 @aorenste @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo

extent analysis

Fix Plan

The issue arises from the incorrect stride information returned by the meta kernel for aten.convolution when using torch.compile() on a model that combines Conv1d, GRU, and linear layers.

To fix this issue, we need to ensure that the input to the convolutional layer has the correct shape and stride. Here are the steps to follow:

  • Verify the input shape to the Conv1d layer.
  • Ensure the stride information is correctly set for the Conv1d layer.

Here's an example code snippet that demonstrates how to fix the issue:

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.Conv1d(1, 150, kernel_size=50)
        self.pool = nn.MaxPool1d(4)
        self.gru = nn.GRU(150, 200, batch_first=True)
        self.dropout1 = nn.Dropout(0.25)
        self.fc1 = nn.Linear(200, 128)
        self.fc2 = nn.Linear(128, 35)
        self.dropout2 = nn.Dropout(0.25)
        self.fc3 = nn.Linear(35, 1)
        self.activation = nn.ReLU()  # Replace RandomActivation with nn.ReLU()
    
    def forward(self, x):
        x = x.transpose(1, 2)  # Input shape: (batch_size, sequence_length, 1)
        x = F.relu(self.conv1(x))  # Conv1d input shape: (batch_size, 1, sequence_length)
        x = self.pool(x)
        x = x.transpose(1, 2)  # Transpose back to (batch_size, sequence_length, channels)
        x, _ = self.gru(x)
        x = self.dropout1(x[:, -1, :])
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.dropout2(x)
        x = self.fc3(x)
        x = self.activation(x)
        return x

model = TestModel()
model.eval()
inputs = torch.randn(4, 100, 1)

# Eager mode works
with torch.no_grad():
    output = model(inputs)

# Compilation works
compiled_model = torch.compile(model)
with torch.no_grad():
    output_compile = compiled_model(inputs)

Verification

To verify that the fix worked, you can compare the output of the compiled model with the output of the eager mode:

print(torch.allclose(output, output_compile))

This should print True if the outputs are identical.

Extra Tips

When using torch.compile(), ensure that your model is in evaluation mode (model.eval()) to avoid

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