Add hamming/blackman/bartlett window op converters#2744
Open
hemanth1999k wants to merge 2 commits into
Open
Conversation
torch.hamming_window, torch.blackman_window and torch.bartlett_window had no converter — they failed with 'Unsupported fx node ... hamming_window' on the torch.export path (only hann_window was supported). Since window_length/periodic/alpha/beta are all known at conversion time, the (data-independent) window is materialized as a constant computed with the exact torch formulas. Handles the TorchScript and torch.export/ExecuTorch frontends (input-count differs), the periodic variants, and Hamming's alpha/beta overloads (hamming_window.periodic_alpha[_beta]) via torch_alias. Adds TestWindowFunctions. Verified against torch 2.9.0: convert + predict match PyTorch within fp16 tolerance across sizes, periodic settings, and custom alpha/beta. (kaiser_window is left out — it needs a Bessel I0 approximation.)
TobyRoseman
reviewed
Jun 22, 2026
| compute_units, | ||
| backends, | ||
| frontends, | ||
| ["hamming", "blackman", "bartlett"], |
Collaborator
There was a problem hiding this comment.
Why not just have this line be:
[torch.hamming_window, torch.blackman_window,torch.bartlett_window]
and get rid of the dictionary lookup.
Contributor
Author
There was a problem hiding this comment.
Done — parametrized directly on [torch.hamming_window, torch.blackman_window, torch.bartlett_window] and removed the dict lookup.
Collaborator
Contributor
Author
|
Addressed the review comment — parametrized directly on the window callables and dropped the dict lookup. Ready for re-review / CI whenever you get a chance. Thanks! |
Collaborator
|
@hemanth1999k - the change looks good. There are however CI failures which need to be addressed: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
torch.hamming_window,torch.blackman_window, andtorch.bartlett_windowhave no converter. On thetorch.exportpath they fail with:Only
hann_windowwas supported, so any audio/DSP model that uses one of the other standard windows can't convert. I found these while bringing up torch 2.9 (#2743) and they reproduce on 2.8 too — they're a plain missing-op gap, not a version regression.Fix
window_length,periodic, and (for Hamming)alpha/betaare all known at conversion time, so the data-independent window is materialized as a constant using the exact torch formulas (matchingtorch's symmetric-of-length-N+1-then-drop-last behavior for the periodic case).A shared
_parse_window_inputshelper handles the input-count difference between frontends — TorchScript carries the trailingdtype/layout/device/pin_memorygraph inputs, whiletorch.export/ExecuTorch pass only the positional params. The periodic and Hammingalpha/betaoverloads (*.periodic,hamming_window.periodic_alpha[_beta]) are wired up withtorch_alias, sincesanitize_op_kinddoesn't strip those suffixes.Test
Adds
TestWindowFunctions— parametrized over frontends, window lengths[1, 3, 6, 10, 12], andperiodicTrue/False for all three windows, plus a Hamming custom-alpha/betacase.Verification
Built against coremltools 9.0 + torch 2.9.0 on macOS (arm64). Convert + predict matches PyTorch within fp16 tolerance for every combination:
Not included
kaiser_window— its definition needs a modified Bessel functionI0, which has no direct MIL op, so it warrants a separate change (polynomial approximation). Left out here to keep this focused.