Skip to content

Reduce feature extraction memory on long recordings - #1730

Open
hellomiku831 wants to merge 1 commit into
SYSTRAN:masterfrom
hellomiku831:perf/bound-mel-workspace
Open

hellomiku831 wants to merge 1 commit into
SYSTRAN:masterfrom
hellomiku831:perf/bound-mel-workspace

Conversation

@hellomiku831

Copy link
Copy Markdown

With VAD off, transcribe() extracts features for the whole recording before it starts decoding. The NumPy STFT ends up allocating a windowed frame array and a complex spectrum for the entire file. This is the allocation people ran into in #1234.

This patch computes up to 4,096 frames at a time and writes each block into the final Mel array. Reflection padding still applies at the two ends of the recording, and the log-Mel floor still uses the maximum over the whole recording.

I compared peak process working set on Windows with NumPy 2.2.6. Each cell is a fresh Python process with one OpenBLAS thread, an 80-bin extractor, and a seeded mono float32 input at 16 kHz.

Audio duration Before After
30 seconds 62.4 MiB 62.9 MiB
5 minutes 301.8 MiB 121.1 MiB
15 minutes 833.6 MiB 212.4 MiB

I also compared every feature against the original extractor on all five audio fixtures in tests/data. The largest absolute difference was 1.2e-7. On NumPy 1.26.4 the five-minute benchmark went from 302.8 to 122.6 MiB with identical features.

The new test covers off-hop input lengths, an odd FFT size, and quiet audio followed by louder audio. It also checks that a long recording isn't sent to the FFT in one piece.

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