Skip to content

[Feature][Relax] Support shared-KV attention with configurable sliding windows - #20121

Merged
tlopex merged 2 commits into
apache:mainfrom
akaashrp:gemma4-audio-tvm-upstream
Aug 12, 2026
Merged

tlopex merged 2 commits into
apache:mainfrom
akaashrp:gemma4-audio-tvm-upstream

Conversation

@akaashrp

Copy link
Copy Markdown
Contributor

Extend PagedKVCache for models whose logical attention layers reuse K/V cached by another physical layer.

  • Adds non-mutating attention_with_shared_kv support.
  • Makes per-layer sliding-window size configurable.
  • Corrects sliding-window masking during chunked prefill.

This is intended to enable downstream Gemma 4 support in MLC-LLM and WebLLM.

@akaashrp
akaashrp force-pushed the gemma4-audio-tvm-upstream branch from e6f54fa to 5d6848b Compare August 12, 2026 03:54
Replace the hard-coded 1024-token per-layer window with a cache configuration value. Use the configured value consistently when selecting pages, computing page offsets and RoPE positions, and masking the past-cache portion of chunked prefill.

Keep the five-field runtime configuration backward compatible, preserve the existing positional constructor arguments, and cover both CPU end-to-end attention and the sliding prefill mask on CUDA/Metal targets.
Add a paged-KV-cache operation for logical layers that reuse another layer's K/V. The source layer owns and appends the cache; dependent layers provide their queries and the source layer's current-chunk K/V without allocating or appending a second cache.\n\nDefine the frontend and runtime ABI directly as attention_with_shared_kv and validate both ordinary MHA and per-layer sliding MHA against a NumPy reference.
@akaashrp
akaashrp requested a review from tlopex August 12, 2026 09:20
@akaashrp
akaashrp force-pushed the gemma4-audio-tvm-upstream branch from 5d6848b to 3f31be6 Compare August 12, 2026 10:21
@tlopex
tlopex merged commit 27c2e01 into apache:main Aug 12, 2026
8 checks passed
@akaashrp
akaashrp deleted the gemma4-audio-tvm-upstream branch August 13, 2026 03:06
wodylm pushed a commit to wodylm/mcTVM that referenced this pull request Sep 15, 2026
…g windows (apache#20121)

Extend `PagedKVCache` for models whose logical attention layers reuse
K/V cached by another physical layer.
- Adds non-mutating `attention_with_shared_kv` support.
- Makes per-layer sliding-window size configurable.
- Corrects sliding-window masking during chunked prefill.

This is intended to enable downstream Gemma 4 support in MLC-LLM and
WebLLM.
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