Skip to content

Commit

Permalink
Disable Attention V operand transposition.
Browse files Browse the repository at this point in the history
This impacts the ability to horizontally fuse the matmuls that feed
into `Q-K-V` transpose. The improvements seen with the change might
have been due to reduction in copy overheads, which are no more an
issue.

Signed-off-by: MaheshRavishankar <[email protected]>
  • Loading branch information
MaheshRavishankar committed Jan 25, 2025
1 parent 1648af4 commit 417012a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions compiler/src/iree/compiler/GlobalOptimization/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def PropagateLinalgTransposePass :
"Flag used for lit-testing sinking patterns only. Not for general usage">,
Option<"testBubblingOnly", "test-bubbling-only", "bool", /*default=*/"false",
"Flag used for lit-testing bubbling patterns only. Not for general usage">,
Option<"enableAttentionVTranspose", "enable-attention-v-transpose", "bool",
/*default=*/"false", "Enable transposition of attention v operand">,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,15 +1092,19 @@ void PropagateLinalgTransposePass::runOnOperation() {
linalg::populateFoldReshapeOpsByExpansionPatterns(bubblingPatterns,
reshapePropagationFn);
linalg::FillOp::getCanonicalizationPatterns(bubblingPatterns, context);
linalg::ControlFusionFn bubbleTransposeControlFn =
[](OpOperand *fusedOperand) {
Operation *producer = fusedOperand->get().getDefiningOp();
Operation *consumer = fusedOperand->getOwner();

return IREE::Flow::isNonNullAndOutsideDispatch({producer, consumer});
};
IREE::LinalgExt::populateBubbleTransposeFromLinalgExtOps(
bubblingPatterns, bubbleTransposeControlFn);
if (enableAttentionVTranspose) {
linalg::ControlFusionFn bubbleTransposeControlFn =
[](OpOperand *fusedOperand) {
Operation *producer = fusedOperand->get().getDefiningOp();
Operation *consumer = fusedOperand->getOwner();

return IREE::Flow::isNonNullAndOutsideDispatch(
{producer, consumer});
};
IREE::LinalgExt::populateBubbleTransposeFromLinalgExtOps(
bubblingPatterns, bubbleTransposeControlFn);
}
bubblingPatterns.insert<FuseTransposeWithProducerLinalgOp>(
context, enableAggressivePropagation);
bubblingPatterns.insert<BubbleTransposeThroughCollapseShape>(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: iree-opt --pass-pipeline="builtin.module(util.func(iree-global-opt-propagate-linalg-transpose))" --split-input-file %s | FileCheck %s
// RUN: iree-opt --pass-pipeline="builtin.module(util.func(iree-global-opt-propagate-linalg-transpose{enable-attention-v-transpose=true}))" --split-input-file %s | FileCheck %s
// RUN: iree-opt --pass-pipeline="builtin.module(util.func(iree-global-opt-propagate-linalg-transpose{enable-aggressive-propagation=true}))" --split-input-file %s | FileCheck %s --check-prefix=APROP
// RUN: iree-opt --pass-pipeline="builtin.module(util.func(iree-global-opt-propagate-linalg-transpose{test-sinking-only=true}))" --split-input-file %s | FileCheck %s --check-prefix=SINK
// RUN: iree-opt --pass-pipeline="builtin.module(util.func(iree-global-opt-propagate-linalg-transpose{test-bubbling-only=true}))" --split-input-file %s | FileCheck %s --check-prefix=BUBBLE
Expand Down

0 comments on commit 417012a

Please sign in to comment.