Skip to content

[Bugfix] fix the wrong use of extract_slice and insert_slice#6956

Closed
wangx700 wants to merge 3 commits intovllm-project:mainfrom
wangx700:fix_ta_interface
Closed

[Bugfix] fix the wrong use of extract_slice and insert_slice#6956
wangx700 wants to merge 3 commits intovllm-project:mainfrom
wangx700:fix_ta_interface

Conversation

@wangx700
Copy link
Copy Markdown
Contributor

@wangx700 wangx700 commented Mar 3, 2026

What this PR does / why we need it?

fix the wrong use of extract_slice and insert_slice. In the TritonAscend main branch, extract_slice and insert_slice are located in the triton.language.extra.cann.extension library, rather than in the triton.language library

Does this PR introduce any user-facing change?

How was this patch tested?

…end main branch, extract_slice and insert_slice are located in

the triton.language.extra.cann.extension library, rather than in the
triton.language library

Signed-off-by: wangx700 <wangxin700@huawei.com>
@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 resolves an issue where Triton's extract_slice and insert_slice functions were incorrectly referenced in vllm_ascend modules, specifically for the TritonAscend environment. By introducing conditional imports, the change ensures that the correct versions of these functions are used, enhancing the adaptability and stability of the codebase across different Triton configurations without requiring manual adjustments.

Highlights

  • Conditional Import for Triton Slicing Functions: Implemented a conditional import mechanism for extract_slice and insert_slice functions. The code now attempts to import these functions from triton.language.extra.cann.extension first, falling back to triton.language if the specialized extension is not available. This ensures compatibility with the TritonAscend main branch where these functions are located in a different module.
  • Updated Usage of Slicing Functions: All direct calls to tl.extract_slice and tl.insert_slice across the affected files have been replaced with the newly defined extract_slice and insert_slice variables, which dynamically resolve to the correct implementation based on the conditional import.

🧠 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.

Changelog
  • vllm_ascend/ops/triton/activation/swiglu_quant.py
    • Added conditional import logic for extract_slice to support triton.language.extra.cann.extension.
    • Updated all usages of tl.extract_slice to use the newly defined extract_slice variable.
  • vllm_ascend/ops/triton/fla/solve_tril.py
    • Added conditional import logic for insert_slice and extract_slice to support triton.language.extra.cann.extension.
    • Updated all usages of tl.insert_slice and tl.extract_slice to use the newly defined insert_slice and extract_slice variables.
  • vllm_ascend/ops/triton/linearnorm/split_qkv_rmsnorm_rope.py
    • Added conditional import logic for insert_slice and extract_slice to support triton.language.extra.cann.extension.
    • Updated all usages of tl.insert_slice and tl.extract_slice to use the newly defined insert_slice and extract_slice variables.
Activity
  • No specific activity has been recorded for this pull request yet.
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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

👋 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
Copy Markdown
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

The pull request correctly identifies and addresses the issue of extract_slice and insert_slice being located in a specific Triton extension library (triton.language.extra.cann.extension) rather than the standard triton.language module in the TritonAscend main branch. The changes introduce conditional imports to use the extension's functions if available, falling back to the standard tl module otherwise. This improves compatibility across different Triton environments.

However, the fallback mechanism in the except ImportError block assumes that tl.extract_slice and tl.insert_slice will always exist in the triton.language module. Given the PR description stating these functions are "rather than in the triton.language library" for the specific branch, this assumption might be incorrect and could lead to AttributeError if the standard tl module does not define these functions. A more robust fallback is suggested to explicitly check for the existence of these functions in tl or raise a more informative error.

Comment on lines +6 to +10
try:
import triton.language.extra.cann.extension as extension
extract_slice = extension.extract_slice
except ImportError:
extract_slice = tl.extract_slice
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.

high

The current try-except ImportError block assumes that tl.extract_slice will always be available if triton.language.extra.cann.extension cannot be imported. However, the PR description indicates that these functions might not be in the standard triton.language library for the TritonAscend main branch. If tl.extract_slice is indeed missing, this fallback will result in an AttributeError at runtime.

To make this more robust, consider explicitly checking for the existence of tl.extract_slice or handling AttributeError in the fallback, or raising a more specific error if neither source provides the function.

try:
    import triton.language.extra.cann.extension as extension
    extract_slice = extension.extract_slice
except ImportError:
    if hasattr(tl, 'extract_slice'):
        extract_slice = tl.extract_slice
    else:
        raise RuntimeError("Neither triton.language.extra.cann.extension.extract_slice nor tl.extract_slice is available.")

Comment on lines +17 to 24
try:
import triton.language.extra.cann.extension as extension
insert_slice = extension.insert_slice
extract_slice = extension.extract_slice
except ImportError:
insert_slice = tl.insert_slice
extract_slice = tl.extract_slice

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.

high

Similar to the issue in swiglu_quant.py, the fallback in the except ImportError block assumes tl.insert_slice and tl.extract_slice are always present. If these functions are not part of the standard triton.language module in some environments, this could lead to an AttributeError.

It's recommended to add a check for the existence of these functions in tl or to catch AttributeError to provide a more graceful failure or a clearer error message.

Suggested change
try:
import triton.language.extra.cann.extension as extension
insert_slice = extension.insert_slice
extract_slice = extension.extract_slice
except ImportError:
insert_slice = tl.insert_slice
extract_slice = tl.extract_slice
try:
import triton.language.extra.cann.extension as extension
insert_slice = extension.insert_slice
extract_slice = extension.extract_slice
except ImportError:
if hasattr(tl, 'insert_slice') and hasattr(tl, 'extract_slice'):
insert_slice = tl.insert_slice
extract_slice = tl.extract_slice
else:
raise RuntimeError("Neither triton.language.extra.cann.extension nor tl provides insert_slice/extract_slice.")

Comment on lines +25 to 32
try:
import triton.language.extra.cann.extension as extension
insert_slice = extension.insert_slice
extract_slice = extension.extract_slice
except ImportError:
insert_slice = tl.insert_slice
extract_slice = tl.extract_slice

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.

high

The conditional import for insert_slice and extract_slice has the same potential issue as identified in the other files. If triton.language.extra.cann.extension fails to import, the fallback to tl.insert_slice and tl.extract_slice might fail with an AttributeError if these functions are not defined in the standard triton.language module for the current environment.

Please implement a more robust fallback mechanism to ensure these functions are available or to provide a clear error if they are not.

try:
    import triton.language.extra.cann.extension as extension
    insert_slice = extension.insert_slice
    extract_slice = extension.extract_slice
except ImportError:
    if hasattr(tl, 'insert_slice') and hasattr(tl, 'extract_slice'):
        insert_slice = tl.insert_slice
        extract_slice = tl.extract_slice
    else:
        raise RuntimeError("Neither triton.language.extra.cann.extension nor tl provides insert_slice/extract_slice.")

wangx700 added 2 commits March 3, 2026 17:28
Signed-off-by: wangx700 <wangxin700@huawei.com>
Signed-off-by: wangx700 <wangxin700@huawei.com>
@wangx700 wangx700 changed the title fix the wrong use of extract_slice and insert_slice [Bugfix]fix the wrong use of extract_slice and insert_slice Mar 3, 2026
@wangx700 wangx700 changed the title [Bugfix]fix the wrong use of extract_slice and insert_slice [Bugfix] fix the wrong use of extract_slice and insert_slice Mar 3, 2026
Copy link
Copy Markdown
Collaborator

@linfeng-yuan linfeng-yuan left a comment

Choose a reason for hiding this comment

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

#6937 has already been merged to avoid these cases and keep compatibility between triton-ascend 3.2 and newest one. Please check that whether it can help with your case~


insert_slice = extension.insert_slice
extract_slice = extension.extract_slice
except ImportError:
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.

you could move the same logic to triton_utils.py

@wangx700 wangx700 closed this Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants