pytorch - ✅(Solved) Fix torch.conv1d incorrectly accepts invalid weight shape in meta backend while raising correct error in eager execution [1 pull requests, 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#177237Fetched 2026-04-08 00:21:44
View on GitHub
Comments
1
Participants
2
Timeline
54
Reactions
0
Author
Participants
Timeline (top)
mentioned ×21subscribed ×21labeled ×9commented ×1

Error Message

  • torch.compile (Dynamo): Fails with a Dynamo internal error when processing fake tensors.
  • Meta backend: Incorrectly accepts the invalid weight shape and returns a shape inference result, without raising any error.

Error logs

Fix Action

Fix / Workaround

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: 0,1 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) CPU @ 2.20GHz CPU family: 6 Model: 79 Thread(s) per core: 2 Core(s) per socket: 1 Socket(s): 1 Stepping: 0 BogoMIPS: 4399.99 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat md_clear arch_capabilities Hypervisor vendor: KVM Virtualization type: full L1d cache: 32 KiB (1 instance) L1i cache: 32 KiB (1 instance) L2 cache: 256 KiB (1 instance) L3 cache: 55 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0,1 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Vulnerable Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Mitigation; PTE Inversion Vulnerability Mds: Vulnerable; SMT Host state unknown Vulnerability Meltdown: Vulnerable Vulnerability Mmio stale data: Vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Vulnerable Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Vulnerable Vulnerability Spectre v1: Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers Vulnerability Spectre v2: Vulnerable; IBPB: disabled; STIBP: disabled; PBRSB-eIBRS: Not affected; BHI: Vulnerable Vulnerability Srbds: Not affected Vulnerability Tsa: Not affected Vulnerability Tsx async abort: Vulnerable Vulnerability Vmscape: Not affected

PR fix notes

PR #178797: Fix meta conv shape checks for invalid groups vs out_channels

Description (problem / solution / changelog)

Grouped convolution requires both input and output channel counts to be compatible with groups. This change tightens the meta implementation so invalid combinations fail with the same "Invalid channel dimensions" error as on real devices, updates the conv1d / conv3d docs to state that both in_channels and out_channels must be divisible by groups, and adds regression tests on the meta device for conv1d, conv2d, and conv3d.

Fixes #177237

Changed files

  • test/test_meta.py (modified, +22/-0)
  • torch/_meta_registrations.py (modified, +3/-1)
  • torch/nn/functional.py (modified, +4/-4)
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

When using torch.conv1d with an invalid weight shape for the specified groups parameter:

  • Eager execution: Correctly raises a ValueError indicating the weight shape does not match the group configuration.
  • torch.compile (Dynamo): Fails with a Dynamo internal error when processing fake tensors.
  • Meta backend: Incorrectly accepts the invalid weight shape and returns a shape inference result, without raising any error.

This inconsistency leads to silent shape inference errors in meta mode, which can mislead model construction workflows that rely on meta tensor shape checks.

Error logs

Here is an example in this gist.

parameters

bias = None stride = 1 padding = 4 dilation = 5 groups = 6 input_tensor = torch.randn(2,12,30) weight_tensor = torch.randn(3,2,3)

results

  • eager_mode(correct behavior) : Given groups=6, expected weight to be at least 6 at dimension 0, but got weight of size [3, 2, 3] instead
  • meta backend: torch.Size([2, 3, 28])

Versions

Collecting environment information... PyTorch version: 2.10.0+cpu Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

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

Python version: 3.12.12 (main, Oct 10 2025, 08:52:57) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-6.6.113+-x86_64-with-glibc2.35 Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA 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 Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: 0,1 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) CPU @ 2.20GHz CPU family: 6 Model: 79 Thread(s) per core: 2 Core(s) per socket: 1 Socket(s): 1 Stepping: 0 BogoMIPS: 4399.99 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat md_clear arch_capabilities Hypervisor vendor: KVM Virtualization type: full L1d cache: 32 KiB (1 instance) L1i cache: 32 KiB (1 instance) L2 cache: 256 KiB (1 instance) L3 cache: 55 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0,1 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Vulnerable Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Mitigation; PTE Inversion Vulnerability Mds: Vulnerable; SMT Host state unknown Vulnerability Meltdown: Vulnerable Vulnerability Mmio stale data: Vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Vulnerable Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Vulnerable Vulnerability Spectre v1: Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers Vulnerability Spectre v2: Vulnerable; IBPB: disabled; STIBP: disabled; PBRSB-eIBRS: Not affected; BHI: Vulnerable Vulnerability Srbds: Not affected Vulnerability Tsa: Not affected Vulnerability Tsx async abort: Vulnerable Vulnerability Vmscape: Not affected

Versions of relevant libraries: [pip3] intel-cmplr-lib-ur==2025.3.2 [pip3] intel-openmp==2025.3.2 [pip3] mkl==2025.3.1 [pip3] numpy==2.0.2 [pip3] nvidia-nccl-cu12==2.29.7 [pip3] onemkl-license==2025.3.1 [pip3] optree==0.19.0 [pip3] tbb==2022.3.1 [pip3] tcmlib==1.4.1 [pip3] torch==2.10.0+cpu [pip3] torchao==0.10.0 [pip3] torchaudio==2.10.0+cpu [pip3] torchcodec==0.10.0 [pip3] torchdata==0.11.0 [pip3] torchsummary==1.5.1 [pip3] torchtune==0.6.1 [pip3] torchvision==0.25.0+cpu [pip3] umf==1.0.3 [conda] Could not collect

cc @malfet @ezyang @eellison @bdhirsh @bobrenjc93 @aorenste @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @amjames @Lucaskabela @jataylo

extent analysis

Fix Plan

Fix Name

Validate Weight Shape in torch.conv1d with groups Parameter

Fix Steps

1. Update PyTorch Code

Update the torch.conv1d function in PyTorch to validate the weight shape when the groups parameter is specified.

def conv1d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1):
    if groups > 1 and weight.shape[0] % groups != 0:
        raise ValueError("Weight shape does not match the group configuration")
    # Rest of the function remains the same

2. Update Meta Backend

Update the meta backend to raise an error when an invalid weight shape is encountered.

def infer_shape(input, weight, groups):
    if groups > 1 and weight.shape[0] % groups != 0:
        raise ValueError("Weight shape does not match the group configuration")
    # Rest of the function remains the same

3. Test the Fix

Test the updated torch.conv1d function with the groups parameter to ensure that it raises a ValueError when an invalid weight shape is encountered.

import torch

input_tensor = torch.randn(2, 12, 30)
weight_tensor = torch.randn(3, 2, 3)
groups = 6

try:
    output = torch.conv1d(input_tensor, weight_tensor, groups=groups)
except ValueError as e:
    print(e)

Verification

Verify that the fix works by running the test code and ensuring that a ValueError is raised when an invalid weight shape is encountered.

Extra Tips

  • Make sure to update the PyTorch code and meta backend to validate the weight shape when the groups parameter is specified.
  • Test the updated torch.conv1d

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