<h2 dir="auto"><g-emoji class="g-emoji" alias="bug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f41b.png">🐛</g-emoji> Bug</h2>
<p dir="auto"><code class="notranslate">torch.nn.functional.conv1d </code> returns strange results when weight tensor created by <code class="notranslate">torch.inverse</code> or <code class="notranslate">torch.t</code> operations.</p>
<h2 dir="auto">To Reproduce</h2>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import torch
from torch import nn
from torch.nn import functional as F"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">torch</span>
<span class="pl-k">from</span> <span class="pl-s1">torch</span> <span class="pl-k">import</span> <span class="pl-s1">nn</span>
<span class="pl-k">from</span> <span class="pl-s1">torch</span>.<span class="pl-s1">nn</span> <span class="pl-k">import</span> <span class="pl-s1">functional</span> <span class="pl-k">as</span> <span class="pl-v">F</span></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="def print_max_diff(x, y):
    print((x - y).abs().max())"><pre class="notranslate"><span class="pl-k">def</span> <span class="pl-en">print_max_diff</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>):
    <span class="pl-en">print</span>((<span class="pl-s1">x</span> <span class="pl-c1">-</span> <span class="pl-s1">y</span>).<span class="pl-en">abs</span>().<span class="pl-en">max</span>())</pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="def have_fun(x, w):
    z_linear = F.linear(x.permute(0, 2, 1), w).permute(0, 2, 1)
    z_conv_f = F.conv1d(x, w.unsqueeze(2))
    
    layer = nn.Conv1d(2, 2, 1, bias=False)
    sd = layer.state_dict()
    sd[&quot;weight&quot;] = w.unsqueeze(2)
    layer.load_state_dict(sd)
    z_conv = layer(x)
    
    print(z_linear)
    print(z_conv_f)
    print(z_conv)
    print_max_diff(z_linear, z_conv)
    print_max_diff(z_linear, z_conv_f)"><pre class="notranslate"><span class="pl-k">def</span> <span class="pl-en">have_fun</span>(<span class="pl-s1">x</span>, <span class="pl-s1">w</span>):
    <span class="pl-s1">z_linear</span> <span class="pl-c1">=</span> <span class="pl-v">F</span>.<span class="pl-en">linear</span>(<span class="pl-s1">x</span>.<span class="pl-en">permute</span>(<span class="pl-c1">0</span>, <span class="pl-c1">2</span>, <span class="pl-c1">1</span>), <span class="pl-s1">w</span>).<span class="pl-en">permute</span>(<span class="pl-c1">0</span>, <span class="pl-c1">2</span>, <span class="pl-c1">1</span>)
    <span class="pl-s1">z_conv_f</span> <span class="pl-c1">=</span> <span class="pl-v">F</span>.<span class="pl-en">conv1d</span>(<span class="pl-s1">x</span>, <span class="pl-s1">w</span>.<span class="pl-en">unsqueeze</span>(<span class="pl-c1">2</span>))
    
    <span class="pl-s1">layer</span> <span class="pl-c1">=</span> <span class="pl-s1">nn</span>.<span class="pl-v">Conv1d</span>(<span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">1</span>, <span class="pl-s1">bias</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
    <span class="pl-s1">sd</span> <span class="pl-c1">=</span> <span class="pl-s1">layer</span>.<span class="pl-en">state_dict</span>()
    <span class="pl-s1">sd</span>[<span class="pl-s">"weight"</span>] <span class="pl-c1">=</span> <span class="pl-s1">w</span>.<span class="pl-en">unsqueeze</span>(<span class="pl-c1">2</span>)
    <span class="pl-s1">layer</span>.<span class="pl-en">load_state_dict</span>(<span class="pl-s1">sd</span>)
    <span class="pl-s1">z_conv</span> <span class="pl-c1">=</span> <span class="pl-en">layer</span>(<span class="pl-s1">x</span>)
    
    <span class="pl-en">print</span>(<span class="pl-s1">z_linear</span>)
    <span class="pl-en">print</span>(<span class="pl-s1">z_conv_f</span>)
    <span class="pl-en">print</span>(<span class="pl-s1">z_conv</span>)
    <span class="pl-en">print_max_diff</span>(<span class="pl-s1">z_linear</span>, <span class="pl-s1">z_conv</span>)
    <span class="pl-en">print_max_diff</span>(<span class="pl-s1">z_linear</span>, <span class="pl-s1">z_conv_f</span>)</pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="x = torch.rand(1, 2, 3)
w = torch.rand(2, 2)"><pre class="notranslate"><span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">rand</span>(<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>)
<span class="pl-s1">w</span> <span class="pl-c1">=</span> <span class="pl-s1">torch</span>.<span class="pl-en">rand</span>(<span class="pl-c1">2</span>, <span class="pl-c1">2</span>)</pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="have_fun(x, w)"><pre class="notranslate"><span class="pl-en">have_fun</span>(<span class="pl-s1">x</span>, <span class="pl-s1">w</span>)</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]])
tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]])
tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.)"><pre class="notranslate"><code class="notranslate">tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]])
tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]])
tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.)
</code></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="have_fun(x, w.inverse())"><pre class="notranslate"><span class="pl-en">have_fun</span>(<span class="pl-s1">x</span>, <span class="pl-s1">w</span>.<span class="pl-en">inverse</span>())</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]])
tensor([[[-0.0508, -0.1854, -1.2418],
         [ 1.1893,  0.2983,  2.3101]]])
tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.7889)"><pre class="notranslate"><code class="notranslate">tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]])
tensor([[[-0.0508, -0.1854, -1.2418],
         [ 1.1893,  0.2983,  2.3101]]])
tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.7889)
</code></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="have_fun(x, w.inverse().clone())"><pre class="notranslate"><span class="pl-en">have_fun</span>(<span class="pl-s1">x</span>, <span class="pl-s1">w</span>.<span class="pl-en">inverse</span>().<span class="pl-en">clone</span>())</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]])
tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]])
tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.)"><pre class="notranslate"><code class="notranslate">tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]])
tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]])
tensor([[[ 0.5952, -0.1171, -0.6075],
         [ 0.7475,  0.1979,  1.5212]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.)
</code></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="have_fun(x, w.t())"><pre class="notranslate"><span class="pl-en">have_fun</span>(<span class="pl-s1">x</span>, <span class="pl-s1">w</span>.<span class="pl-en">t</span>())</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]])
tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]])
tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.2074)"><pre class="notranslate"><code class="notranslate">tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]])
tensor([[[0.5881, 0.0673, 0.6110],
         [0.8276, 0.1188, 1.0196]]])
tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.2074)
</code></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="have_fun(x, w.t().clone())"><pre class="notranslate"><span class="pl-en">have_fun</span>(<span class="pl-s1">x</span>, <span class="pl-s1">w</span>.<span class="pl-en">t</span>().<span class="pl-en">clone</span>())</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]])
tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]])
tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.)"><pre class="notranslate"><code class="notranslate">tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]])
tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]])
tensor([[[0.4183, 0.0493, 0.4442],
         [0.9437, 0.1451, 1.2270]]], grad_fn=&lt;SqueezeBackward1&gt;)
tensor(0., grad_fn=&lt;MaxBackward1&gt;)
tensor(0.)
</code></pre></div>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto"><code class="notranslate">F.conv1d</code> should behave the same way as <code class="notranslate">nn.Conv1d</code>.</p>
<p dir="auto"><code class="notranslate">F.conv1d(x, w.t().unsqueeze(2))</code> should be equal to <code class="notranslate">F.linear(x.permute(0, 2, 1), w.t().permute(0, 2, 1)</code> or at least to <code class="notranslate">F.conv1d(x, w.t().clone().unsqueeze(2))</code>. Same for <code class="notranslate">.inverse()</code> and <code class="notranslate">conv2d</code> (did not check for <code class="notranslate">conv3d</code> but probably it is broken too).</p>
<h2 dir="auto">Environment</h2>
<p dir="auto">PyTorch version: 1.0.0<br>
Is debug build: No<br>
CUDA used to build PyTorch: 9.0.176</p>
<p dir="auto">OS: Red Hat Enterprise Linux Server 7.4 (Maipo)<br>
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)<br>
CMake version: Could not collect</p>
<p dir="auto">Python version: 3.6<br>
Is CUDA available: No<br>
CUDA runtime version: 9.2.88</p>
<p dir="auto">Nvidia driver version: 396.26<br>
cuDNN version: Could not collect</p>
<p dir="auto">pip version: 18.1</p>
<p dir="auto">I compile PyTorch from source (1.0.0a0+54e8623).<br>
and when I attempt to load data I get this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/
Abort trap: 6"><pre class="notranslate"><code class="notranslate">OMP: Error #15: Initializing libomp.dylib, but found libiomp5.dylib already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/
Abort trap: 6
</code></pre></div>
<p dir="auto">The crash occurs when I do this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="dataloader = DataLoader(self._dataset, batch_size=self._batch_size, pin_memory=True, shuffle=True, drop_last=True)
next(dataloader)"><pre class="notranslate"><code class="notranslate">dataloader = DataLoader(self._dataset, batch_size=self._batch_size, pin_memory=True, shuffle=True, drop_last=True)
next(dataloader)
</code></pre></div>
<p dir="auto">I'm using the CIFAR10 dataset here, the problem does not occur with MNIST.</p>
<p dir="auto">The system is macOS 10.12.6. What could the problem be here?</p>