whisper_npu: WhisperEncoder::add_bias_optimized leaks 1,331,200 B on every encode_audio() call
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 15/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- cpp
- Área
- machine-learning
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- C++
- Estrellas
- 2.1k
- Forks
- 184
- Merge medio
- 12 h 22 min
- PR fusionados (30 d)
- 239
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ROCm/FastFlowLM
-
Update Gemma tokenizer.json after Google's recent fixPosiblemente ocupada @four1er la tomó hace 6 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ROCm/FastFlowLM#1057 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ROCm/FastFlowLM#757 ·
Los mantenedores suelen responder en 1 día
-
No valid checkpoint to restore + Max length reached on multi-turn tool calls (Qwen3.6-MoE, NPU)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ROCm/FastFlowLM#744 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Truncated tool call is emitted as a complete one (unterminated heredoc reaches the client)Posiblemente ocupada @Javinator9889 la tomó hace 72 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ROCm/FastFlowLM#741 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Download timeoutPosiblemente ocupada @stdevPavelmc la tomó hace 200 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
ROCm/FastFlowLM#520 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de ROCm/FastFlowLM
Issues similares
-
bug good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
difficulty:easy func:gui prio:normal type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NatronGitHub/Natron#2118 ·
Los mantenedores suelen responder en 1 día
-
Bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
-
bug difficulty:easy prio:low
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
NatronGitHub/openfx-io#523 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
ArduPilot/ardupilot_gazebo#195 ·