Skip to content

Commit 2e79b09

Browse files
sirakiintensorflower-gardener
authored andcommitted
Add an optimization pattern that tranform const<[a, 1]> @ <[1, b]> to <[1, b]> * const<[a, 1]>.
PiperOrigin-RevId: 786124861
1 parent a008822 commit 2e79b09

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tensorflow/compiler/mlir/lite/transforms/optimize_patterns.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,3 +2220,20 @@ def DegenerateFCtoMul : Pat<
22202220
(IsLastDimensionEqualOne $input),
22212221
(SameElementType $input, $filter),
22222222
(IsNoneType $bias)]>;
2223+
2224+
// Replace matmul where inputs & weights have inner dimension of 1 with an
2225+
// elementwise multiplication that broadcasts, i.e. replace:
2226+
// const [a, 1] @ [1, b] => [a, b]
2227+
// with:
2228+
// [1, b] * const [a, 1] => [a, b]
2229+
def BMMAsBroadCastMultoFc : Pat<
2230+
(TFL_BatchMatMulOp
2231+
(Arith_ConstantOp:$const_input $constInputVal),
2232+
$filter, ConstBoolAttrFalse, ConstBoolAttrFalse, ConstBoolAttrFalse),
2233+
(TFL_MulOp
2234+
$filter, $const_input,
2235+
TFL_AF_None),
2236+
[(HasRank<2> $const_input),
2237+
(HasRank<2> $filter),
2238+
(IsLastDimensionEqualOne $const_input),
2239+
(SameElementType $const_input, $filter)]>;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy