Skip to content

[Flow] Make dequantization ops clonable into dispatch regions - #15662

Merged
Max191 merged 5 commits into
iree-org:mainfrom
Max191-agents:dequantization-fusion
Nov 28, 2023
Merged

Max191 merged 5 commits into
iree-org:mainfrom
Max191-agents:dequantization-fusion

Conversation

@Max191

@Max191 Max191 commented Nov 21, 2023 •

Copy link
Copy Markdown
Contributor

This PR eliminates the need for ad hoc custom fusion of dequantization
and matmul linalg.generic ops. The fusion heuristics are updated and
the FuseDequantizationMatmul pattern has been removed from the
FuseDequantizationMatmulPass in GlobalOptimization.

We want to avoid dequantization ops ending up in their own dispatch
region because the result of these ops are larger than the inputs,
often by multiple times. To avoid storing and loading the large results
between dispatch regions, this makes dequantization ops clonable into
dispatch regions rather than fusing in dispatch region formation.

Fixes #15680

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, accidentally added this file. I'll remove it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will remove this as well

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! One down. I'll review the next one later tonight

// Step 2. Check whether it is possible to collapse
// Step 2. Don't collapse dims if there is a clonable dequantization like
// producer. Collapsing in this case will prevent fusion later.
if (llvm::any_of(getCloneableOps(regionOp), [&](Operation *op) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is kind of OK, but this logic seems better suited to incorporated into the findRootOp method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we can just leave this here for now, since we plan to remove it by switching the pass order of collapseDims later anyway

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we do that first... Just send out a simple PR that does the change in order. If that passes, and then you can drop all this logic, then we dont need to worry about this at all.

return false;
}

// Always fuse dequant to consumer since it's not very useful by itself.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this logic needed here?

if (!isa<linalg::LinalgOp, tensor::PadOp, tensor::PackOp,
IREE::LinalgExt::SetEncodingOp>(op) ||
isa<linalg::FillOp>(op)) {
isa<linalg::FillOp>(op) || isGroupedDequantizationOp(&op)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if it is worth it adding a test in form_dispatch_regions to show that it won't get fused into a dispatch region.

Max191 added a commit that referenced this pull request Nov 27, 2023
…5671)

The CollapseDimensions pass can introduce reshapes that can prevent
clonable ops from being cloned into dispatch regions. Specifically,
dequantization ops, which are becoming clonable with
#15662, will not get fused. Moving
CollapseDimensions to after CloneProducersIntoDispatchRegions will
prevent anything like this from ever happening.
@Max191
Max191 force-pushed the dequantization-fusion branch from fce3a47 to 4a4994d Compare November 27, 2023 20:29

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok, this looks good to me. Maybe adding a test like @raikonenfnu suggested of making sure those dont get pulled into dispatch during FormDispatchRegion is worth it.

raikonenfnu and others added 5 commits November 28, 2023 10:18
We want to avoid dequantization ops ending up in their own dispatch
region because the result of these ops are larger than the inputs,
often by multiple times. To avoid storing and loading the large results
between dispatch regions, this makes dequantization ops clonable into
dispatch regions rather than fusing in dispatch region formation.
@Max191
Max191 force-pushed the dequantization-fusion branch from 4a4994d to c0f6eee Compare November 28, 2023 16:26
@MaheshRavishankar MaheshRavishankar added benchmarks:cuda Run default CUDA benchmarks benchmarks:x86_64 Run default x86_64 benchmarks benchmarks:comp-stats Run default compilation statistics benchmarks benchmarks:android-cpu Run default Android CPU benchmarks benchmarks:android-gpu Run default Android GPU benchmarks benchmarks:vulkan-nvidia Run default Vulkan benchmarks on NVIDIA GPU labels Nov 28, 2023
@github-actions

Copy link
Copy Markdown

@MaheshRavishankar

MaheshRavishankar commented Nov 28, 2023 •

Copy link
Copy Markdown
Collaborator

Fantastic. Land it please. Great work @Max191 and @raikonenfnu

qedawkins added a commit to qedawkins/iree that referenced this pull request Nov 29, 2023
Reintroduces CollapseDimsPass behind a flag after iree-org#15662
qedawkins added a commit that referenced this pull request Nov 29, 2023
Reintroduces CollapseDimsPass behind a flag after #15662
ramiro050 pushed a commit to ramiro050/iree that referenced this pull request Dec 19, 2023
…ee-org#15671)

The CollapseDimensions pass can introduce reshapes that can prevent
clonable ops from being cloned into dispatch regions. Specifically,
dequantization ops, which are becoming clonable with
iree-org#15662, will not get fused. Moving
CollapseDimensions to after CloneProducersIntoDispatchRegions will
prevent anything like this from ever happening.
ramiro050 pushed a commit to ramiro050/iree that referenced this pull request Dec 19, 2023
…rg#15662)

This PR eliminates the need for ad hoc custom fusion of dequantization
and matmul `linalg.generic` ops. The fusion heuristics are updated and
the FuseDequantizationMatmul pattern has been removed from the
FuseDequantizationMatmulPass in GlobalOptimization.

We want to avoid dequantization ops ending up in their own dispatch
region because the result of these ops are larger than the inputs,
often by multiple times. To avoid storing and loading the large results
between dispatch regions, this makes dequantization ops clonable into
dispatch regions rather than fusing in dispatch region formation.

---------

Co-authored-by: Stanley Winata <[email protected]>
ramiro050 pushed a commit to ramiro050/iree that referenced this pull request Dec 19, 2023
@Max191
Max191 deleted the dequantization-fusion branch October 25, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmarks:android-cpu Run default Android CPU benchmarks benchmarks:android-gpu Run default Android GPU benchmarks benchmarks:comp-stats Run default compilation statistics benchmarks benchmarks:cuda Run default CUDA benchmarks benchmarks:vulkan-nvidia Run default Vulkan benchmarks on NVIDIA GPU benchmarks:x86_64 Run default x86_64 benchmarks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form cast ops and mmt4d ops into the same dispatch.

3 participants