8000 Wrong output of single-channel channels_last convolution with channels_first input · Issue #82060 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Wrong output of single-channel channels_last convolution with channels_first input #82060
Closed
@emilyfy

Description

@emilyfy

🐛 Describe the bug

Asked about some unexpected behavior on this thread and was asked to raise an issue here.

I'm trying to run convolution with torch.channels_last memory format for the weights but contiguous input, and the output is wrong if the input channels is 1.

import torch

input = torch.randn(1, 1, 100, 100)
conv = torch.nn.Conv2d(1, 64, kernel_size=(3, 3), padding=(1, 1), bias=False)

with torch.no_grad():
    out_ref = conv(input)

conv.to(memory_format=torch.channels_last)
with torch.no_grad():
    out = conv(input)

print(torch.mean(torch.abs(out - out_ref)))

this prints some non-zero value.

Note:

  • if input channel is not 1, the output is correct.
  • this is observed in CPU only. If input and conv are both sent to .cuda(), the error will be zero.

Versions

PyTorch version: 1.12.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 11.2.3 (x86_64)
GCC version: Could not collect
Clang version: 12.0.0 (clang-1200.0.32.27)
CMake version: version 3.16.2
Libc version: N/A

Python version: 3.10.4 (main, Mar 31 2022, 03:38:35) [Clang 12.0.0 ] (64-bit runtime)
Python platform: macOS-10.16-x86_64-i386-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.23.1
[pip3] torch==1.12.0
[pip3] torchaudio==0.12.0
[conda] numpy 1.23.1 pypi_0 pypi
[conda] torch 1.12.0 pypi_0 pypi
[conda] torchaudio 0.12.0 pypi_0 pypi

cc @ezyang @gchanan @zou3519 @VitalyFedyunin @gujinghui @PenghuiCheng @XiaobingSuper @jianyuh @jamesr66a

Metadata

Metadata

Assignees

No one assigned

    Labels

    high prioritymodule: convolutionProblems related to convolutions (THNN, THCUNN, CuDNN)module: correctness (silent)issue that returns an incorrect result silentlymodule: cpuCPU specific problem (e.g., perf, algorithm)module: memory formatMemory format/layout related issues/changes (channels_last, nhwc)module: mkldnnRelated to Intel IDEEP or oneDNN (a.k.a. mkldnn) integrationtriagedThis 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

      0