[bugfix] Fix MHA model runtime error in aclgraph mode - #5397
Conversation
There was a problem hiding this comment.
Code Review
This pull request aims to fix a runtime error for MHA models in aclgraph mode. It introduces a change in the attention mechanism to correctly slice key and value tensors during the prefill stage. Additionally, it expands test coverage by parameterizing an existing test to include both MHA and GQA models. My review identifies a critical issue where the query tensor is not being sliced consistently with the key and value tensors in the aclgraph capture path, which could lead to shape mismatch errors. A fix is suggested to ensure tensor shapes are consistent.
|
👋 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. |
| actual_seq_lengths_kv = attn_metadata.actual_seq_lengths_q | ||
| num_tokens_kv = actual_seq_lengths_kv[-1] | ||
| key = key[:num_tokens_kv] | ||
| value = value[:num_tokens_kv] |
There was a problem hiding this comment.
move this to eager or piecewise branch.
Signed-off-by: Wang Kunpeng <1289706727@qq.com>
26582e0 to
51c3f5c
Compare
) ### What this PR does / why we need it? Currently, MHA models (eg: minicpm-2b, Baichuan-7b) will encounter errors when running in piecewise graph mode, with error messages similar to: ``` (E89999): When layout is TND and PA not enabled, keyT(8) and valueT(8) must be equal to the last element of actualSeqenceLengthKV(5)[FUNC:CheckInputShapeWhenLayoutIsTND][FILE:prompt_flash_attention_tiling.cpp][LINE:3618] ``` The error occurs because the qkv in the Prefill stage is also padded, causing the shape to be inconsistent with actual_seq_lengths. Add unpadding logic for kv. - vLLM version: release/v0.13.0 - vLLM main: vllm-project/vllm@254f6b9 Signed-off-by: Wang Kunpeng <1289706727@qq.com>
) ### What this PR does / why we need it? Currently, MHA models (eg: minicpm-2b, Baichuan-7b) will encounter errors when running in piecewise graph mode, with error messages similar to: ``` (E89999): When layout is TND and PA not enabled, keyT(8) and valueT(8) must be equal to the last element of actualSeqenceLengthKV(5)[FUNC:CheckInputShapeWhenLayoutIsTND][FILE:prompt_flash_attention_tiling.cpp][LINE:3618] ``` The error occurs because the qkv in the Prefill stage is also padded, causing the shape to be inconsistent with actual_seq_lengths. Add unpadding logic for kv. - vLLM version: release/v0.13.0 - vLLM main: vllm-project/vllm@254f6b9 Signed-off-by: Wang Kunpeng <1289706727@qq.com>
) ### What this PR does / why we need it? Currently, MHA models (eg: minicpm-2b, Baichuan-7b) will encounter errors when running in piecewise graph mode, with error messages similar to: ``` (E89999): When layout is TND and PA not enabled, keyT(8) and valueT(8) must be equal to the last element of actualSeqenceLengthKV(5)[FUNC:CheckInputShapeWhenLayoutIsTND][FILE:prompt_flash_attention_tiling.cpp][LINE:3618] ``` The error occurs because the qkv in the Prefill stage is also padded, causing the shape to be inconsistent with actual_seq_lengths. Add unpadding logic for kv. - vLLM version: release/v0.13.0 - vLLM main: vllm-project/vllm@254f6b9 Signed-off-by: Wang Kunpeng <1289706727@qq.com> Signed-off-by: nanxing <1014662416@qq.com>
) ### What this PR does / why we need it? Currently, MHA models (eg: minicpm-2b, Baichuan-7b) will encounter errors when running in piecewise graph mode, with error messages similar to: ``` (E89999): When layout is TND and PA not enabled, keyT(8) and valueT(8) must be equal to the last element of actualSeqenceLengthKV(5)[FUNC:CheckInputShapeWhenLayoutIsTND][FILE:prompt_flash_attention_tiling.cpp][LINE:3618] ``` The error occurs because the qkv in the Prefill stage is also padded, causing the shape to be inconsistent with actual_seq_lengths. Add unpadding logic for kv. - vLLM version: release/v0.13.0 - vLLM main: vllm-project/vllm@254f6b9 Signed-off-by: Wang Kunpeng <1289706727@qq.com>
) ### What this PR does / why we need it? Currently, MHA models (eg: minicpm-2b, Baichuan-7b) will encounter errors when running in piecewise graph mode, with error messages similar to: ``` (E89999): When layout is TND and PA not enabled, keyT(8) and valueT(8) must be equal to the last element of actualSeqenceLengthKV(5)[FUNC:CheckInputShapeWhenLayoutIsTND][FILE:prompt_flash_attention_tiling.cpp][LINE:3618] ``` The error occurs because the qkv in the Prefill stage is also padded, causing the shape to be inconsistent with actual_seq_lengths. Add unpadding logic for kv. - vLLM version: release/v0.13.0 - vLLM main: vllm-project/vllm@254f6b9 Signed-off-by: Wang Kunpeng <1289706727@qq.com>
What this PR does / why we need it?
Currently, MHA models (eg: minicpm-2b, Baichuan-7b) will encounter errors when running in piecewise graph mode, with error messages similar to:
The error occurs because the qkv in the Prefill stage is also padded, causing the shape to be inconsistent with actual_seq_lengths.
Add unpadding logic for kv.
Does this PR introduce any user-facing change?
no
How was this patch tested?