whisper_npu: WhisperEncoder::add_bias_optimized leaks 1,331,200 B on every encode_audio() call

Đang mở
#788 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ROCm/FastFlowLM

Tất cả issue của ROCm/FastFlowLM

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.