Skip to content

A5 support reshape and cache in CP situation#7636

Open
lenghuixing0330 wants to merge 4 commits intovllm-project:mainfrom
lenghuixing0330:scatter_fix
Open

A5 support reshape and cache in CP situation#7636
lenghuixing0330 wants to merge 4 commits intovllm-project:mainfrom
lenghuixing0330:scatter_fix

Conversation

@lenghuixing0330
Copy link

@lenghuixing0330 lenghuixing0330 commented Mar 25, 2026

What this PR does / why we need it?

The reshape and cache operators of A5 require that the inputs be contiguous.
In some scenarios, such as sequence parallelism, there are some non-contiguous operations, such as slicing with intervals.
slot_mapping = attn_metadata.slot_mapping[: num_decode_tokens * self.pcp_size : self.pcp_size], where slot_mapping is non-contiguous and needs to be contiguous.

Does this PR introduce any user-facing change?

How was this patch tested?

Signed-off-by: lenghuixing0330 <2531948770@qq.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! 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 enhances A5 device support for KV cache reshape and cache operations within the context parallel attention module. It streamlines the interaction with device-specific operations by routing them through a dedicated DeviceOperator, standardizes parameter naming for clarity, and enforces tensor contiguity for key and slot mapping data, which is vital for efficient processing on NPU hardware.

Highlights

  • Centralized KV Cache Operations: The reshape_and_cache calls within the context parallel attention mechanism have been refactored to utilize the DeviceOperator class, centralizing device-specific operations.
  • Parameter Name Standardization: The parameter name slot_indices has been updated to slot_mapping in the reshape_and_cache function calls for consistency.
  • Tensor Contiguity Enforcement: The reshape_and_cache method in DeviceOperator now explicitly ensures that the key and slot_mapping tensors are contiguous before being passed to the underlying NPU scatter KV cache function, which can be crucial for performance and correctness on Ascend devices.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 👍 and 👎 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.

Footnotes

  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.

@github-actions
Copy link
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

Copy link
Contributor

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

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 refactors the reshape_and_cache operation by introducing a DeviceOperator abstraction. It moves the direct calls to torch_npu._npu_reshape_and_cache into this new operator, improving modularity and maintainability. Additionally, the reshape_and_cache method within the A5DeviceAdaptor is updated to ensure that the key, value, and slot_mapping tensors are contiguous before being passed to torch_npu.npu_scatter_pa_kv_cache, which can enhance performance and prevent potential issues with non-contiguous data. The argument name slot_indices is also updated to slot_mapping for consistency. There are no review comments to address.

Signed-off-by: lenghuixing0330 <2531948770@qq.com>
Signed-off-by: lenghuixing0330 <2531948770@qq.com>
Signed-off-by: lenghuixing0330 <2531948770@qq.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.

1 participant