Speed up Smart Fades beat tracking with a numba-accelerated decoder#4204
Speed up Smart Fades beat tracking with a numba-accelerated decoder#4204marcelveldt wants to merge 1 commit into
Conversation
The DBN Viterbi post-processing ran as a pure-Python per-frame loop that pegged a CPU core for the full duration of each track's beat analysis. Add a numba-jitted decoder that produces bit-identical beats/downbeats but runs ~4-5x faster, keeping the numpy decoder as an automatic fallback.
🔒 Dependency Security Report📦 Modified Dependencies
|
| Name | Skip Reason |
|---|---|
| torch | Dependency not found on PyPI and could not be audited: torch (2.11.0+cpu) |
| torchaudio | Dependency not found on PyPI and could not be audited: torchaudio (2.11.0+cpu) |
| ✅ No known vulnerabilities found |
Automated Security Checks
- ✅ Vulnerability Scan: Passed - No known vulnerabilities
- ✅ Trusted Sources: All packages have verified source repositories
- ✅ Typosquatting Check: No suspicious package names detected
- ✅ License Compatibility: All licenses are OSI-approved and compatible
- ✅ Supply Chain Risk: Passed - packages appear mature and maintained
Manual Review
Maintainer approval required:
- I have reviewed the changes above and approve these dependency updates
To approve: Comment /approve-dependencies or manually add the dependencies-reviewed label.
There was a problem hiding this comment.
Pull request overview
This PR accelerates Smart Fades’ DBN/HMM (Viterbi) beat/downbeat post-processing by adding an optional numba-jitted decoder and by precomputing decode-plans per meter at tracker initialization, aiming to reduce per-track CPU spikes during analysis.
Changes:
- Add a numba-accelerated Viterbi decoder with a numpy fallback path.
- Precompute per-meter decode plan (state classification / predecessor tables) once at init instead of per-track.
- Add tests to assert bit-identical outputs across numba vs numpy vs a naive reference implementation, and add
numbato dependencies.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
music_assistant/providers/smart_fades/dbn_postprocessor.py |
Adds numba-jitted decoder, decode-plan precompute, and switches runtime decode to a numba-first path with numpy fallback. |
music_assistant/providers/smart_fades/manifest.json |
Declares numba as a Smart Fades provider requirement. |
requirements_all.txt |
Adds numba to the aggregated dependency list used in CI installs. |
tests/providers/smart_fades/test_dbn_postprocessor.py |
Adds correctness tests ensuring numba/numpy/naive Viterbi decoders are consistent and output-identical. |
| """The numba-jitted decode must return bit-identical beats to the numpy fallback.""" | ||
| combined = _synth_activations(seed, num_frames, bpm, meter) | ||
| tracker = DBNDownBeatTracker(beats_per_bar=[3, 4], min_bpm=55, max_bpm=215, fps=50) |
|
Just be aware that the gains are not substantial. Postprocessing takes around 5% of the the total inference time, so we are optimizing on a small portion already. For example, total inference time on my prod setup takes like 30s with 2s being the post processing time. |
|
Let this one for you to decide @MarvinSchenkel - in general a C-backed library is always better than pure python so maybe good to do some comparison - no rush. |
What does this implement/fix?
The Smart Fades beat/downbeat tracker ran its DBN (HMM/Viterbi) post-processing as a pure-Python per-frame loop, which pegged a CPU core for the full duration of every track's analysis and contributed to sluggishness while streaming. This adds a compiled (numba) decoder that produces bit-identical beats/downbeats while running ~4-5x faster, reducing the per-track CPU spike.
nogil, compiled once at provider init) used by default, with the existing numpy decoder kept as an automatic fallback and readable reference implementation.numbain the Smart Fades manifest (already present transitively via the corelibrosadependency).Related issue (if applicable):
Types of changes
bugfixnew-featureenhancementnew-providerbreaking-changerefactordocumentationmaintenancecidependenciesChecklist
pre-commit run --all-filespasses.pytestpasses, and tests have been added/updated undertests/where applicable.music-assistant/modelsis linked.music-assistant/frontendis linked.