whisper_npu: WhisperEncoder::add_bias_optimized leaks 1,331,200 B on every encode_audio() call
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 15/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cpp
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- C++
- Star
- 2.1k
- Fork
- 184
- Merge trung bình
- 12 giờ 22 phút
- Pull request đã merge (30 ngày)
- 239
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ROCm/FastFlowLM
-
Update Gemma tokenizer.json after Google's recent fixCó thể đã có người làm @four1er đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ROCm/FastFlowLM#1057 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ROCm/FastFlowLM#757 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
No valid checkpoint to restore + Max length reached on multi-turn tool calls (Qwen3.6-MoE, NPU)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
ROCm/FastFlowLM#744 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Truncated tool call is emitted as a complete one (unterminated heredoc reaches the client)Có thể đã có người làm @Javinator9889 đã nhận 72 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ROCm/FastFlowLM#741 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Download timeoutCó thể đã có người làm @stdevPavelmc đã nhận 200 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
ROCm/FastFlowLM#520 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ROCm/FastFlowLM
Issue tương tự
-
bug good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
difficulty:easy func:gui prio:normal type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NatronGitHub/Natron#2118 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
bug difficulty:easy prio:low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NatronGitHub/openfx-io#523 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
ArduPilot/ardupilot_gazebo#195 ·