pytorch - ✅(Solved) Fix conv_transpose1d meta implementation allows invalid output_padding that real CUDA execution rejects [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#178125Fetched 2026-04-08 01:16:33
View on GitHub
Comments
1
Participants
2
Timeline
46
Reactions
0
Author
Timeline (top)
mentioned ×16subscribed ×16labeled ×9unlabeled ×2

torch.conv_transpose1d validates output_padding on real execution, but the meta device path accepts the same invalid configuration and returns a shape.

Error Message

import torch import numpy as np import torch import torch.nn.functional as F

def call_func(inputs, stride=1, padding=0, output_padding=0, groups=1, dilation=1): if len(inputs) == 2: input_tensor, weight = inputs bias = None elif len(inputs) == 3: input_tensor, weight, bias = inputs else: raise ValueError("inputs must contain 2 or 3 tensors")

return torch.conv_transpose1d(
    input=input_tensor,
    weight=weight,
    bias=bias,
    stride=stride,
    padding=padding,
    output_padding=output_padding,
    groups=groups,
    dilation=dilation
)

Test input that causes the defect

input_tensor = torch.randn(20, 16, 50) weight = torch.randn(16, 33, 5) inputs = [input_tensor, weight]

Test parameters

stride = 2 padding = [0] output_padding = 2 groups = 2 dilation = 1

print("Testing torch.conv_transpose1d defect reproduction")

Test 1: Dynamic output shape (direct call)

print("\n1. Dynamic output shape (direct call):") try: dynamic_result = call_func(inputs, stride=stride, padding=padding, output_padding=output_padding, groups=groups, dilation=dilation) print(f"Dynamic shape: {dynamic_result.shape}") except Exception as e: print(f"Dynamic error: {e}")

Test 2: Static output shape (torch.compile with dynamic=True)

print("\n2. Static output shape (torch.compile with dynamic=True):") try: compiled_func = torch.compile(call_func, dynamic=True) static_result = compiled_func(inputs, stride=stride, padding=padding, output_padding=output_padding, groups=groups, dilation=dilation) print(f"Static shape: {static_result.shape}") except Exception as e: print(f"Static error: {e}")

Test 3: Meta output shape (device='meta')

print("\n3. Meta output shape (device='meta'):") try: meta_input_tensor = torch.randn(20, 16, 50, device='meta') meta_weight = torch.randn(16, 33, 5, device='meta') meta_inputs = [meta_input_tensor, meta_weight]

meta_result = call_func(meta_inputs, stride=stride, padding=padding,
                       output_padding=output_padding, groups=groups, dilation=dilation)
print(f"Meta shape: {meta_result.shape}")

except Exception as e: print(f"Meta error: {e}")

print("\nDefect reproduced: Inconsistent behavior between dynamic/static execution (both fail with validation error) vs meta execution (succeeds and returns shape)")

Root Cause

torch.conv_transpose1d validates output_padding on real execution, but the meta device path accepts the same invalid configuration and returns a shape.

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 #178572: [Bugfix] Add output_padding and bias validation for convolution meta path

Description (problem / solution / changelog)

Issue

Fixes #178125, #178127, #178128

Summary

The meta device path for convolution (calc_conv_nd_return_shape and meta_conv in _meta_registrations.py) was missing two classes of validation checks that exist in the C++ backend (Convolution.cpp, NaiveConvolutionTranspose{2d,3d}.cpp):

  1. output_padding validationoutput_padding[i] must be smaller than either stride[i] or dilation[i]. Without this, conv_transpose{1,2,3}d on meta tensors silently accepted invalid output_padding values and returned incorrect shapes.

  2. bias shape validationbias must be 1-dimensional with the correct number of elements (weight.shape[1] * groups for transposed, weight.shape[0] for non-transposed). Without this, conv_transpose3d and conv2d on meta tensors accepted mismatched bias shapes without error.

Changes

  • torch/_meta_registrations.py (+32 lines):
    • Added output_padding vs stride/dilation check in calc_conv_nd_return_shape
    • Added bias shape check in meta_conv
  • test/nn/test_convolution.py (+113 lines):
    • test_conv_transpose_meta_invalid_output_padding: tests invalid output_padding for conv_transpose{1,2,3}d on meta + valid case
    • test_conv_meta_invalid_bias: tests invalid bias for conv_transpose{3,1}d and conv2d on meta + valid case

Checklist

  • Added tests
  • Matches C++ backend validation logic
  • No BC-breaking changes (only adds missing error checks for invalid inputs)

End-to-end run logs

Test script exercises all 3 bug repros plus valid cases, comparing meta device behavior against CPU (ground truth).

<details> <summary>BEFORE (unpatched — bugs present)</summary>
PyTorch version: 2.12.0a0+git18464b7

======================================================================
Test: #178125 conv_transpose1d: output_padding=2, stride=2, dilation=1 on META
======================================================================
  Result shape: torch.Size([20, 66, 105])
  Status: NO ERROR (returned successfully)

======================================================================
Test: #178125 conv_transpose1d: output_padding=2, stride=2, dilation=1 on CPU
======================================================================
  RuntimeError: output padding must be smaller than either stride or dilation, but got output_padding_height: 0 output_padding_width: 2 stride_height: 1 stride_width: 2 dilation_height: 1 dilation_width: 1
  Status: ERROR RAISED

======================================================================
Test: #178127 conv_transpose2d: output_padding=2, stride=2, dilation=2 on META
======================================================================
  Result shape: torch.Size([1, 8, 13, 15])
  Status: NO ERROR (returned successfully)

======================================================================
Test: #178127 conv_transpose2d: output_padding=2, stride=2, dilation=2 on CPU
======================================================================
  RuntimeError: output padding must be smaller than either stride or dilation, but got output_padding_height: 2 output_padding_width: 2 stride_height: 2 stride_width: 2 dilation_height: 2 dilation_width: 2
  Status: ERROR RAISED

======================================================================
Test: #178128 conv_transpose3d: bias=33 but expected=66 (groups=2) on META
======================================================================
  Result shape: torch.Size([20, 66, 50, 10, 20])
  Status: NO ERROR (returned successfully)

======================================================================
Test: #178128 conv_transpose3d: bias=33 but expected=66 (groups=2) on CPU
======================================================================
  RuntimeError: Given transposed=1, weight of size [16, 33, 3, 3, 3], expected bias to be 1-dimensional with 66 elements, but got bias of size [33] instead
  Status: ERROR RAISED

======================================================================
Test: conv2d: bias=3 but expected=4 on META
======================================================================
  Result shape: torch.Size([1, 4, 6, 6])
  Status: NO ERROR (returned successfully)

======================================================================
Test: conv2d: bias=3 but expected=4 on CPU
======================================================================
  RuntimeError: Given weight of size [4, 3, 3, 3], expected bias to be 1-dimensional with 4 elements, but got bias of size [3] instead
  Status: ERROR RAISED

======================================================================
Test: VALID: conv_transpose1d output_padding=1 < stride=2 on META
======================================================================
  Result shape: torch.Size([20, 66, 104])
  Status: NO ERROR (returned successfully)

======================================================================
Test: VALID: conv_transpose3d correct bias=66 on META
======================================================================
  Result shape: torch.Size([20, 66, 50, 10, 20])
  Status: NO ERROR (returned successfully)

======================================================================
All tests completed.
======================================================================

Key issues in BEFORE:

  • #178125: conv_transpose1d with output_padding=2, stride=2, dilation=1 silently returns shape [20, 66, 105] on meta instead of raising an error (CPU correctly raises RuntimeError)
  • #178127: conv_transpose2d with output_padding=2, stride=2, dilation=2 silently returns shape [1, 8, 13, 15] on meta instead of raising an error (CPU correctly raises RuntimeError)
  • #178128: conv_transpose3d with bias=33 (expected 66 for groups=2) silently returns shape [20, 66, 50, 10, 20] on meta instead of raising an error (CPU correctly raises RuntimeError)
  • conv2d with bias=3 (expected 4) also silently succeeds on meta
</details> <details> <summary>AFTER (patched — bugs fixed)</summary>
PyTorch version: 2.12.0a0+git18464b7

======================================================================
Test: #178125 conv_transpose1d: output_padding=2, stride=2, dilation=1 on META
======================================================================
  RuntimeError: output padding must be smaller than either stride or dilation, but got output_padding[0]=2, stride[0]=2, dilation[0]=1
  Status: ERROR RAISED

======================================================================
Test: #178125 conv_transpose1d: output_padding=2, stride=2, dilation=1 on CPU
======================================================================
  RuntimeError: output padding must be smaller than either stride or dilation, but got output_padding_height: 0 output_padding_width: 2 stride_height: 1 stride_width: 2 dilation_height: 1 dilation_width: 1
  Status: ERROR RAISED

======================================================================
Test: #178127 conv_transpose2d: output_padding=2, stride=2, dilation=2 on META
======================================================================
  RuntimeError: output padding must be smaller than either stride or dilation, but got output_padding[0]=2, stride[0]=2, dilation[0]=2
  Status: ERROR RAISED

======================================================================
Test: #178127 conv_transpose2d: output_padding=2, stride=2, dilation=2 on CPU
======================================================================
  RuntimeError: output padding must be smaller than either stride or dilation, but got output_padding_height: 2 output_padding_width: 2 stride_height: 2 stride_width: 2 dilation_height: 2 dilation_width: 2
  Status: ERROR RAISED

======================================================================
Test: #178128 conv_transpose3d: bias=33 but expected=66 (groups=2) on META
======================================================================
  RuntimeError: Given transposed=True, weight of size [16, 33, 3, 3, 3], expected bias to be 1-dimensional with 66 elements, but got bias of size [33] instead
  Status: ERROR RAISED

======================================================================
Test: #178128 conv_transpose3d: bias=33 but expected=66 (groups=2) on CPU
======================================================================
  RuntimeError: Given transposed=1, weight of size [16, 33, 3, 3, 3], expected bias to be 1-dimensional with 66 elements, but got bias of size [33] instead
  Status: ERROR RAISED

======================================================================
Test: conv2d: bias=3 but expected=4 on META
======================================================================
  RuntimeError: Given weight of size [4, 3, 3, 3], expected bias to be 1-dimensional with 4 elements, but got bias of size [3] instead
  Status: ERROR RAISED

======================================================================
Test: conv2d: bias=3 but expected=4 on CPU
======================================================================
  RuntimeError: Given weight of size [4, 3, 3, 3], expected bias to be 1-dimensional with 4 elements, but got bias of size [3] instead
  Status: ERROR RAISED

======================================================================
Test: VALID: conv_transpose1d output_padding=1 < stride=2 on META
======================================================================
  Result shape: torch.Size([20, 66, 104])
  Status: NO ERROR (returned successfully)

======================================================================
Test: VALID: conv_transpose3d correct bias=66 on META
======================================================================
  Result shape: torch.Size([20, 66, 50, 10, 20])
  Status: NO ERROR (returned successfully)

======================================================================
All tests completed.
======================================================================

All issues fixed in AFTER:

  • #178125: Now correctly raises "output padding must be smaller than either stride or dilation" — matches CPU behavior
  • #178127: Now correctly raises "output padding must be smaller than either stride or dilation" — matches CPU behavior
  • #178128: Now correctly raises "expected bias to be 1-dimensional with 66 elements" — matches CPU behavior
  • conv2d now correctly raises "expected bias to be 1-dimensional with 4 elements" — matches CPU behavior
  • Valid cases continue to work correctly (no regression)
</details> <details> <summary>pytest results (2 new tests)</summary>
test/nn/test_convolution.py::TestConvolutionNN::test_conv_meta_invalid_bias PASSED
test/nn/test_convolution.py::TestConvolutionNN::test_conv_transpose_meta_invalid_output_padding PASSED
2 passed, 1179 deselected in 0.62s
</details>

Authored with the assistance of Claude (AI).

Changed files

  • test/nn/test_convolution.py (modified, +113/-0)
  • torch/_meta_registrations.py (modified, +32/-0)

Code Example

import torch
import numpy as np
import torch
import torch.nn.functional as F

def call_func(inputs, stride=1, padding=0, output_padding=0, groups=1, dilation=1):
    if len(inputs) == 2:
        input_tensor, weight = inputs
        bias = None
    elif len(inputs) == 3:
        input_tensor, weight, bias = inputs
    else:
        raise ValueError("inputs must contain 2 or 3 tensors")
    
    return torch.conv_transpose1d(
        input=input_tensor,
        weight=weight,
        bias=bias,
        stride=stride,
        padding=padding,
        output_padding=output_padding,
        groups=groups,
        dilation=dilation
    )

# Test input that causes the defect
input_tensor = torch.randn(20, 16, 50)
weight = torch.randn(16, 33, 5)
inputs = [input_tensor, weight]

# Test parameters
stride = 2
padding = [0]
output_padding = 2
groups = 2
dilation = 1

print("Testing torch.conv_transpose1d defect reproduction")

# Test 1: Dynamic output shape (direct call)
print("\n1. Dynamic output shape (direct call):")
try:
    dynamic_result = call_func(inputs, stride=stride, padding=padding, 
                              output_padding=output_padding, groups=groups, dilation=dilation)
    print(f"Dynamic shape: {dynamic_result.shape}")
except Exception as e:
    print(f"Dynamic error: {e}")

# Test 2: Static output shape (torch.compile with dynamic=True)
print("\n2. Static output shape (torch.compile with dynamic=True):")
try:
    compiled_func = torch.compile(call_func, dynamic=True)
    static_result = compiled_func(inputs, stride=stride, padding=padding,
                                 output_padding=output_padding, groups=groups, dilation=dilation)
    print(f"Static shape: {static_result.shape}")
except Exception as e:
    print(f"Static error: {e}")

# Test 3: Meta output shape (device='meta')
print("\n3. Meta output shape (device='meta'):")
try:
    meta_input_tensor = torch.randn(20, 16, 50, device='meta')
    meta_weight = torch.randn(16, 33, 5, device='meta')
    meta_inputs = [meta_input_tensor, meta_weight]
    
    meta_result = call_func(meta_inputs, stride=stride, padding=padding,
                           output_padding=output_padding, groups=groups, dilation=dilation)
    print(f"Meta shape: {meta_result.shape}")
except Exception as e:
    print(f"Meta error: {e}")

print("\nDefect reproduced: Inconsistent behavior between dynamic/static execution (both fail with validation error) vs meta execution (succeeds and returns shape)")
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Summary

torch.conv_transpose1d validates output_padding on real execution, but the meta device path accepts the same invalid configuration and returns a shape.

Reproduction

import torch
import numpy as np
import torch
import torch.nn.functional as F

def call_func(inputs, stride=1, padding=0, output_padding=0, groups=1, dilation=1):
    if len(inputs) == 2:
        input_tensor, weight = inputs
        bias = None
    elif len(inputs) == 3:
        input_tensor, weight, bias = inputs
    else:
        raise ValueError("inputs must contain 2 or 3 tensors")
    
    return torch.conv_transpose1d(
        input=input_tensor,
        weight=weight,
        bias=bias,
        stride=stride,
        padding=padding,
        output_padding=output_padding,
        groups=groups,
        dilation=dilation
    )

# Test input that causes the defect
input_tensor = torch.randn(20, 16, 50)
weight = torch.randn(16, 33, 5)
inputs = [input_tensor, weight]

# Test parameters
stride = 2
padding = [0]
output_padding = 2
groups = 2
dilation = 1

print("Testing torch.conv_transpose1d defect reproduction")

# Test 1: Dynamic output shape (direct call)
print("\n1. Dynamic output shape (direct call):")
try:
    dynamic_result = call_func(inputs, stride=stride, padding=padding, 
                              output_padding=output_padding, groups=groups, dilation=dilation)
    print(f"Dynamic shape: {dynamic_result.shape}")
except Exception as e:
    print(f"Dynamic error: {e}")

# Test 2: Static output shape (torch.compile with dynamic=True)
print("\n2. Static output shape (torch.compile with dynamic=True):")
try:
    compiled_func = torch.compile(call_func, dynamic=True)
    static_result = compiled_func(inputs, stride=stride, padding=padding,
                                 output_padding=output_padding, groups=groups, dilation=dilation)
    print(f"Static shape: {static_result.shape}")
except Exception as e:
    print(f"Static error: {e}")

# Test 3: Meta output shape (device='meta')
print("\n3. Meta output shape (device='meta'):")
try:
    meta_input_tensor = torch.randn(20, 16, 50, device='meta')
    meta_weight = torch.randn(16, 33, 5, device='meta')
    meta_inputs = [meta_input_tensor, meta_weight]
    
    meta_result = call_func(meta_inputs, stride=stride, padding=padding,
                           output_padding=output_padding, groups=groups, dilation=dilation)
    print(f"Meta shape: {meta_result.shape}")
except Exception as e:
    print(f"Meta error: {e}")

print("\nDefect reproduced: Inconsistent behavior between dynamic/static execution (both fail with validation error) vs meta execution (succeeds and returns shape)")

Expected behavior

Both real and meta execution should reject the invalid output_padding with the same error.

Actual behavior

  • Real CUDA/normal execution: raises
  • output padding must be smaller than either stride or dilation
  • Meta execution: succeeds and returns torch.Size([20, 66, 105])

Impact

This makes meta shape inference inconsistent with runtime validation and can let invalid models pass tracing/compilation checks.

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

extent analysis

Fix Plan

To fix the inconsistent behavior between real and meta execution of torch.conv_transpose1d, we need to ensure that the validation of output_padding is performed consistently in both cases.

Step 1: Validate Output Padding

We can add a manual validation check for output_padding before calling torch.conv_transpose1d. This check should ensure that output_padding is smaller than either stride or dilation.

def validate_output_padding(output_padding, stride, dilation):
    if output_padding >= stride or output_padding >= dilation:
        raise ValueError("output padding must be smaller than either stride or dilation")

# ...

validate_output_padding(output_padding, stride, dilation)
result = torch.conv_transpose1d(
    input=input_tensor,
    weight=weight,
    bias=bias,
    stride=stride,
    padding=padding,
    output_padding=output_padding,
    groups=groups,
    dilation=dilation
)

Step 2: Modify Meta Execution

We also need to modify the meta execution path to perform the same validation check. We can do this by overriding the torch.conv_transpose1d function for meta tensors.

def meta_conv_transpose1d(input, weight, bias, stride, padding, output_padding, groups, dilation):
    validate_output_padding(output_padding, stride, dilation)
    return torch.conv_transpose1d(
        input=input,
        weight=weight,
        bias=bias,
        stride=stride,
        padding=padding,
        output_padding=output_padding,
        groups=groups,
        dilation=dilation
    )

# ...

if input_tensor.device == 'meta':
    result = meta_conv_transpose1d(
        input=input_tensor,
        weight=weight,
        bias=bias,
        stride=stride,
        padding=padding,
        output_padding=output_padding,
        groups=groups,
        dilation=dilation
    )
else:
    result = torch.conv_transpose1d(
        input=input_tensor,
        weight=weight,
        bias=bias,
        stride=stride,
        padding=padding,
        output_padding=output_padding,
        groups=groups,
        dilation=dilation
    )

Verification

To verify that the fix worked, we can run the same test cases as before and check that the validation error is raised consistently in both real and meta execution.

# Test 1: Dynamic output shape (direct call)
try:
    dynamic_result = call_func(inputs, stride=stride, padding=padding, 
                              output_padding=output_padding, groups=groups, dilation=dilation)
    print(f"Dynamic shape: {dynamic_result.shape}")
except Exception as e:
    print(f"Dynamic error: {e}")

# Test 2: Static output shape (torch.compile with dynamic=True)
try:
    compiled_func = torch.compile(call_func, dynamic=True)
    static_result = compiled_func(inputs

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…

FAQ

Expected behavior

Both real and meta execution should reject the invalid output_padding with the same error.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix conv_transpose1d meta implementation allows invalid output_padding that real CUDA execution rejects [1 pull requests, 1 comments, 2 participants]