Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix view size error when backpropagating through lfilter #3794

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yoyololicon
Copy link
Collaborator

This commit solves the view size error when the gradient tensor propagates to the filter is not in a contiguous format.

The bug can be reproduced by the following script (provided by @forgi86) using the latest version of torchaudio.

import torch
import torchaudio.functional

order = 5
in_channels = 10
seq_len = 1000
batch_size = 32

b_coeff = torch.randn((in_channels, order)) * 0.05
b_coeff = b_coeff.requires_grad_(True)
a_coeff = torch.randn((in_channels, order - 1)) * 0.05
a_coeff = a_coeff.requires_grad_(True)

ones = torch.ones_like(a_coeff[..., :1])
a_coeffs_with_ones = torch.cat((ones, a_coeff), dim=-1)

u = torch.randn((batch_size, in_channels, seq_len))

y = torchaudio.functional.lfilter(u, a_coeffs_with_ones, b_coeff, clamp=False, batching=True)
y = y.transpose(-2, -1).reshape(batch_size, in_channels // 2, 2, seq_len)

loss = torch.sum(y**2)
loss.backward()
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

@yoyololicon yoyololicon requested a review from a team as a code owner May 14, 2024 21:32
Copy link

pytorch-bot bot commented May 14, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/3794

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 7bd9b72 with merge base 1980f8a (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants