Research: KVarN V-store per-call latency grows with n_kv at fixed grid, K stays flat
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
- 12/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- cpp
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
The suspect path is the value=true branch of the KVarN store in llama-kv-cache-kvarn.cpp (store()), reaching kvarn_quantize_stage_lowshmem and kvarn_stage_rotated_value, enabled with GGML_KVARN_PROFILE and GGML_CUDA_DISABLE_GRAPHS=1. Start by reproducing the V-versus-K per-call timing gap at a fixed grid and comparing the two paths. Done would mean identifying what scales with n_kv or ub in the V path and either fixing it or documenting the cause.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Research Stage
- Background Research (Let's try to avoid reinventing the wheel)
- Hypothesis Formed (How do you think this will work and it's effect?)
- Strategy / Implementation Forming
- Analysis of results
- Debrief / Documentation (So people in the future can learn from us)
Previous existing literature and research
Hi,
I have been chasing a scaling oddity in the KVarN store path on my box (7900 XTX,
gfx1100) and I am out of ideas for what to measure next, so I figured I would ask.
Setup: 27B dense model (D256, GQA 6, 24/4 heads), kvarn5 for K and V, prefill with
ub 512. Timing comes from the built in GGML_KVARN_PROFILE event pairs with
GGML_CUDA_DISABLE_GRAPHS=1.
For reference, q8_0 on the same binary and box does 912 / 835 / 712 t/s at
8k / 16k / 32k, i.e. minus 22% over the range where kvarn5 loses 32%
(550 / 475 / 376 t/s). The gap widens with context (0.60x down to 0.53x of q8_0),
so this looks KVarN specific rather than general long context scaling.
| pp | q8_0 | q5_0 | kvarn5 | kvarn5 / q8_0 |
|---|---|---|---|---|
| 8192 | 911.95 t/s | 907.39 t/s | 549.58 t/s | 0.60x |
| 16384 | 834.50 t/s | 832.27 t/s | 475.26 t/s | 0.57x |
| 32768 | 711.97 t/s | 710.26 t/s | 376.10 t/s | 0.53x |
What I see: V store_low per-call mean climbs all the way from 8k to 65k context
at a fixed launch grid (4 blocks). K store over the same range is flat.
| ctx | 8k | 16k | 24.6k | 32k | 49k | 65k |
|---|---|---|---|---|---|---|
| V mean/call | 36.5 ms | 44.1 | 51.6 | 59.1 | 74.3 | 90.0 ms |
| K mean/call | ~7.7 ms flat throughout |
The V curve is smooth (about +0.94 ms per 1k tokens, exponent around 1.6), not
stepwise. At 32k, V totals are 121 s vs 15.9 s for K, so about 7.6x apart with
the same grid shape.
Things I ruled out on my side:
- Route is stable
prompt-generic-mma / compact-tailfrom 512 to 65536 (route debug env). --flash-attn offgives byte identical V totals (121.1 vs 121.0 s at 32k), so it is not queued FA work on the stream.- Host side
live_stage_groupsplanning is 11.8 ms total over an 87 s prefill, so not the host loop. - kvarn2/5/8 all show the same exponent despite 4x record bytes, so not payload size.
Two more discriminators since:
- Ub sweep at fixed 32k. K behaves normally (totals fall monotonically as ub grows,
mean linear in ub). V totals are U shaped with the minimum at the default ub 512,
and the same U shape shows at 8k. So V per-chunk cost is superlinear in ub at any
fixed position, while K is linear.
| ub | 128 | 256 | 512 | 1024 | 2048 |
|---|---|---|---|---|---|
| K total @32k | 17.51 s | 16.55 | 15.76 | 14.34 | 12.99 s |
| V total @32k | 137.73 s | 123.04 | 121.20 | 129.12 | 141.42 s |
| V total @8k | 23.10 s | (not run) | 18.74 | (not run) | 21.58 s |
- Asymmetric bit widths at 32k/ub512. The gap follows the side, not the bits. Each
side only cares about its own bits, and V moves all of 0.7% going from 2 to 8 bits.
| cfg | K mean | V mean | V/K gap |
|---|---|---|---|
| kvarn5 (sym) | 7.70 ms | 59.18 ms | 7.7x |
| kvarn2 (sym) | 7.27 ms | 57.36 ms | 7.9x |
| kvarn8 (sym) | 8.43 ms | 57.09 ms | 6.8x |
| K8V2 | 8.30 ms | 57.33 ms | 6.9x |
| K2V8 | 7.29 ms | 57.73 ms | 7.9x |
I also checked the store call site (llama-kv-cache-kvarn.cpp, store()): same
sinkhorn iters (16), same stage/tail groups, same slices (2), same grid for K and V.
The only difference is the value flag. So as far as I can tell, the level gap, the
position slope, and the ub superlinearity are all properties of the value=true path,
i.e. the transposed stage reads in kvarn_quantize_stage_lowshmem via
kvarn_stage_rotated_value (token = value ? row : col).
My question: what in that path could grow with cache position and with ub at fixed
per-flush work? The flush kernel reads O(128) stage data and writes one fixed size
record, so I would expect constant cost per flush, but per-flush cost goes from
9.2 ms at 8k to 14.8 ms at 32k (ub512). Is there something striding over a structure
that grows with n_kv that I am not seeing, or an interaction with the record sweep /
L2 at large ub? Is there a debug counter worth adding, or a knob I can use to test
this without rebuilding?
Happy to run anything you suggest on this box and report back. Raw numbers and logs
available on request.
Hypothesis
No response
Implementation
No response
Analysis
No response
Relevant log output
- Ngôn ngữ chính
- C++
- Star
- 1.2k
- Fork
- 80
- Merge trung bình
- 4 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 Anbeeld/beellama.cpp
-
[BUG] KVarN assertion failure in build_inp_mem_hybrid_iswa() due to uninitialized self_kvarn_rotĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Anbeeld/beellama.cpp#205 ·
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 58/100
Anbeeld/beellama.cpp#206 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 57/100
Anbeeld/beellama.cpp#204 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Anbeeld/beellama.cpp#203 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Anbeeld/beellama.cpp#202 · 1 bình luận ·
Tất cả issue của Anbeeld/beellama.cpp
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
CachyOS/packageinstaller#144 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
TomerAberbach/profiler-md#951 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Default key routing (JavaStringHash) picks a different partition than the Java client for about half of keysCó thể đã có người làm @0z5a đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
apache/pulsar-client-go#1575 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
pocoproject/poco#5764 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug cpp-core-guidelines low-priority
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
NatronGitHub/openfx-supportext#164 ·
Maintainer thường phản hồi trong vòng 1 ngày