[Performance] Change the shape of kv_cache to avoid view of k_cache and v_cache.#204
Merged
wangxiyuan merged 1 commit intovllm-project:mainfrom Mar 5, 2025
Merged
Conversation
894b170 to
fb6686e
Compare
MengqingCao
reviewed
Feb 28, 2025
| num_layers = len(self.cache_engine[ve].gpu_cache) | ||
| for i in range(num_layers): | ||
| self.cache_engine[ve].gpu_cache[i] = torch_npu.npu_format_cast( | ||
| self.cache_engine[ve].gpu_cache[i], 2) |
Collaborator
There was a problem hiding this comment.
The official doc states that torch_npu.npu_format_cast is a inplace op, maybe we have no need to receive the return value.
And the next question, why 2 here?
https://www.hiascend.com/document/detail/zh/Pytorch/600/apiref/apilist/ptaoplist_000449.html#ZH-CN_TOPIC_0000002173377585__zh-cn_topic_0000002137977492_section1261113545317
Collaborator
Author
There was a problem hiding this comment.
That makes sense. I'll change it to inplace.
Using 2 here is to cast the format from NCDHW to ND (2 indicates ND). This is because when we construct a tensor of more than 4 dimensions, the format of this tensor is NCDHW, while our operations only supports data in ND format.
fbb81fb to
cb3c3ab
Compare
wangxiyuan
approved these changes
Mar 3, 2025
Collaborator
Collaborator
|
|
…_cache; cache the metadata of k_cache and v_cache to avoid replicated slice operation Signed-off-by: hw_whx <wanghexiang7@huawei.com>
cb3c3ab to
a2277a7
Compare
wangxiyuan
approved these changes
Mar 5, 2025
wangxiyuan
pushed a commit
to wangxiyuan/vllm-ascend
that referenced
this pull request
Mar 7, 2025
…nd v_cache. (vllm-project#204) This PR changes the shape of kv cache to avoid the view of k_cache and v_cache. What's more, cache the metadata of k_cache and v_cache to avoid duplicative slice operations to improve performance. Signed-off-by: hw_whx <wanghexiang7@huawei.com>
wangxiyuan
pushed a commit
to wangxiyuan/vllm-ascend
that referenced
this pull request
Mar 7, 2025
…nd v_cache. (vllm-project#204) This PR changes the shape of kv cache to avoid the view of k_cache and v_cache. What's more, cache the metadata of k_cache and v_cache to avoid duplicative slice operations to improve performance. Signed-off-by: hw_whx <wanghexiang7@huawei.com> Signed-off-by: wangxiyuan <wangxiyuan1007@gmail.com>
ttanzhiqiang
pushed a commit
to ttanzhiqiang/vllm-ascend
that referenced
this pull request
Apr 27, 2025
…nd v_cache. (vllm-project#204) This PR changes the shape of kv cache to avoid the view of k_cache and v_cache. What's more, cache the metadata of k_cache and v_cache to avoid duplicative slice operations to improve performance. Signed-off-by: hw_whx <wanghexiang7@huawei.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR changes the shape of kv cache to avoid the view of k_cache and v_cache.
What's more, cache the metadata of k_cache and v_cache to avoid duplicative slice operations to improve performance.