fix: RuntimeError in free_kv_cache with vLLM v1 (0.19+)#14
Open
IthaloPS wants to merge 1 commit into
Open
Conversation
In vLLM v1, `attn_module.kv_cache` is a Tensor, not a list. Using `if kv_list` on a multi-element Tensor raises: RuntimeError: Boolean value of Tensor with more than one value is ambiguous Replace `if kv_list` with `if kv_list is not None` in both `turboquant/integration/vllm.py` and `turboquant/vllm_attn_backend.py`. Verified on: vLLM 0.19.1, PyTorch 2.10, CUDA 12.8, RTX 3090 (24GB) Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When running TurboQuant with vLLM 0.19+ (v1 engine), calling
free_kv_cacheraises:Traceback points to
free_kv_cachein bothturboquant/integration/vllm.pyandturboquant/vllm_attn_backend.py:In vLLM v1,
attn_module.kv_cacheis a Tensor, not a Python list. Evaluating a multi-element Tensor as a boolean is ambiguous in PyTorch and raises the error.Fix
Replace the truthiness check with an explicit
Nonecheck in all 3 occurrences across both files:Tested on
Benchmark results (RTX 3090 24GB — Qwen3.5-9B, TP=1, max_len=32768)
After the fix, TurboQuant runs end-to-end including
free_kv_cache:The throughput gain is higher than reported for the 27B model because the 9B model is more memory-bound on a single 24 GB GPU, so KV cache compression reduces the decode bottleneck more aggressively.
Made with Cursor