lightllm icon indicating copy to clipboard operation
lightllm copied to clipboard

[feature] Add prefix_kv_cache transfer between dp rankers.

Open WANDY666 opened this issue 3 weeks ago • 1 comments

WANDY666 avatar Nov 04 '25 06:11 WANDY666

Summary of Changes

Hello @WANDY666, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial optimization for distributed inference by enabling the transfer of prefix KV cache data between different data parallel ranks. This feature aims to improve performance by allowing requests to leverage pre-computed KV states even when processed by different workers. The changes span across core components like memory management, request handling, and the distributed inference backend, supported by a new Triton kernel for efficient data movement and a fix for inter-process CUDA tensor transfers. Additionally, the benchmarking tools have been upgraded to provide more comprehensive performance analysis.

Highlights

  • KV Cache Transfer: Introduced a new Triton kernel (_kv_trans_for_dp_kernel) and a corresponding Python function (kv_trans_for_dp) to efficiently transfer KV cache data between different data parallel (DP) ranks.
  • Memory Management Integration: The MemoryManager now includes a copy_kv_from_other_dp_ranks method, enabling the system to copy prefix KV cache from other DP ranks to the current rank's memory.
  • Request Object Enhancements: The Req object has been extended with dp_max_kv_len and dp_max_kv_rank fields to track the maximum KV cache length and the DP rank possessing it, facilitating prefix cache fetching. It also now manages shared memory arrays for KV indexes.
  • Data Parallel Backend Logic: The DPChunkedPrefillBackend has been updated to support fetching prefix KV cache from other DP ranks, including logic for matching radix cache, coordinating across ranks using dist.barrier(), and performing the KV transfer.
  • CUDA P2P Fix: A new module p2p_fix.py was added to address issues with CUDA tensor serialization and deserialization across processes, which is critical for enabling peer-to-peer (P2P) data transfers between GPUs in a distributed setup.
  • CLI Argument for Control: A new command-line argument --disable_dp_prompt_cache_fetch has been added to allow users to disable the prefix prompt cache fetching feature for data parallel inference.
  • Benchmarking Tool Improvements: The benchmark_sharegpt.py script has been significantly enhanced to support OpenAI API format, concurrency control, and more detailed latency metrics including time to first token and inter-token latency.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot] avatar Nov 04 '25 06:11 gemini-code-assist[bot]