Skip to content

Smaller available space for paged KV cache compared with vLLM #224

Closed

Description

@yunfeng-scale

Built an engine with

python /code/tensorrt_llm/examples/llama/build.py --model_dir /model_weights/llama-2-7b                 --dtype float16                 --remove_input_padding                 --use_gpt_attention_plugin float16                 --enable_context_fmha                 --use_gemm_plugin float16                 --output_dir /model_weights/llama-2-7b-trt-llm                 --max_batch_size 25                 --max_output_len 4096                 --use_inflight_batching                 --tokens_per_block 16

and use 0.95 for kv_cache_free_gpu_mem_fraction.

Running on an A10 with TRT-LLM Triton backend, I'm seeing the paged KV cache size to be 10718 tokens from logs

[TensorRT-LLM][INFO] Using 10718 tokens in paged KV cache.

Is 10718 tokens actually 10718 blocks since 10718 does not divide 16?
Using vLLM I'm getting GPU block of 8348 out of the box (0.9 free memory ratio), and block size is 16 by default.

Activity

  1. self-assigned this
    on Nov 1, 2023
  2. schetlur-nv commented on Nov 1, 2023

    @schetlur-nv
    Collaborator

    Hey, thanks for the question. That is indeed the number of tokens calculated based on user provided-constaints, but it gets rounded up to the next multiple of block size during allocation in the KV cache. We will fix the log message to be more accurate.

  3. added
    question
    triaged
    on Nov 2, 2023
  4. removed their assignment
    on Nov 2, 2023
  5. jdemouth-nvidia commented on Nov 2, 2023

    @jdemouth-nvidia
    Collaborator

    Hi @yunfeng-scale ,

    Thanks for your question. As @schetlur-nv explained, that's indeed the number of tokens. However, we are wondering why the difference between TensorRT-LLM and vLLM is that large. The weights should occupy around 14GB so we think there must be space for TensorRT-LLM to allocate a bigger KV cache. Do you have the log that was produced by TensorRT-LLM during the compilation, please? If not, we'll generate one ourselves.

    Thanks,
    Julien

  6. kaiyux commented on Nov 7, 2023

    @kaiyux
    Member

    Hi @yunfeng-scale , we pushed an update to the main branch, the log messages on KV cache are more accurate now. Feel free to let us know if there are further questions, thank you.

  7. yunfeng-scale commented on Nov 7, 2023

    @yunfeng-scale
    Author

    Hi @yunfeng-scale ,

    Thanks for your question. As @schetlur-nv explained, that's indeed the number of tokens. However, we are wondering why the difference between TensorRT-LLM and vLLM is that large. The weights should occupy around 14GB so we think there must be space for TensorRT-LLM to allocate a bigger KV cache. Do you have the log that was produced by TensorRT-LLM during the compilation, please? If not, we'll generate one ourselves.

    Thanks, Julien

    Sorry I can't reproduce the numbers with vLLM and 7b model. Tried again today and I'm getting 868 blocks on vLLM and that's 13888 tokens. That's still larger that TRT-LLM. It would be nice to match the size of kv cache

  8. schetlur-nv commented on Dec 11, 2023

    @schetlur-nv
    Collaborator

    Hey @yunfeng-scale can you confirm if you still see this issue? We have made several updates to optimize memory savings in the past month or so.

  9. schetlur-nv commented on Dec 20, 2023

    @schetlur-nv
    Collaborator

    @yunfeng-scale I will close this issue now. Please feel free to leave a comment or open a new issue if you have more questions.

  10. achartier commented on Jan 12, 2024

    @achartier
    Collaborator

    @yunfeng-scale We were able to reproduce your numbers but found they are likely due to different default values for the number of input tokens. Using the following values to build the TRT-LLM engine would match the vLLM default values:
    --max_batch_size 256 --max_num_tokens 2048

    With that engine, TRT-LLM is able to allocate a larger KV cache size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questiontriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions