-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Native WebGPU EP] Add packedQKV and do_rotary attribute support to GroupQueryAttention operator #23386
base: main
Are you sure you want to change the base?
Conversation
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.
You can commit the suggested changes from lintrunner.
shader.MainFunctionBody() << " if (n + local_id.y < uniforms.kv_sequence_length) {\n" | ||
" tileK[idx] = key[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x];\n" | ||
" tileK[idx] = " << (is_packed_qkv_ ? "q" : "key") << "[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x];\n" | ||
" }\n"; | ||
} |
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.
shader.MainFunctionBody() << " if (n + local_id.y < uniforms.kv_sequence_length) {\n" | |
" tileK[idx] = key[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x];\n" | |
" tileK[idx] = " << (is_packed_qkv_ ? "q" : "key") << "[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x];\n" | |
" }\n"; | |
} | |
shader.MainFunctionBody() << " if (n + local_id.y < uniforms.kv_sequence_length) {\n" | |
" tileK[idx] = " | |
<< (is_packed_qkv_ ? "q" : "key") << "[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x];\n" | |
" }\n"; | |
} |
return ApplyAttention(&qRotary, &kRotary, &vBNSH, nullptr, past_key, past_value, output, present_key, | ||
present_value, parameters, context, seqlens_k); | ||
} else { | ||
return ApplyAttention(&qBNSH, &kBNSH, &vBNSH, nullptr, past_key, past_value, output, present_key, | ||
present_value, parameters, context, seqlens_k); | ||
} |
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.
return ApplyAttention(&qRotary, &kRotary, &vBNSH, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} else { | |
return ApplyAttention(&qBNSH, &kBNSH, &vBNSH, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} | |
return ApplyAttention(&qRotary, &kRotary, &vBNSH, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} else { | |
return ApplyAttention(&qBNSH, &kBNSH, &vBNSH, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} |
return ApplyAttention(&qRotary, nullptr, nullptr, nullptr, past_key, past_value, output, present_key, | ||
present_value, parameters, context, seqlens_k); | ||
} else { | ||
return ApplyAttention(&qBNSH, nullptr, nullptr, nullptr, past_key, past_value, output, present_key, | ||
present_value, parameters, context, seqlens_k); | ||
} |
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.
return ApplyAttention(&qRotary, nullptr, nullptr, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} else { | |
return ApplyAttention(&qBNSH, nullptr, nullptr, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} | |
return ApplyAttention(&qRotary, nullptr, nullptr, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} else { | |
return ApplyAttention(&qBNSH, nullptr, nullptr, nullptr, past_key, past_value, output, present_key, | |
present_value, parameters, context, seqlens_k); | |
} |
Description
Add Packed QKV inputs and do_rotary attribute to GQA.
Motivation and Context
Packed QKV inputs and do_rotary attribute are required for certain models.