whisper_npu: WhisperEncoder::add_bias_optimized leaks 1,331,200 B on every encode_audio() call
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- machine-learning
Direzione di ricerca
The leaking operator new[] call is in the prebuilt whisper_npu engine, and no WhisperEncoder source exists in the tree; src/CMakeLists.txt and src/include/whisper/whisper_npu.hpp are the only in-repo touchpoints. Start by reproducing with heaptrack and confirming the nm/objdump evidence against the shipped .so. Done means the per-encode scratch buffer is owned and released, which requires an upstream engine change rather than an edit in this repository.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Every call to whisper_npu::encode_audio() leaks 1,331,200 bytes. The allocations all come from a single operator new[] inside WhisperEncoder::add_bias_optimized() that has no matching delete[].
The buffer looks like per-call scratch for the bias broadcast. It survives every teardown path — engine destruction included — because nothing holds a pointer to it after the call returns. At ~1.3 MB per 30 s encode window that is roughly 160 MB per hour of continuous speech, growing without bound.
Component: whisper_npu prebuilt engine — affects both src/lib/hrx/libwhisper_npu.so and src/lib/xrt/libwhisper_npu.so (and the matching .dlls).
Model exercised: whisper-v3:turbo (Whisper-V3-Turbo-NPU2, 32 encoder layers).
Measurement
heaptrack, comparing a 10-encode run against a 40-encode run of the same audio. Leaked bytes scale linearly and exactly with encode count. Decode steps and clear_context() leak nothing, which isolates it to the encode path.
Per encode, 33 allocations:
| count | size each | subtotal |
|---|---|---|
| 32 (one per encoder layer) | 40,960 B | 1,310,720 B |
| 1 | 20,480 B | 20,480 B |
| total | 1,331,200 B |
Static confirmation from the shipped binaries
This is verifiable from the released artifacts alone — no source needed.
The symbol is local, hence absent from the dynamic table:
$ nm -C src/lib/hrx/libwhisper_npu.so | grep add_bias
0000000000028660 t WhisperEncoder::add_bias_optimized(buffer<bfloat16_t>&, buffer<bfloat16_t>&, buffer<bfloat16_t>&) [clone .isra.0]
The function spans 0x28660–0x289d0. Every call instruction in that range:
$ objdump -d -C --start-address=0x28660 --stop-address=0x289d0 \
src/lib/hrx/libwhisper_npu.so | grep -oE 'call.*<.*>'
3 __assert_fail@plt
1 operator new[](unsigned long)@plt
No operator delete[], no free, no destructor call. The allocation at 0x286d0 has no release path at all:
286c5: lea 0x0(,%r15,4),%rdi ; byte count = element_count * 4 (float32 scratch)
286cd: mov %r8,%r12
286d0: call f040 <operator new[](unsigned long)@plt>
286d5: mov %rax,%rdi ; result used directly, never stored for cleanup
Library-wide the imbalance comes down to this one site:
$ objdump -d -C src/lib/hrx/libwhisper_npu.so | grep -c 'operator new\[\](unsigned long)@plt'
14
$ objdump -d -C src/lib/hrx/libwhisper_npu.so | grep -c 'operator delete\[\](void\*)@plt'
13
14 array allocations against 13 array frees. The one unmatched new[] is the one above. The same unmatched allocation is present in the XRT build at 0x57df0.
The lea (,%r15,4) gives a 4-byte element, i.e. a float32 scratch buffer: 40,960 B = 10,240 floats per encoder layer (×32), and 20,480 B = 5,120 floats once per encode.
Suggested fix
Allocate the scratch once and reuse it. Best as a WhisperEncoder member sized at construction — the shapes are fixed per model — which also removes 33 allocator round-trips from the per-encode hot path. Failing that, a std::vector<float> / std::unique_ptr<float[]> local would at least bound the lifetime to the call.
Why this needs an engine rebuild
whisper_npu ships only as a prebuilt binary (src/CMakeLists.txt resolves it out of ${FLM_ENGINE_LIB_DIR}), and no WhisperEncoder source exists in the tree. Unlike gemma4e_npu, which has an opt-in source build under src/detail/ behind FLM_BUILD_GEMMA4E, there is no whisper equivalent. The implementation is fully behind the pimpl in src/include/whisper/whisper_npu.hpp, so there is no caller-side workaround.
Possible relation to #585
#585 reports flm serve --asr 1 with whisper-v3:turbo exiting with code -1 after ~2.5–2.8 h, consistently. An unbounded encode-path leak is an obvious suspect, and a single 100 MB audio file is on the order of a hundred encode windows (~138 MB), so the growth can be fast for large inputs.
That said, the evidence does not cleanly line up and I do not want to overclaim: #585 reports uptimes clustering tightly in a 2h28m–2h48m band regardless of load, including while idle. A per-encode leak is load-dependent, so heavy-file periods should die noticeably sooner than idle ones. That argues for a time- or handle-based cause as the primary driver, with this leak at most a contributor. Worth checking RSS against uptime on an affected host to separate the two.
Found while investigating a separate HRX runtime retention problem (#787).
- Lingua principale
- C++
- Stelle
- 2.1k
- Fork
- 184
- Merge medio
- 12h 22m
- PR unite (30g)
- 239
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ROCm/FastFlowLM
-
Update Gemma tokenizer.json after Google's recent fixForse già presa @four1er l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ROCm/FastFlowLM#1057 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ROCm/FastFlowLM#757 ·
I maintainer di solito rispondono entro 1 giorno
-
No valid checkpoint to restore + Max length reached on multi-turn tool calls (Qwen3.6-MoE, NPU)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ROCm/FastFlowLM#744 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Truncated tool call is emitted as a complete one (unterminated heredoc reaches the client)Forse già presa @Javinator9889 l’ha presa 72 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ROCm/FastFlowLM#741 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Download timeoutForse già presa @stdevPavelmc l’ha presa 200 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
ROCm/FastFlowLM#520 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ROCm/FastFlowLM
Issue simili
-
bug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
difficulty:easy func:gui prio:normal type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NatronGitHub/Natron#2118 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
bug difficulty:easy prio:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NatronGitHub/openfx-io#523 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
ArduPilot/ardupilot_gazebo#195 ·