Skip to content
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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

satyajandhyala
Copy link
Contributor

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.

Copy link
Contributor

@github-actions github-actions bot left a 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.

Comment on lines 142 to 145
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";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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";
}

Comment on lines 172 to 177
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
}

Comment on lines 188 to 193
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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);
}

@guschmue guschmue added the ep:WebGPU ort-web webgpu provider label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:WebGPU ort-web webgpu provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants