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

Merged
merged 2 commits into from
Jun 24, 2024

Conversation

yoyolicoris
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.

@yoyolicoris yoyolicoris 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.

❌ 4 New Failures

As of commit 8745e8c with merge base b829e93 (image):

NEW FAILURES - The following jobs have failed:

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

@yoyolicoris yoyolicoris enabled auto-merge (squash) June 24, 2024 12:21
@yoyolicoris yoyolicoris merged commit 7f6209b into main Jun 24, 2024
51 of 55 checks passed
@yoyolicoris yoyolicoris deleted the fix/lfilter-backward-error branch June 24, 2024 12:36
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.

3 participants