Skip to content

Conversation

@heheda12345
Copy link
Collaborator

@heheda12345 heheda12345 commented Mar 1, 2025

As KVCacheBlock is a doubly linked list, the default print of one block will recursively print all KVCacheBlock objects in the list, and can cause stack overflow. To avoid this problem, print prev_block_id and next_block_id instead.

Reproduce script from vllm.multimodal.inputs import MultiModalKwargs from vllm.sampling_params import SamplingParams from vllm.v1.core.kv_cache_manager import KVCacheManager from vllm.v1.request import Request

def make_request(request_id,
prompt_token_ids,
mm_positions=None,
mm_hashes=None):
if mm_positions is None:
multi_modal_inputs = None
else:
multi_modal_inputs = [MultiModalKwargs({})] * len(mm_positions)

return Request(
    request_id=request_id,
    prompt=None,
    prompt_token_ids=prompt_token_ids,
    multi_modal_inputs=multi_modal_inputs,
    multi_modal_hashes=mm_hashes,
    multi_modal_placeholders=mm_positions,
    sampling_params=SamplingParams(max_tokens=17),
    eos_token_id=100,
    arrival_time=0,
    lora_request=None,
)

manager = KVCacheManager(
block_size=16,
num_gpu_blocks=10000,
max_model_len=819200,
sliding_window=None,
enable_caching=True,
num_preallocate_tokens=16,
)

common_token_ids = [i for i in range(10) for _ in range(16)]
req0 = make_request("0", common_token_ids)
computed_blocks, num_computed_tokens = manager.get_computed_blocks(req0)
blocks = manager.allocate_slots(req0, 55, computed_blocks)
manager.free(req0)

req1 = make_request("1", common_token_ids)
computed_blocks, num_computed_tokens = manager.get_computed_blocks(req1)
print("computed_blocks", computed_blocks)

Signed-off-by: Chen Zhang <zhangch99@outlook.com>
@github-actions
Copy link

github-actions bot commented Mar 1, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the v1 label Mar 1, 2025
@comaniac comaniac added the ready ONLY add when PR is ready to merge/full CI is needed label Mar 1, 2025
@comaniac comaniac enabled auto-merge (squash) March 1, 2025 19:27
@comaniac comaniac merged commit d54990d into vllm-project:main Mar 1, 2025
47 of 49 checks passed
lulmer pushed a commit to lulmer/vllm that referenced this pull request Apr 7, 2025
shreyankg pushed a commit to shreyankg/vllm that referenced this pull request May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants