Skip to content

Add Mel-Band RoFormer model support - #1

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1771827284-mel-band-roformer
Open

Add Mel-Band RoFormer model support#1
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1771827284-mel-band-roformer

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Add Mel-Band RoFormer demixing model (STFT + ONNX masks + iSTFT)

Summary

This PR adds first-class support for a Mel-Band RoFormer audio source-separation (demixing) model in transformers.js:

  • Introduces MelBandRoformerModel with an end-to-end separate() API:
    • STFT preprocessing (reflect padding + Hann window)
    • Feature packing to match the model’s mel-band frequency indexing (freq_indices)
    • ONNX inference via sessionRun
    • Mask scatter-add + overlap averaging + complex multiply in the STFT domain
    • iSTFT reconstruction + optional chunked overlap-add for long audio
  • Registers the model under the mel-band-roformer model type in the model registry.
  • Exports the new model from packages/transformers/src/models/models.js.

Files changed:

  • packages/transformers/src/models/mel_band_roformer/modeling_mel_band_roformer.js (new)
  • packages/transformers/src/models/models.js
  • packages/transformers/src/models/registry.js

Review & Testing Checklist for Human

  • Validate ONNX I/O naming assumptions: sessionRun(..., { input: ... }) and expecting outputs.masks matches the exported ONNX model’s actual input/output names.
  • Audio correctness spot-check:
    • run separation on a short stereo clip and confirm output is non-silent, correctly shaped (1, num_stems, channels, time), and sounds like vocal isolation.
    • compare against a reference implementation (e.g., PyTorch) for at least one known input.
  • Performance/memory sanity:
    • try a multi-minute track (chunked path) and confirm runtime is reasonable and no runaway memory usage.
  • Confirm fft.fft.inverseTransform(...) access is stable/acceptable (uses an internal property through any casting).

Notes

devin-ai-integration Bot and others added 3 commits February 23, 2026 06:31
Implements MelBandRoformerModel for audio demixing/source separation.
The model uses a transformer-based architecture with mel-scale frequency
bands to separate audio sources (e.g., vocals from instrumental).

Architecture:
- STFT preprocessing (JS) - converts audio to frequency domain
- Mel-band indexing (JS) - maps frequencies to mel-scale bands
- Core transformer model (ONNX) - band_split -> transformers -> mask_estimators
- Mask application + iSTFT (JS) - reconstructs separated audio

Features:
- Full complex STFT/iSTFT implementation in JavaScript
- Stereo audio support with proper channel interleaving
- Chunked processing with overlap-add for long audio files
- Compatible with voc_fv7 and other Mel-Band RoFormer checkpoints

Co-Authored-By: Raymond <20248577+javaarchive@users.noreply.github.com>
…freq

Rewrote _applyMasks to match the PyTorch forward method exactly:
1. Build full interleaved STFT representation (2050 entries for stereo)
2. Scatter-add mask values back to full 2050 positions
3. Divide by num_bands_per_freq to average overlapping bands
4. Complex multiply full STFT by averaged mask
5. Split back to per-channel and perform iSTFT

Co-Authored-By: Raymond <20248577+javaarchive@users.noreply.github.com>
Co-Authored-By: Raymond <20248577+javaarchive@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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