- 
                Notifications
    You must be signed in to change notification settings 
- Fork 530
[Perf] Move attention update stream out of loop to optimize performance #3848
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
base: main
Are you sure you want to change the base?
Conversation
| 👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge: 
 If CI fails, you can run linting and testing checks locally according Contributing and Testing. | 
There was a problem hiding this 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 correctly optimizes the update_attn_params function in vllm_ascend/compilation/acl_graph.py by moving the torch.npu.stream context manager outside the for loop. This change effectively reduces the overhead of stream context switching, leading to a performance improvement. The implementation is correct. For consistency and further optimization, consider applying the same pattern to update_mla_attn_params, update_attn_dcp_pcp_params, and update_mla_attn_dcp_pcp_params in the same file, as they exhibit a similar structure.
6b3c8a6    to
    298e13c      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also refactor update_mla_attn_dcp_pcp_params and update_attn_dcp_pcp_params.
| 
 | 
5dcf47b    to
    f7041fb      
    Compare
  
    | This pull request has conflicts, please resolve those before we can evaluate the pull request. | 
Signed-off-by: wangxiaoxin-sherie <[email protected]>
What this PR does / why we need it?
In the
update_*attn_paramsfunctions, thetorch.npu.stream(update_stream)context manager was previously located inside the for-loop that updates parameters for each layer. This resulted in redundant stream initiations for every layer, adding unnecessary overhead.This commit refactors the code by moving the stream context manager to wrap the entire for-loop. This ensures that the update stream is initiated only once per function call, rather than for each layer. This change reduces 90us in each decode model.

update stream in every layer:
remove update stream in every layer:

Does this PR introduce any user-facing change?
How was this patch tested?