[AIMIGRAPHX-1017] Skip Q/DQ for Attention Ops#4900
Draft
eddieliao wants to merge 4 commits into
Draft
Conversation
Contributor
Author
|
PR currently in draft as I am looking for some feedback on the premise of this change before I go and work on/clean up the actual implementation. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the FP8 quantization pipeline to avoid inserting Q/DQ pairs into dot -> softmax -> dot attention subgraphs so those regions can be fused later (improving performance and reducing scratch usage), and factors the attention-pattern matcher into a reusable header.
Changes:
- Extracts a reusable
match::dot_softmax_dotmatcher and uses it in GPU prefusion matching. - Adds a
skip_instructionsmechanism tocapture_arguments_passand wires it through FP8 quantization. - Detects attention regions in
quantize_fp8()and skips capture/QDQ insertion for those instructions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/targets/gpu/prefuse_ops.cpp | Switches attention prefusion matching to the new shared dot_softmax_dot matcher. |
| src/quantize_8bits.cpp | Skips inserting capture ops (and therefore Q/DQ) for a provided set of instructions. |
| src/quantization.cpp | Detects attention regions and passes them into the capture pass to skip Q/DQ insertion. |
| src/include/migraphx/quantize_8bits.hpp | Extends capture_arguments_pass API to carry a skip set. |
| src/include/migraphx/match/dot_softmax_dot.hpp | Introduces a reusable matcher for undecomposed attention (dot -> softmax -> dot). |
Comment on lines
44
to
50
| struct MIGRAPHX_EXPORT capture_arguments_pass | ||
| { | ||
| std::unordered_set<std::string> ins_names = {"dot", "convolution"}; | ||
| std::function<void(std::size_t, std::vector<argument>)> f{}; | ||
| std::size_t* param_index = nullptr; | ||
| std::unordered_set<instruction_ref> skip_instructions{}; | ||
| std::string name() const { return "capture_arguments"; } |
Comment on lines
+34
to
+40
| /// Match the (undecomposed) `dot -> softmax -> dot` attention pattern, with | ||
| /// optional `mul` (scale), `add` (bias), or `where` (mask) ops between the | ||
| /// first dot and the softmax. This is the form before `rewrite_reduce` | ||
| /// decomposes softmax into its `div(exp(sub(x, max)), sum(exp(...)))` chain. | ||
| /// | ||
| /// `gemm_pred` is applied to both dot operations; pass `match::any()` to | ||
| /// match any dot. `bias_pred` is applied to the optional `add` (bias) op. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4900 +/- ##
========================================
Coverage 92.88% 92.88%
========================================
Files 587 588 +1
Lines 30348 30365 +17
========================================
+ Hits 28187 28204 +17
Misses 2161 2161
🚀 New features to boost your workflow:
|
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.
Motivation
Skips inserting Q/DQ pairs for attention patterns so they can be fused later on.
Technical Details
Before:
After:
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable