Skip to content

Conversation

@MichelleWu351
Copy link

@MichelleWu351 MichelleWu351 commented Nov 1, 2025

This pull request aims to support the ‘enable-mixed-chunk feature‘ on Ascend NPUs. It merges the current decode requests with upcoming prefill requests into the same batch.
We use a new ‘forward_mixed‘’ method within AscendAttnBackend to specifically handle mixed-chunk attention, leveraging ‘torch_npu._npu_paged_attention_splitfuse‘ for optimized NPU operations.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MichelleWu351, 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 introduces support for 'enable-mixed-chunk' attention specifically tailored for Ascend NPUs. It integrates a new attention forwarding mechanism that utilizes NPU-specific paged attention split-fuse operations, complemented by a robust system for dynamic attention mask generation and caching. This feature aims to optimize attention computations for mixed-chunk scenarios on Ascend hardware, enhancing overall performance and efficiency. Additionally, the PR includes minor refinements to the memory allocator and scheduling policy for improved stability and correctness.

Highlights

  • Ascend Mixed-Chunk Attention: Implemented a new forward_mixed method within AscendAttnBackend to specifically handle mixed-chunk attention, leveraging torch_npu._npu_paged_attention_splitfuse for optimized NPU operations.
  • Dynamic Attention Mask Management: Introduced a comprehensive system for generating, caching, and updating attention masks, including _generate_attn_mask, _update_attn_cache, get_splitfuse_attn_mask, and get_attention_mask_id, to support the new mixed-chunk processing.
  • Base Attention Backend Extension: The AttentionBackend base class now includes an abstract forward_mixed method, ensuring that all attention backends can properly implement and support this new attention mode.
  • Memory Allocator Refinement: Enhanced the memory allocator by ensuring that the list of free page indices (self.free_pages) contains only unique entries, preventing potential issues from duplicate page references.
  • Scheduling Policy Adjustment: Modified the scheduling policy's condition for chunked prefill from self.rem_chunk_tokens == 0 to self.rem_chunk_tokens <= 0, improving robustness for edge cases.
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.

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.

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.

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 adds support for mixed-chunk batches in the Ascend backend, which is a significant feature for improving throughput by combining prefill and decode operations. The changes include a new forward_mixed method in the attention backend, logic for generating specialized attention masks, and a critical correctness fix in the memory allocator. My review focuses on ensuring the correctness and performance of these new additions. I've identified a potential bug in attention mask generation for bfloat16 data types, a performance improvement opportunity in mask ID generation, and a minor maintainability issue with a hardcoded value. The fix in the memory allocator is crucial for preventing data corruption and is a great addition.

@iforgetmyname iforgetmyname marked this pull request as draft November 1, 2025 13:38
Refactor attention mask generation to use a constant for cache size and simplify mask value assignment.
@MichelleWu351 MichelleWu351 marked this pull request as ready for review November 3, 2025 02:57
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