Skip to content

feat: Triattention support#356

Open
iMmAseu wants to merge 7 commits into
ovg-project:mainfrom
iMmAseu:triattention
Open

feat: Triattention support#356
iMmAseu wants to merge 7 commits into
ovg-project:mainfrom
iMmAseu:triattention

Conversation

@iMmAseu

@iMmAseu iMmAseu commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds optional external TriAttention integration for kvcached without vendoring the TriAttention source tree.

TriAttention is loaded from a separately installed checkout and is enabled only when ENABLE_TRIATTENTION=1 is set. Existing kvcached users are unaffected by default.

What Changed

  • Add an external TriAttention loader under kvcached.integration.triattention_external.
  • Add optional TriAttention activation paths for both vLLM and SGLang autopatching.
  • Fail fast when ENABLE_TRIATTENTION=1 is requested but TriAttention activation fails.
  • Add a kvcached compatibility patch for the upstream TriAttention repository.
  • Add benchmark scripts for comparing kvcached-only vs kvcached+TriAttention:
    • tools/compare_vllm_triattention.py
    • tools/compare_sglang_triattention.py
  • Add a SGLang decode-stress benchmark profile, since SGLang TriAttention compression is decode-time driven.

Differences between vLLM and SGLang Workloads

The vLLM benchmark uses a long-prompt workload because the vLLM integration can reclaim KV blocks through block_pool.free_blocks(...), which is routed through kvcached's ElasticBlockPool. As a result, reclaim can directly reduce physical KV memory pressure and show up clearly in peak GPU memory.

SGLang behaves differently. Its TriAttention compression path is decode-time driven, so a very long prompt alone mostly creates a prefill-time memory peak before compression has a chance to help. For SGLang, this PR uses a decode-stress workload: short prompt, long forced decode, min_tokens=max_tokens, and ignore_eos=true. This makes compression and reclaim happen while decode memory is growing, which better exposes the effect in GPU peak memory.

Benchmark Results

Model: Qwen3-8B
GPU memory sampled with nvidia-smi.

vLLM Long-Context Workload

Workload:

  • prompt repeat: 1200
  • max output tokens: 2048
  • concurrencies: 4, 8, 16
  • KV budgets: 1024, 2048
Concurrency KV Budget kvcached Peak kvcached+TriAttention Peak Reduction Compression Events Freed Blocks E2E Change
4 1024 35669 MiB 23329 MiB 12340 MiB / 34.6% 175 6157 -3.6%
4 2048 35669 MiB 23621 MiB 12048 MiB / 33.8% 175 5901 +3.7%
8 1024 45893 MiB 23905 MiB 21988 MiB / 47.9% 331 11644 -23.9%
8 2048 45893 MiB 25061 MiB 20832 MiB / 45.4% 331 11132 -26.0%
16 1024 45893 MiB 25633 MiB 20260 MiB / 44.1% 641 23103 -31.5%
16 2048 45893 MiB 27367 MiB 18526 MiB / 40.4% 639 22542 -31.1%

The vLLM path shows a large peak GPU memory reduction, especially at higher concurrency, because reclaimed KV blocks are returned through kvcached's physical allocator path.

SGLang Decode-Stress Workload

Workload:

  • workload profile: decode-stress
  • prompt repeat: 64
  • prompt tokens: 2010
  • max tokens: 8192
  • min tokens: 8192
  • ignore EOS: true
  • concurrency: 4
  • KV budget: 1024
Mode Success TTFT Mean E2E Mean GPU Peak Compression Events Skipped Events Freed Blocks
kvcached 4/4 230.482 ms 76296.729 ms 25570 MiB 0 0 0
kvcached + TriAttention 4/4 238.556 ms 72940.810 ms 21910 MiB 16 4 34316

SGLang peak GPU memory was reduced by 3660 MiB, or 14.3%.

These happen when a request has already been released by the time a late compression attempt is observed. The successful compression and reclaim path is confirmed by compression_events=16 and freed_blocks=34316.

Validation

pre-commit run --all-files
Passed.

Additional checks:

vLLM benchmark CSV parsed successfully.
SGLang decode-stress benchmark CSV parsed successfully.
SGLang benchmark script syntax check passed.

@RixinLiu RixinLiu requested review from RixinLiu and Copilot June 10, 2026 10:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RixinLiu

Copy link
Copy Markdown
Collaborator

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates the external TriAttention package with SGLang and vLLM serving engines in kvcached. It introduces patch files, documentation, auto-patching logic, and benchmark comparison scripts (compare_sglang_triattention.py and compare_vllm_triattention.py) to evaluate serving performance. The review feedback highlights critical issues in both benchmark scripts where the use of preexec_fn in subprocess.Popen within a multi-threaded context could lead to deadlocks, and potential exceptions during process startup could cause log file resource leaks. It is recommended to replace preexec_fn with start_new_session=True and wrap the process creation in a try...except block to ensure proper resource cleanup.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tools/compare_sglang_triattention.py Outdated
Comment thread tools/compare_vllm_triattention.py Outdated
iMmAseu and others added 2 commits June 14, 2026 11:06
…ero-output bench runs as failures

TriAttention's vLLM integration replaces GPUModelRunner._prepare_inputs with a
wrapper expecting `num_scheduled_tokens`, a calling convention that only exists
in vLLM >= 0.13.0. On vLLM <= 0.11.x the engine crashes on the first decode
step with a cryptic "missing 1 required positional argument: 'num_scheduled_tokens'"
and produces zero output tokens.

- triattention_external: check vllm.__version__ before installing the vLLM
  hooks; raise a clear error below 0.13.0 (instead of crashing mid-decode) and
  warn above the last validated version (0.21.0).
- compare_{vllm,sglang}_triattention: a stream that completes with 0 content
  tokens is now a failure, not success=N/N — so a crashed engine no longer
  reports a (misleadingly low) GPU peak as a win.

Verified: vLLM 0.11.0 now fails fast at startup with a clear message; vLLM
0.13.0 (SGLang 0.5.10) still activate and compress normally.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

4 participants