Skip to content

transpose() followed by conv breaks backward pass #674

@dementrock

Description

@dementrock

The following snippet demonstrates the problem:

import torch
import torch.nn
from torch.autograd import Variable
import numpy as np

x = Variable(torch.from_numpy(np.random.randn(4, 6, 5)).float(), requires_grad=True)
x = torch.transpose(x, 1, 2)
conv = torch.nn.Conv1d(in_channels=5, out_channels=10, kernel_size=2)
result = torch.sum(conv(x))
result.backward()

Running this code and you will get the following error:

  File ".../lib/python3.5/site-packages/torch/tensor.py", line 214, in view
    raise ValueError("input should be contiguous")
ValueError: input should be contiguous

The fix is to change here to output += [t.contiguous().view(*size)]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions