Skip to content

flint/metal_native: add convTranspose1d, snake, pad1d and clamp kernels - #129

Merged
ling0322 merged 1 commit into
mainfrom
metal-signal-ops
Oct 15, 2026
Merged

ling0322 merged 1 commit into
mainfrom
metal-signal-ops

Conversation

@ling0322

Copy link
Copy Markdown
Owner

Adds Metal kernels for convTranspose1d, snake, pad1d and clamp (kernels/signal.metal, signal.cc), ported from the Vulkan shaders, so Metal no longer falls back to the F::composed* versions from #127. stft and istft use them through the operators they are composed of.

Why

#127 left Metal on the compositions, and they had never been run on Metal.

Details

  • convTranspose1d: a matmul per group into columns, then an overlap_add1d gather kernel, as on Vulkan.
  • snake: one pass. Metal's sin is precise when built without fast math, so the angle isn't reduced first as in the Vulkan shader.
  • clamp: keeps a NaN as NaN, like torch.clamp.
  • pad1d: float32 and float16; other types still use the composition.
  • The compositions stay in functional.cc for any backend without kernels. Comments and docs that said Metal composes these are updated.
  • Also fixes waifu-tools/src/bin/parameters.rs, which flint: add conv_transpose1d, snake, pad1d, clamp, stft and istft operators; remove waifu::audio's compositions #127 broke by changing w2v_bert::graph's signature.

Tests

  • New test Metal signal operators: each op against the CPU in float and half, NaN and infinity through clamp, snake at large angles, and an stft/istft round trip.
  • ./build/unittest (116 passed, 3 skipped), cargo test for waifu, waifu-modelmanager and waifu-cli, and cargo build -p waifu-tools all pass on an M-series Mac.
  • Model tests (indextts, indextts_gpt, cosyvoice3) not run.

🤖 Generated with Claude Code

Metal ran these four as compositions in flint/functional.cc, which had
never been run on Metal. They now have kernels of their own, ported from
the Vulkan shaders, in kernels/signal.metal and signal.cc; stft and istft
pick them up through the operators they are composed of.

Also fixes waifu-tools, which #127 broke by changing w2v_bert::graph's
signature without updating parameters.rs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ling0322 ling0322 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reviewed d440c31. No actionable correctness findings. Checked the Metal shader/host parameter layouts and buffer bindings, grouped transposed-convolution offsets and optional bias, snake's optional beta, padding indices, clamp NaN handling, and the parameters tool signature update.

Local validation: Metal-enabled unittest build succeeded, including compilation/linking of signal.metal; the unit suite reported 93 passed, 26 skipped, and 11,688 assertions passed. Metal device execution was unavailable in this sandbox, so the GPU cases were skipped and their numerical behavior was not independently verified here. cargo check -p waifu-tools --bin parameters and git diff --check also passed. Model tests were not run.

@ling0322
ling0322 merged commit 6e6b27b into main Oct 15, 2026
0 of 3 checks passed
@ling0322
ling0322 deleted the metal-signal-ops branch October 24, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant