-
Notifications
You must be signed in to change notification settings - Fork 739
feat: batching/filter banks support of lfilter #1561
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fe29555
Merge pull request #1 from pytorch/master
yoyolicoris f695635
Merge pull request #4 from pytorch/master
yoyolicoris 68f551b
Merge pull request #9 from pytorch/master
yoyolicoris 537a153
Merge pull request #10 from pytorch/master
yoyolicoris 86fcc3d
Merge branch 'master' of https://github.com/yoyololicon/audio
yoyolicoris 01b73e1
Merge branch 'master' of https://github.com/yoyololicon/audio
yoyolicoris b4839d5
Merge branch 'master' of https://github.com/yoyololicon/audio
yoyolicoris 415362b
Merge branch 'master' of https://github.com/pytorch/audio
yoyolicoris 48016d0
draft
yoyolicoris de4e385
draft
yoyolicoris 448483a
fix iir wrong index
yoyolicoris c2844e8
add tests
yoyolicoris 6d81471
modified python part
yoyolicoris d53c3d9
update docstrings
yoyolicoris 93cabef
fix python style
yoyolicoris 17ada5a
remove trailing white space
yoyolicoris 18a7d71
test: add batch consistency test
yoyolicoris 9641c1b
test: add new batch consistency test
yoyolicoris 2960274
test: batch behavior of filter coefficients
yoyolicoris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,20 @@ def test_lfilter_shape(self, shape): | |
| output_waveform = F.lfilter(waveform, a_coeffs, b_coeffs) | ||
| assert shape == waveform.size() == output_waveform.size() | ||
|
|
||
| @parameterized.expand([ | ||
| ((44100,), (2, 3), (2, 44100)), | ||
| ((3, 44100), (1, 3), (3, 44100)), | ||
| ((3, 44100), (3, 3), (3, 44100)), | ||
| ((1, 2, 1, 44100), (3, 3), (1, 2, 3, 44100)) | ||
| ]) | ||
| def test_lfilter_broadcast_shape(self, input_shape, coeff_shape, target_shape): | ||
|
Comment on lines
+83
to
+89
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mthrok |
||
| torch.random.manual_seed(42) | ||
| waveform = torch.rand(*input_shape, dtype=self.dtype, device=self.device) | ||
| b_coeffs = torch.rand(*coeff_shape, dtype=self.dtype, device=self.device) | ||
| a_coeffs = torch.rand(*coeff_shape, dtype=self.dtype, device=self.device) | ||
| output_waveform = F.lfilter(waveform, a_coeffs, b_coeffs) | ||
| assert target_shape == output_waveform.size() | ||
|
|
||
| def test_lfilter_9th_order_filter_stability(self): | ||
| """ | ||
| Validate the precision of lfilter against reference scipy implementation when using high order filter. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
self.assert_batch_consistencyhelper method? It handlesdtype/deviceas well.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assert_batch_consistencyseems assume it only needs to take batch on the first input, but in our case,a_coeffsandb_coeffsshould also be in batch as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean it is applying different filters to samples in batch? I thought the same set of filters are applied to each sample in batch, so one can change the batch size without changing
a_coeffsandb_coeffs.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like we need to do 2 type of tests. I will add another one that use
self.assert_batch_consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And can you clarify that in the above case, where you said "
a_coeffsandb_coeffsshould also be in batch as well", the number of filter bank happens to be same as the batch size, but that's not requirement?So my understanding/expectation is that when input batch is the shape of
[batch_size, sequence_length],a_coeffsandb_coeffscan take any shape of[filter_dim, number_of_filters], without being constrained on the input shape.And if I understand correctly, here your test is testing that filter banks produces the same result regardless they are applied separately or together, in that correct?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, when input is a 2D batch of signals,
a_coeffsandb_coeffsshould be in shape of[batch_size, filter_order + 1]or just[filter_order + 1]. The first one means that the number of filters is equal to batch_size, and each signal is applied with different filter; the second is just one filter apply on all signals.The case that filter shape will not be constrainted, is when the shape of input is
[..., 1, sequence_length]. Thena_coeffsandb_coeffscan be in any shape of 2D matrix[number_of_filters, filter_order + 1], the output shape will be[..., number_of_filters, sequence_length]. It means each signal is filtered by a shared set of filters.Yes, that's correct.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I think the batch behavior we want to test is actually the coefficients, not the input. 😆
So we might need to change the test, with
a_coeffsandb_coeffsas input batch,waveformas the parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yoyololicon
Can you help me clarify with the understanding of the shape semantics here?
Are these correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mthrok
If you want to apply multiple filters at once, these are correct; if there is only one filter, it will fall back to original behavior.
The shape semantics I proposed actually follows pytorch conventions except the last dimension, which is time or filter order.