Fuse hardwish for mobilenet v3

The mobilenet v3 frozen graph has extra FakeQuant ops which blocks the fusion,
thus we create a special pattern to remove the redundant FakeQuant ops.

PiperOrigin-RevId: 296093529
Change-Id: Ic5bc6808afb12b2004ed7b6f3a81f914df917d5e
This commit is contained in:
Feng Liu 2020-02-19 17:15:59 -08:00 committed by TensorFlower Gardener
parent 34a38afdee
commit 37d4d0484c
2 changed files with 17 additions and 1 deletions

View File

@ -1349,7 +1349,7 @@ def TFL_GreaterOp : TFL_Op<"greater", [
}
def TFL_HardSwishOp: TFL_Op<"hard_swish", [NoSideEffect,
SameOperandsAndResultType]> {
SameOperandsAndResultShape]> {
let summary = "Hardswish activation function.";
let description = [{
Computes hard-swish activation function

View File

@ -199,6 +199,22 @@ def : Pat<
(TFL_HardSwishOp $x),
[(EqualOperands $x, $y)]>;
// Matching HardSwish with extra FakeQuant. These FakeQuant ops were due to
// incorrect placement in the quantization aware training.
// TODO(b/149735743): We should make the placement automatically.
def : Pat<
(TFL_MulOp (TFL_DequantizeOp (TFL_QuantizeOp
(TFL_MulOp
$x, (TFL_DequantizeOp (TFL_QuantizeOp (TFL_AddOp
$y,
(ConstantOp ConstantAttr<RankedF32ElementsAttr<[]>, "3.0f">),
TFL_AF_Relu6), $qattr2)),
TFL_AF_None), $qattr1)),
(ConstantOp ConstantAttr<RankedF32ElementsAttr<[]>, "0.166666666f">),
TFL_AF_None),
(TFL_HardSwishOp $x),
[(EqualOperands $x, $y)]>;
// Constraint that the attribute value is less than 'n'
class ConstDoubleValueLessThan<string n> : Constraint<
CPred<"$0.isa<DenseElementsAttr>() && "