Skip to content

[BugFix][Mamba] Fix staged-write kernel and duplicate is_prefilling argument - #14649

Merged
weijinqian0 merged 4 commits into
vllm-project:mainfrom
Lethobenthos20:fix-mamba-triton
Aug 26, 2026
Merged

weijinqian0 merged 4 commits into
vllm-project:mainfrom
Lethobenthos20:fix-mamba-triton

Conversation

@Lethobenthos20

@Lethobenthos20 Lethobenthos20 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two issues in the Ascend V2 Runner inference path:

  1. Fixes incorrect index/address offset calculation in the block-table staged-write Triton kernel, which caused:

    PtroffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
    
  2. Fixes the duplicate is_prefilling argument passed to AscendCommonAttentionMetadata, which caused:

     got multiple values for keyword argument 'is_prefilling'
    

    After these changes, V2 Runner inference works correctly with curl and aisbench.

@gemini-code-assist

Copy link
Copy Markdown
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 addresses critical stability and runtime issues in the Ascend V2 Runner inference path. By correcting memory access patterns in the Mamba state copy kernel and resolving argument collisions in attention metadata, the changes ensure reliable execution across different inference workloads. Additionally, it integrates NPU-optimized sampling operations to improve performance.

Highlights

  • Triton Kernel Fix: Corrected the index and address offset calculation in the block-table staged-write Triton kernel to prevent assertion failures.
  • Argument Conflict Resolution: Resolved a duplicate 'is_prefilling' argument error in AscendCommonAttentionMetadata by properly managing keyword arguments.
  • Sampler Integration: Added support for NPU-specific top-k/top-p sampling by patching the sampler operation.
New Features

🧠 You can now enable Memory (public preview) 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 the 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 counterproductive. 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. ↩

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Suggested PR Title:

[Ops][Feature] Implement Ascend-safe Mamba pre-copy kernel and patch sampler/attention metadata

Suggested PR Summary:

### What this PR does / why we need it?

This PR introduces several compatibility and safety improvements for running vLLM on Ascend NPU:
1. **Ascend-Safe Mamba Pre-copy Kernel**: Adds a custom Triton kernel `precopy_mamba_align_fused_kernel` in `vllm_ascend/ops/triton/mamba/precopy.py` and patches it in `patch_mamba_utils.py`. This implementation hoists pointer casts out of copy loops to prevent Triton-Ascend's AxisInfo analysis from aborting.
2. **Top-K/Top-P Sampler Patching**: Patches `topk_topp_sampler.apply_top_k_top_p` to use the NPU-specific `_apply_top_k_top_p_torch_npu` implementation.
3. **Attention Metadata Fix**: Safely extracts `is_prefilling` from `common_attn_metadata_extra_kwargs` in `build_attn_metadata` to avoid potential duplicate argument errors or incorrect states.

### Does this PR introduce _any_ user-facing change?

No. These are internal backend patches and kernel implementations for Ascend NPU support.

### How was this patch tested?

No specific tests were added in this PR. The changes are expected to be verified via existing integration tests on Ascend hardware.

@github-actions

Copy link
Copy Markdown
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.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [BugFix] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

Comment thread vllm_ascend/utils.py Outdated
from vllm.v1.sample.ops import topk_topp_sampler
from vllm_ascend.sample.sampler import _apply_top_k_top_p_torch_npu

topk_topp_sampler.apply_top_k_top_p = _apply_top_k_top_p_torch_npu

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply_top_k_top_p has been fixed on ascend. No need to do patch here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I removed the redundant patch and pushed a new commit.

@LoganJane LoganJane added ready ready-precise run selected e2e test for pr and removed ready labels Aug 24, 2026
common_is_prefilling = common_attn_metadata_extra_kwargs.pop(
"is_prefilling",
is_prefilling,
)
common_attn_metadata = AscendCommonAttentionMetadata(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm the reason why the value is repeatedly transferred.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. This follows the same pattern already used upstream in vllm/v1/worker/gpu/attn_utils.py around line 545:

group_is_prefilling = common_attn_metadata_extra_kwargs.pop(
    "is_prefilling", is_prefilling
)

It allows the model-specific, padding-aware is_prefilling value to take precedence over the default, so I believe this change is still necessary.

Comment on lines 183 to 184
is_prefilling: torch.Tensor | None = None,
pcp_context: "AscendPCPAttentionContext | None" = None,
model_specific_attn_metadata: ModelSpecificAttnMetadata | None = None,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should check out why there is is_prefilling in both here and model_specific_attn_metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. This follows the same pattern already used upstream in vllm/v1/worker/gpu/attn_utils.py around line 545:

group_is_prefilling = common_attn_metadata_extra_kwargs.pop(
    "is_prefilling", is_prefilling
)

It allows the model-specific, padding-aware is_prefilling value to take precedence over the default, so I believe this change is still necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your effort. CC @weijinqian0.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, we'd better change common_is_prefilling to group_is_prefilling, to align with vllm.

weijinqian0
weijinqian0 previously approved these changes Aug 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Signed-off-by: Lethobenthos20 <3205604419@qq.com>
@weijinqian0
weijinqian0 merged commit aeb8e76 into vllm-project:main Aug 26, 2026
44 checks passed
pisceskkk pushed a commit to pisceskkk/vllm-ascend that referenced this pull request Aug 26, 2026
…rgument (vllm-project#14649)

## Summary

This PR fixes two issues in the Ascend V2 Runner inference path:

1. Fixes incorrect index/address offset calculation in the block-table
staged-write Triton kernel, which caused:

   ```text
   PtroffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
2. Fixes the duplicate is_prefilling argument passed to
AscendCommonAttentionMetadata, which caused:
    ```text
     got multiple values for keyword argument 'is_prefilling'
     ```
After these changes, V2 Runner inference works correctly with curl and
aisbench.

- vLLM version: v0.27.1
- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Signed-off-by: QiuChunshuo <qiuchunshuo@huawei.com>
frankie-ys pushed a commit to Csrayz/vllm-ascend that referenced this pull request Aug 26, 2026
…rgument (vllm-project#14649)

## Summary

This PR fixes two issues in the Ascend V2 Runner inference path:

1. Fixes incorrect index/address offset calculation in the block-table
staged-write Triton kernel, which caused:

   ```text
   PtroffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
2. Fixes the duplicate is_prefilling argument passed to
AscendCommonAttentionMetadata, which caused:
    ```text
     got multiple values for keyword argument 'is_prefilling'
     ```
After these changes, V2 Runner inference works correctly with curl and
aisbench.

- vLLM version: v0.27.1
- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
ASH-XING pushed a commit to ASH-XING/vllm-ascend that referenced this pull request Aug 26, 2026
…rgument (vllm-project#14649)

## Summary

This PR fixes two issues in the Ascend V2 Runner inference path:

1. Fixes incorrect index/address offset calculation in the block-table
staged-write Triton kernel, which caused:

   ```text
   PtroffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
2. Fixes the duplicate is_prefilling argument passed to
AscendCommonAttentionMetadata, which caused:
    ```text
     got multiple values for keyword argument 'is_prefilling'
     ```
After these changes, V2 Runner inference works correctly with curl and
aisbench.

- vLLM version: v0.27.1
- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Signed-off-by: d30086105 <denghaojie1@h-partners.com>
weijinqian0 pushed a commit that referenced this pull request Aug 27, 2026
### What this PR does / why we need it?

This PR fixes the following Triton Ascend assertion failure in the Mamba
state pre-copy kernel:

```text
PtrOffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
```
This issue was also observed in #7103 and #10888 .
This PR also:
- Adds an end-to-end test covering the supported layouts and execution
modes.
- Adds documentation for the kernel behavior, parameters, constraints,
and usage.
This is a follow-up to #14649.

After these changes, V2 Runner inference works correctly. 

- vLLM version: v0.27.1
- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
ASH-XING pushed a commit to ASH-XING/vllm-ascend that referenced this pull request Aug 28, 2026
…oject#15032)

### What this PR does / why we need it?

This PR fixes the following Triton Ascend assertion failure in the Mamba
state pre-copy kernel:

```text
PtrOffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
```
This issue was also observed in vllm-project#7103 and vllm-project#10888 .
This PR also:
- Adds an end-to-end test covering the supported layouts and execution
modes.
- Adds documentation for the kernel behavior, parameters, constraints,
and usage.
This is a follow-up to vllm-project#14649.

After these changes, V2 Runner inference works correctly.

- vLLM version: v0.27.1
- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Signed-off-by: d30086105 <denghaojie1@h-partners.com>
Lethobenthos20 added a commit to Lethobenthos20/vllm-ascend that referenced this pull request Sep 4, 2026
…rgument (vllm-project#14649)

## Summary

This PR fixes two issues in the Ascend V2 Runner inference path:

1. Fixes incorrect index/address offset calculation in the block-table
staged-write Triton kernel, which caused:

   ```text
   PtroffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
2. Fixes the duplicate is_prefilling argument passed to
AscendCommonAttentionMetadata, which caused:
    ```text
     got multiple values for keyword argument 'is_prefilling'
     ```
After these changes, V2 Runner inference works correctly with curl and
aisbench.

- vLLM version: v0.27.1
- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Lethobenthos20 added a commit to Lethobenthos20/vllm-ascend that referenced this pull request Sep 4, 2026
…oject#15032)

### What this PR does / why we need it?

This PR fixes the following Triton Ascend assertion failure in the Mamba
state pre-copy kernel:

```text
PtrOffsetInfo::AxisInfo::operator[]: Assertion `idx < size()` failed
```
This issue was also observed in vllm-project#7103 and vllm-project#10888 .
This PR also:
- Adds an end-to-end test covering the supported layouts and execution
modes.
- Adds documentation for the kernel behavior, parameters, constraints,
and usage.
This is a follow-up to vllm-project#14649.

After these changes, V2 Runner inference works correctly. 

- vLLM version: v0.27.1
- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: Lethobenthos20 <3205604419@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants