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

Feature request: support mask for padded batches #4

Open
pfeatherstone opened this issue May 3, 2023 · 6 comments
Open

Feature request: support mask for padded batches #4

pfeatherstone opened this issue May 3, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@pfeatherstone
Copy link

I have a use case where each batch item is zero padded to fit the batch. I would like to run the PESQ metric on the whole batch but not the padded zeros. Enhancing the algorithm to support a mask would solve that problem.

@bytesnake bytesnake added the enhancement New feature or request label May 4, 2023
@pfeatherstone
Copy link
Author

The other option would be to use torch.nested.nested_tensor() but almost nothing supports that.

@nils-werner
Copy link
Contributor

Given that this code is entirely vectorized, applying a mask will likely not be trivial. And in the end it may not result in performance improvement anyways, because you're basically asking the GPU to let the masked streaming processors sleep and wait until the unmasked ones are done with the batch.

To get "true" performance gains, you may have to sort, truncate and batch your samples by their length before putting them through torch-pesq.

Or is there another reason besides performance why you want this?

In the meantime, can't you just filter the output of torch-pesq to ignore the zeros?

@pfeatherstone
Copy link
Author

Oh yeah I could maybe ignore the zeros. However, if two inputs match exactly, then the output would be zero and we would be ignoring it incorrectly. Unlikely but can still happen.

@nils-werner
Copy link
Contributor

Sorry, I should have said "ignore the masked values".

@pfeatherstone
Copy link
Author

pfeatherstone commented May 16, 2023

How do i "ignore the masked values" ? The output of the loss function is a batch of numbers. I.e if ref has shape [B,T], deg has shape [B,T], then output has shape [B]. So you can't mask anything.

What I have done is if I have an additional mask with shape [B,T] I use inputs ref[mask] and deg[mask] which then has a 1D shape call it [N]. The problem with that is that you're feeding a long sequence with your batch flattened and with loads of discontinuities. I don't think that's the right thing to do.

@nils-werner
Copy link
Contributor

I.e if ref has shape [B,T], deg has shape [B,T], then output has shape [B]. So you can't mask anything.

Ah, you're of course right, I misunderstood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants