Skip to content

Commit

Permalink
Merge "Fix hsigmoid and hswish bug for mix_precision quant and update…
Browse files Browse the repository at this point in the history
… model_config."
  • Loading branch information
dgyx authored and Gerrit Code Review committed Jan 9, 2023
2 parents cf6c14b + 7ffd162 commit 44674ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/Conversion/TopToTpu/CV18xx/HardSigmoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ void HardSigmoidLowering::LoweringBF16(PatternRewriter &rewriter,

//2.clip op
//rewriter.setInsertionPointAfterValue(conv_out);
auto caliType = getQuantBF16Type(op.getOutput());
std::vector<Value> clip_operands;
clip_operands.emplace_back(conv_out);
std::vector<NamedAttribute> clip_attrs;
clip_attrs.emplace_back(rewriter.getNamedAttr("min", rewriter.getF64FloatAttr(0.0)));
clip_attrs.emplace_back(rewriter.getNamedAttr("max", rewriter.getF64FloatAttr(1.0)));
rewriter.replaceOpWithNewOp<top::ClipOp>(op.getOperation(), newType, clip_operands, clip_attrs);
rewriter.replaceOpWithNewOp<top::ClipOp>(op.getOperation(), caliType, clip_operands, clip_attrs);
}
} // namespace cv18xx
} // namespace tpu_mlir
3 changes: 2 additions & 1 deletion lib/Conversion/TopToTpu/CV18xx/HardSwish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ void HardSwishLowering::LoweringBF16(PatternRewriter &rewriter,

//3.eltwise mul
//rewriter.setInsertionPointAfter(clip_out);
auto caliType = getQuantBF16Type(op.getOutput());
std::vector<Value> mul_operands;
mul_operands.emplace_back(input_val);
mul_operands.emplace_back(clip_out);
std::vector<NamedAttribute> mul_attrs;
mul_attrs.emplace_back(rewriter.getNamedAttr("relu_limit", rewriter.getF64FloatAttr(-1.0)));
rewriter.replaceOpWithNewOp<top::MulOp>(op.getOperation(), newType, mul_operands, mul_attrs);
rewriter.replaceOpWithNewOp<top::MulOp>(op.getOperation(), caliType, mul_operands, mul_attrs);
}
}
}
12 changes: 6 additions & 6 deletions regression/cv18xx_porting/config/model_config_18xx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ export IMAGE_RESIZE_DIMS=300,300
export NET_INPUT_DIMS=300,300
export MEAN=104.0,117.0,123.0
export INPUT_SCALE=1.0,1.0,1.0
export TOLERANCE_INT8=0.91,0.52
export TOLERANCE_INT8=0.88,0.37 #0.91,0.52
export TOLERANCE_BF16=0.99,0.98
export TOLERANCE_BF16_CMDBUF=0.99,0.91
export DO_QUANT_BF16=0
Expand All @@ -783,7 +783,7 @@ export NET_INPUT_DIMS=448,448
export RAW_SCALE=1.0
export MEAN=0,0,0
export INPUT_SCALE=0.00392,0.00392,0.00392
export TOLERANCE_INT8=0.90,0.50
export TOLERANCE_INT8=0.98,0.81 #0.90,0.50
export TOLERANCE_BF16=0.99,0.96
export TOLERANCE_BF16_CMDBUF=0.99,0.96
export CALI_IMAGES=$DATA_SET/coco/val2017
Expand All @@ -806,7 +806,7 @@ export MEAN=0,0,0
export INPUT_SCALE=0.00392,0.00392,0.00392
export DO_QUANT_BF16=0
# export TOLERANCE_INT8=0.886,0.507 #0.92,0.55
export TOLERANCE_INT8=0.886,0.50 #0.92,0.55
export TOLERANCE_INT8=0.88,0.50 #0.92,0.55
export TOLERANCE_BF16=0.99,0.91
export TOLERANCE_BF16_CMDBUF=0.99,0.98
export YOLO_V3=1
Expand Down Expand Up @@ -940,7 +940,7 @@ export STD=128,128,128
export INPUT_SCALE=0.0078125,0.0078125,0.0078125 # 1.0
export INPUT=input
#export OUTPUTS=output
export TOLERANCE_INT8=0.989,0.831
export TOLERANCE_INT8=0.988,0.817 #0.989,0.831
export TOLERANCE_BF16=0.999,0.961
export TOLERANCE_BF16_CMDBUF=0.99,0.99,0.96
export CALI_IMAGES=$DATA_SET/imagenet/img_val_extracted/ILSVRC2012
Expand Down Expand Up @@ -1123,7 +1123,7 @@ export INPUT_SCALE=0.00392,0.00392,0.00392
export STD=1,1,1
export RAW_SCALE=1.0
export INPUT=input
export TOLERANCE_INT8=0.94,0.64 #0.96,0.72
export TOLERANCE_INT8=0.93,0.63 #0.96,0.72
export TOLERANCE_BF16=0.99,0.95
export TOLERANCE_BF16_CMDBUF=0.99,0.98
export TOLERANCE_FP32=0.99,0.99
Expand Down Expand Up @@ -1193,7 +1193,7 @@ export INPUT_SCALE=0.0171,0.0175,0.0174 # 1.0,1.0,1.0
export INPUT=input
export EXCEPTS=relu_17.tmp_0_Relu # almost all zeros
export MODEL_CHANNEL_ORDER="rgb"
export TOLERANCE_INT8=0.63,0.05 #0.78,0.29
export TOLERANCE_INT8=0.62,0.04 #0.78,0.29
export TOLERANCE_BF16=0.99,0.93
export TOLERANCE_BF16_CMDBUF=0.99,0.98
export CALI_IMAGES=$DATA_SET/coco/val2017
Expand Down

0 comments on commit 44674ea

Please sign in to comment.