Add an exact structured pYIN Viterbi backend#11
Conversation
|
Follow-up update: this PR now uses a direct pYIN block-transition predecessor builder for instead of deriving sparse structure from a dense transition matrix. What changed:
Validation run:no tests ran in 0.00s (10 passed)
|
|
Follow-up update (correcting my previous formatting-mangled comment): this PR now uses a direct pYIN block-transition predecessor builder for viterbi_impl="fast" instead of deriving sparse structure from a dense transition matrix. What changed:
Validation run:
|
145bc98 to
fe77470
Compare
|
Hi @ssmall256, |
sebastianrosenzweig
left a comment
There was a problem hiding this comment.
all good and clean!
Summary
This PR adds an exact structured Viterbi backend to
libf0.pyin()whilepreserving the current dense implementation as the default.
The patch is intentionally narrow:
What This Adds
libf0.pyin(..., viterbi_impl="legacy")libf0.pyin(..., viterbi_impl="fast")compute_transition_structure_from_matrix(...)viterbi_log_likelihood_fast(...)scripts/benchmark_pyin_viterbi.pyWhy
libf0pYIN already constructs a local transition matrix, but the currentdecoder still scans all predecessor states for every target state.
This PR keeps the same transition probabilities and observation matrix, but
precomputes reachable predecessor structure once and evaluates the same dynamic
program only over reachable predecessors.
This is an exact implementation change, not an approximation.
Benchmark Notes
On the bundled quartet excerpt, local measurements showed:
3928.850 mslegacy ->8.753 msfast448.88xpyin():4607.144 mslegacy ->694.988 msfast6.63xThose results are why I think the explicit backend is worth exposing even
before any default change discussion.
Parity
On the exercised local workloads, parity was exact for:
f0The PR includes both low-level and end-to-end parity tests, plus an invalid
backend-mode test.
Validation
Commands used locally:
Reviewer Notes
viterbi_impl="legacy"remains the default in this PR.viterbi_impl="fast".review and broader benchmarking.
Scope
This PR is intentionally limited to pYIN smoothing. It does not refactor other
algorithms or change public defaults beyond adding the new backend option.
Context
This patch comes from a broader cross-repo study of exact structured Viterbi in
pitch trackers. That study produced repeated positive transfer in
penn-mlx,vendored upstream
pennon both CPU and MPS,mlxcrepe,torchcrepe, andlibrosa.pyin.libf0was one of the clearest pYIN-specific wins, which iswhy this PR stays tightly scoped to that decoder path.