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

Set up new module torch.signal.windows #85599

Closed
wants to merge 79 commits into from

Conversation

alvgaona
Copy link
Contributor

Resolves #85366

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 25, 2022

🔗 Helpful Links

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

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

❌ 1 Failures

As of commit e399648:

The following jobs have failed:

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

@facebook-github-bot
Copy link
Contributor

Hi @alvgaona!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple small points as I peeked into the code. Once this PR is ready I'll do a more thorough review :)

torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
@alvgaona alvgaona marked this pull request as ready for review September 26, 2022 23:51
@alvgaona
Copy link
Contributor Author

alvgaona commented Sep 26, 2022

@lezcano I've turned the PR to "Ready to review".

I've got a few questions:

  1. Do we want to migrate the already in-place windows to Python? That is, hann_window, hamming_window, etc.
  2. What are the criteria to, later on, move the python-implemented windows to C++?
  3. Can we have both C++ and Python implementations under the same namespace? I reckon, it's absolutely doable, but I was wondering if there's already a module done this way. I figure we just need to do some mixed configuration based on torch.special and a pure Python module, right?
  4. In order to merge this PR, we'd like to have all these 3 windows and the ones under torch in the same namespace, don't we?
  5. I'd like to create extra PRs to implement the rest of the windows mentioned in the original issue, to keep this one short and well-defined. What'd you think?

Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks great!
I left a number of suggestions. In particular, let's standarise the docs and then I'll do a more in-depth review of these and the implementations.

I also fleshed out a suggestion for how to golf (and make more efficient) the implementation of one of the windows. Similar tricks can be used for the other two windows.

The CI errors seem real.

docs/source/signal.rst Outdated Show resolved Hide resolved
docs/source/signal.rst Outdated Show resolved Hide resolved
test/test_tensor_creation_ops.py Outdated Show resolved Hide resolved
torch/signal/__init__.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
@lezcano
Copy link
Collaborator

lezcano commented Sep 27, 2022

About the points you raise:

  1. Yes! It'd be great to move those from the torch namespace to the signal.windows namespace. Then, we could make the implementations in torch raise a deprecation warning, and call into the implementations in this module. We can do that in a follow up PR. Let's do these 3 first.
  2. About going from Python to C++, let's first get these in Python and see how well they perform. I think that, given that most of them can be implemented as calls to 2-3 kernels and they are quite lightweight, I don't think that implementing them in C++ will bring many efficiency improvements. We can discuss this later down the road though.
  3. No, we'd need to choose between Python and C++.
  4. No. Let's concentrate in these 3 first, and then we can do a follow up PR migrating the others into this namespace.
  5. Yup, that sounds great! But yeah, let's first lock down what's a good way to write the docs, implement these efficiently via arange tricks and so on before jumping into implementing all the others :)

As I said in the review, this is a great effort! Thank you for spearheading it :)

Copy link
Contributor Author

@alvgaona alvgaona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lezcano I tagged you in parts of the code for you to check. Using torch.arange brings floating point errors that are saved by adding an epsilon to the end argument.

We could go back to not using step—which makes it an integer step size of 1—to avoid this, or we just leave it with the epsilon.

The previous version,

k = torch.arange(center,
                 center + window_length,
                 dtype=dtype,
                 layout=layout,
                 device=device,
                 requires_grad=requires_grad)

return torch.exp(-torch.abs(k) / tau)

torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can always have the cake and eat it when it comes to those pesky numerical errors. I proposed a solution that should work for all dtypes (I'm not sure whether the current eps works for all cases for bfloat16 and float16).

We still need to move the tests to OpInfos and fix the CI, but after that, ping me and I'll do a full review, although the PR is already in a very good state. For one, how cool is to implement these windows in 2-3 kernel calls rather than 7-8 :D

torch/signal/windows/__init__.py Outdated Show resolved Hide resolved
torch/signal/windows/__init__.py Outdated Show resolved Hide resolved
torch/signal/windows/windows.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@alvgaona alvgaona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lezcano left a few comments on a few lines.

  • I've added the OpInfo tests for the 3 windows, both sample and error inputs. These tests have passed locally.
  • Feel free to do as many comments and suggestions as you think it's best. I'm open for improvements.

test/test_signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
@alvgaona alvgaona requested review from lezcano and removed request for ngimel and mruberry October 3, 2022 04:09
Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool to have now these tested via OpInfos! I left a few suggestions on how to golf some parts of the code. In particular, I think we will not need test_signal.py at all.

You may want to define a helper function similar to make_mvlgamma_opinfo to create these OpInfos, as many of them have a common structure.

test/test_signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/common_methods_invocations.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/__init__.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
@anjali411 anjali411 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 3, 2022
@facebook-github-bot
Copy link
Contributor

/easycla

As part of the transition to the PyTorch Foundation, this project now requires contributions be covered under the new CLA. See #85559 for additional details.

This comment will trigger a new check of this PR. If you are already covered, you will simply see a new "EasyCLA" check that passes. If you are not covered, a bot will leave a new comment with a link to sign.

@alvgaona alvgaona requested a review from lezcano October 4, 2022 02:28
Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes on the generation of samples.

torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
torch/testing/_internal/opinfo/definitions/signal.py Outdated Show resolved Hide resolved
@mruberry mruberry self-requested a review October 4, 2022 15:34
@lezcano
Copy link
Collaborator

lezcano commented Oct 13, 2022

Also, I've just found about this function:
https://pytorch.org/docs/master/generated/torch.linspace.html
which will get rid of that dirty hack with arange that we currently have :)

@alvgaona
Copy link
Contributor Author

Also, I've just found about this function: https://pytorch.org/docs/master/generated/torch.linspace.html which will get rid of that dirty hack with arange that we currently have :)

Cool. I looked at it last week but didn't pay much attention. Indeed, solves that hack. 😄

@alvgaona alvgaona requested review from mruberry and lezcano and removed request for mruberry and lezcano October 13, 2022 21:57
Copy link
Collaborator

@mruberry mruberry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! There may be some little things I'm missing but I don't think it's productive to delay this PR any longer. Once @lezcano is happy I think this is good to merge. Thanks for creating the torch.signal.windows module, @alvgaona!

@mruberry
Copy link
Collaborator

The ASAN test failures looks unrelated.

@alvgaona
Copy link
Contributor Author

alvgaona commented Oct 13, 2022

Overall LGTM! There may be some little things I'm missing but I don't think it's productive to delay this PR any longer. Once @lezcano is happy I think this is good to merge. Thanks for creating the torch.signal.windows module, @alvgaona!

@mruberry feel free to comment on those minor things! I'd love to know. And you're welcome, expect more PRs from me to add more windows in here.

Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a clean final PR! Thank you for this fantastic effort @alvgaona! I'll merge this one in a bit.

Moving forward, given that we have already agreed on the basics on how these windows should look, feel free to send PRs adding further windows and tag me and Mike as reviewers. I personally would be fine with you sending a few windows per PR, as these are easy to review together.

The other end of the work would be to move the current existing windows to this module and make the functions in the torch namespace aliases. This will be slightly trickier. For one, it will require git grepping your way around the codebase and remove the implementations, while leaving an equivalent API. This is tricky, because you'll need to move the functions from native_functions.yaml to pure Python, but it's doable. You can have a stab at it, and if you get stuck I can help :)

@lezcano
Copy link
Collaborator

lezcano commented Oct 14, 2022

@pytorchbot merge -f "unrelated failures"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@lezcano
Copy link
Collaborator

lezcano commented Oct 14, 2022

a small note: In your future PRs, you may want to base your branch off viable/strict, rather than master. This branch is one on which all the tests are always green. See hud2.pytorch.org/ for the current state of tests that are failing in master.

@github-actions
Copy link

Hey @alvgaona.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

@alvgaona
Copy link
Contributor Author

alvgaona commented Oct 14, 2022

Hey @alvgaona. You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'. For changes that are 'topic: not user facing' there is no need for a release notes label.

@lezcano do you generally do this?

@lezcano lezcano added the topic: new features topic category label Oct 14, 2022
@lezcano
Copy link
Collaborator

lezcano commented Oct 14, 2022

sorted :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged open source topic: new features topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More windows for filtering and spectral analysis
8 participants