-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Implement torch.kaiser_window #44271
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
Implement torch.kaiser_window #44271
Conversation
💊 CI failures summary and remediationsAs of commit a5455f8 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 47 times. |
|
@mruberry PTAL. The XLA failure is real, but I'm not sure why it works for the other window functions. but fails on kaiser_window (maybe because I'm using a kernel for kaiser). In response to the comments from the i0 PR:
|
test/test_torch.py
Outdated
| res = torch_method(size, *args, periodic=periodic, device=device) | ||
| # NB: scipy always returns a float32 result | ||
| ref = torch.from_numpy(signal.get_window(name, size, fftbins=periodic)) | ||
| ref = torch.from_numpy(signal.get_window((name, *args), size, fftbins=periodic)) |
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.
I don't think the signature for get_window() will do what you like. Instead you can pass the torch function and the reference as a pair:
(torch.kaiser_window, scipy.signal.kaiser)
You could also pass the args to each in the tuples so you can unpack them as:
torch_fn, torch_args, ref_fn, ref_ags = ...
test/test_torch.py
Outdated
| test(window) | ||
|
|
||
| for num_test in range(50): | ||
| test('kaiser', (random.random() * 30,)) |
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.
It'd be nice to see a bigger cross of window sizes and beta params, that can be crossed with the periodic argument, too.
torch/_torch_docs.py
Outdated
| kaiser_window(window_length, beta, periodic=True, dtype=None, \ | ||
| layout=torch.strided, device=None, requires_grad=False) -> Tensor | ||
| """ + r""" | ||
| Kaiser window function. |
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.
Would a more accurate description be something like, "Computes symmetric samples from the Kaiser windowing function"?
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.
I don't think I agree with this, since you can compute non symmetric samples with this function (in fact the default is to do that).
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.
That makes sense, I realize now what I suggested is a problem. What I'm trying to get at is something more like, "samples symmetrically from..." as in this Wikipedia article. But all the other documentation, like NumPy and matlab, seem to just refer to this as computing the Kaiser window function, which doesn't seem correct but is probably good enough for now.
What about just, "Computes the Kaiser window with window length :attr:`window_length` and shape parameter :attr:`beta`."? It's nice to include how the positional arguments relate to the function in the opening sentence. I don't love the user of the term "shape factor" for beta, but it seems reasonable and consistent with other descriptions.
|
@mruberry, Unfortunately, the doc build keeps failing if I list out the keyword args, giving me the same error as in #43669. I also tried the fix recommended in that issue, and it still failed to build. I have removed the keyword args description, but kept the star in the function description. What is the right way to proceed? |
That's the best we can do for now. Sorry about the docs build. We should really root cause and fix this issue. |
Alright, in that case I think this can use another review, hopefully the content in the docs is better now. |
| - func: kaiser_window(int window_length, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor | ||
| use_c10_dispatcher: full | ||
|
|
||
| - func: kaiser_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor |
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 these three native_functions.yaml entries be combined if defaults for periodic and beta are specified?
- func: kaiser_window.beta(int window_length, bool periodic=True, float beta=12, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
use_c10_dispatcher: full
mruberry
left a comment
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.
Great work, @muthuArivoli! i0 and this are really interesting functions and it's great to have them available in PyTorch.
I have a couple nits about the docs. I also think you could get away with a single dispatch for this function, too, but it's OK if you'd prefer to leave the three dispatch entries you have (that's consistent with the other window functions, after all). Let me know when you're satisfied and we'll get this merged!
|
@mruberry, I updated the docs. I tried implementing the single dispatch, but I ran into this compile error: I tried to make the True lowercase in the yaml file, but this still popped up. If this is due to something not related to the implementation of the kaiser window function, then I think I'll stick with the multiple dispatches, and this should be good to merge. |
That's weird. See, for example:
which sets a bool to a default value. We don't need to worry about it in this PR, however. Let's wait for the tests and get it merged. |
Codecov Report
@@ Coverage Diff @@
## master #44271 +/- ##
==========================================
- Coverage 67.95% 67.95% -0.01%
==========================================
Files 384 384
Lines 49768 49769 +1
==========================================
- Hits 33822 33821 -1
- Misses 15946 15948 +2
Continue to review full report at Codecov.
|
facebook-github-bot
left a comment
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
This is merged! Congrats @muthuArivoli. Let me know if you're looking for something else and, if you are, what might be fun. |
|
Yes, I'm looking for something else. Any recommendations? |
|
It depends on what you're looking for. Let me offer a few options:
Would any of those be interesting? Or would you like something simpler as a break? I can break down linear algebra-related ideas further if that direction is interesting. |
|
I'd like to hear more about the linear algebra ideas. One other question. When implementing the specialized splits (hsplit, dsplit, vsplit), I ran into a problem where the arg name for the input didn't match up with the arg name in the torch.split function. For some reason the torch.split uses the arg name |
I'll pull a few and update the linalg rollup issue soon. It's a really interesting space.
That is strange. I thought we required native_functions always start with |
Related to #38349