Skip to content

Optimize Chatterbox KV cache reads - #410

Merged
CrispStrobe merged 1 commit into
CrispStrobe:mainfrom
jltjarvinen:chatterbox_kvcache
Aug 30, 2026
Merged

CrispStrobe merged 1 commit into
CrispStrobe:mainfrom
jltjarvinen:chatterbox_kvcache

Conversation

@jltjarvinen

Copy link
Copy Markdown
Contributor

Summary

Pass GPT-2 K/V cache views directly to ggml_flash_attn_ext instead of materializing the full KV history with ggml_cont() on every layer and decode step.

The naive attention fallback still materializes contiguous K/V tensors as before.

The same optimization can also be applied to the shared attention code in attention.h. The flash-attention path can consume the strided KV-cache views directly.

Result

On Chatterbox Nano CPU T3 decoding, this improves decode performance by about 2%

Pass strided KV-cache views directly to flash attention.
@CrispStrobe
CrispStrobe merged commit 313c669 into CrispStrobe:main Aug 30, 2026
30 checks passed
@CrispStrobe

Copy link
Copy Markdown
Owner

Merged after audit, with a follow-up proof on main.

The direct per-layer K/V views are valid: their logical layout is contiguous and only the layer view offset is nonzero; ggml_cont() therefore added a needless copy before flash attention. Follow-up f40e4427 adds a real CPU ggml graph regression comparing a nonzero-offset cache layer directly against the old materialized path (71 assertions), plus CRISPASR_CHATTERBOX_KV_CONT=1 for model-backed A/B.

Hosted live run 33333867440 is green: public Nano Q4_K + Turbo S3Gen Q4_K, same 40-token trajectory and byte-identical decoded PCM between direct-view and old-materialized paths. (The WAV containers themselves carry timestamped provenance, so the workflow correctly compares stream parameters and PCM rather than container bytes.)

@jltjarvinen
jltjarvinen deleted the chatterbox_kvcache branch August 30, 2026 20:45
CrispStrobe pushed a commit that referenced this pull request Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants