Repository navigation
fix: bound the resample kernel cache by memory with LRU eviction - #1124
Conversation
|
@ykhrustalev In your scenario where many resampling configurations accumulate, one concern is the impact on TTFA/RTF. In my tests, cache eviction increased Higgs Audio streaming TTS TTFA from about 85 ms to 104 ms (avg +23%) when processing an uncached reference. Prepared-reference cache hits were unaffected. But if cache churn is frequent, this rebuilding cost will recur, creating a sustained performance penalty rather than a one-time dela. I think the 16-entry limit should be configurable. A better approach could be a memory-bounded cache with LRU eviction, exposed through a framework API, server config, and CLI flag. This would avoid clearing the entire cache when it reaches the limit. E.g.,
|
The torchaudio sinc kernel cache kept one kernel per rate pair forever. It now evicts least recently used kernels to stay within 32 MiB, set by resample_kernel_cache_mb or --resample-kernel-cache-mb (0 disables it). A kernel larger than the budget is rebuilt on every call, not cached.
b6d873c to
648b34e
Compare
|
Reworked as you suggested: an LRU cache bounded by bytes, 32 MiB by default, set with |
Problem
resample_mono_torchaudio_sinc_hannkeeps every kernel it builds, one per rate pair and option set, so a server fed audio at many sample rates grows without bound: 74-75 MiB after 1 s from each of 401 rates. Clearing the whole cache at a fixed count bounds memory, but hot rates then rebuild their kernels after every clear, 11-21 ms per call on x86-64 for 44.1 or 22.05 kHz to 16 kHz with default options.Solution
std::shared_ptr, so a resample still using an evicted kernel keeps it aliveset_resample_kernel_cache_budget_bytes(size_t), which evicts at once (0disables the cache), andresample_kernel_cache_stats()resample_kernel_cache_mb, and--resample-kernel-cache-mb <mb>on the server (overriding the key) and onaudiocpp_cliTesting
audio_dsp_test,server_config_test,mel_spectrogram_frontend_testandearshot_vad_testpass on M3 Ultra (Metal) and H100 (CUDA, x86-64 Linux); the newaudio_dsp_testcases (byte budget, LRU order, budget 0, shrinking, 4 threads) are clean under TSan and ASan/UBSan, andcli_request_options_testcovers the flag's parser.mainover 8x8 rate pairs, all kernel modes, both accumulations and 3 input lengths, at budgets of 32 MiB, 64 KiB and 0.lfm3_audioASR without libsoxr: a 7.5 s 44.1 kHz request after each burst of 20 requests at other rates, with the same transcript on every build and budget.mainmainbuilds it once. A 100 MiB limit, by flag or config key, restores caching (M3 Ultra server: 232.5 to 184 ms per request).