Research: KVarN V-store per-call latency grows with n_kv at fixed grid, K stays flat
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 12/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Calme
- Stack technique
- cpp
- Domaine
- backend, performance
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- C++
- Étoiles
- 1.2k
- Forks
- 80
- Merge moyen
- 4 j 20 h
- PR mergées (30 j)
- 2
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de Anbeeld/beellama.cpp
-
[BUG] KVarN assertion failure in build_inp_mem_hybrid_iswa() due to uninitialized self_kvarn_rotOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Anbeeld/beellama.cpp#205 ·
-
Difficulté 3/5 Une demi-journée Accessibilité débutants 58/100
Anbeeld/beellama.cpp#206 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 57/100
Anbeeld/beellama.cpp#204 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
Anbeeld/beellama.cpp#203 · 2 commentaires ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
Anbeeld/beellama.cpp#202 · 1 commentaire ·
Toutes les issues de Anbeeld/beellama.cpp
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
CachyOS/packageinstaller#144 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
TomerAberbach/profiler-md#951 ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug] Default key routing (JavaStringHash) picks a different partition than the Java client for about half of keysPeut-être pris @0z5a l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
apache/pulsar-client-go#1575 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
pocoproject/poco#5764 ·
Les mainteneurs répondent en général sous 2 jours
-
bug cpp-core-guidelines low-priority
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
NatronGitHub/openfx-supportext#164 ·
Les mainteneurs répondent en général sous 1 jour