Skip to content

[0.9.1]optmize rope in qwen2 #1782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v0.9.1-dev
Choose a base branch
from

Conversation

David9857
Copy link
Contributor

What this PR does / why we need it?

Does this PR introduce any user-facing change?

How was this patch tested?

Signed-off-by: rjg-lyh <1318825571@qq.com>
Copy link

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

# TODO: Remove the contiguous in the future.
query = query.contiguous().view(query.shape[0], -1)
key = key.contiguous().view(key.shape[0], -1)
torch_npu._npu_rotary_embedding(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you considering using the npu_mrope operator here?

Copy link
Contributor Author

@David9857 David9857 Jul 15, 2025

Choose a reason for hiding this comment

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

Are you considering using the npu_mrope operator here?

Not sure if npu_mrope performs exactly the same with _npu_rotary_embedding, so I keep this part unchanged.

David9857 and others added 2 commits July 14, 2025 20:07
Signed-off-by: David9857 <985700846@qq.com>
use npu_apply_rotary_pos_emb when head_size is 128 and is noex_style

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

Optimize rope by extracting index_select from layers into model, which
can reduce (layer_num -1) * 2 Gather ops in each prefill/decode stage.

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

NA

### How was this patch tested?

NA

---------

Signed-off-by: David9857 <985700846@qq.com>
@wangxiyuan wangxiyuan changed the title optmize rope in qwen2 [0.9.1]optmize rope in qwen2 Jul 15, 2025
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