Skip to content

Commit

Permalink
Merge pull request #32486 from Intel-tensorflow:rgomathi/mkl_quantize…
Browse files Browse the repository at this point in the history
…_minfirst

PiperOrigin-RevId: 280006380
Change-Id: Iaa6feaff763eafe31bdf559b3cf4b1866dc1669b
  • Loading branch information
tensorflower-gardener committed Nov 12, 2019
2 parents 65016d4 + 1b8b71e commit d6bbe8c
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 42 deletions.
17 changes: 15 additions & 2 deletions tensorflow/core/graph/mkl_layout_pass.cc
Expand Up @@ -1576,10 +1576,13 @@ rinfo_.push_back({csinfo_.tanh_grad,
int axis = -1;
string mode_string;
string round_mode_string;
DataType type;
TryGetNodeAttr(n->def(), "narrow_range", &narrow_range);
TryGetNodeAttr(n->def(), "axis", &axis);
TF_CHECK_OK(GetNodeAttr(n->def(), "mode", &mode_string));
TF_CHECK_OK(GetNodeAttr(n->def(), "round_mode", &round_mode_string));
TF_CHECK_OK(GetNodeAttr(n->def(), "T", &type));

if (narrow_range) {
VLOG(1) << "QuantizeOpRewrite: narrow range is enabled for quantization."
<< "This case is not optimized by Intel MKL, "
Expand All @@ -1593,8 +1596,9 @@ rinfo_.push_back({csinfo_.tanh_grad,
<< "thus using Eigen op for Quantize op ";
return false;
}
if (mode_string != "SCALED" || round_mode_string != "HALF_TO_EVEN") {
VLOG(1) << "QuantizeOpRewrite: Mode is not SCALED and/or"
if (!((mode_string == "SCALED" && round_mode_string == "HALF_TO_EVEN") ||
(mode_string == "MIN_FIRST"))) {
VLOG(1) << "QuantizeOpRewrite: Mode is not SCALED or MIN_FIRST and/or"
<< "rounding mode is not HALF_TO_EVEN. "
<< "This case is not optimized by Intel MKL, thus using Eigen op"
<< "for Quantize op ";
Expand All @@ -1608,6 +1612,14 @@ rinfo_.push_back({csinfo_.tanh_grad,

return false;
}
if (mode_string == "MIN_FIRST") {
if (type != DT_QUINT8) {
VLOG(1) << "QuantizeOpRewrite: For MIN_FIRST mode the data type is "
<< "not DT_UINT8. This case is not optimized by Intel MKL, "
<< "thus using Eigen op for Quantize op ";
return false;
}
}
return true;
}
static bool MaxpoolGradRewrite(const Node* n) {
Expand Down Expand Up @@ -1849,6 +1861,7 @@ rinfo_.push_back({csinfo_.tanh_grad,
// NOTE: names are alphabetically sorted.
static void CopyAttrsAll(const Node* orig_node, NodeBuilder* nb,
bool change_format = false);

static void CopyAttrsConv(const Node* orig_node, NodeBuilder* nb,
bool change_format = false);
static void CopyAttrsConv2DDepthwiseCheckConstFilter(
Expand Down
9 changes: 6 additions & 3 deletions tensorflow/core/graph/mkl_layout_pass_test.cc
Expand Up @@ -1470,7 +1470,7 @@ TEST_F(MklLayoutPassTest, NodeRewrite_QuantizeV2Op_Negative_ConstInp) {
"A->D;B->D:1;C->D:2;D->E");
}

TEST_F(MklLayoutPassTest, NodeRewrite_QuantizeV2Op_Negative_MinFirst) {
TEST_F(MklLayoutPassTest, NodeRewrite_QuantizeV2Op_MinFirst) {
InitGraph(
"node { name: 'A' op: 'Input' } "
"node { name: 'B' op: 'Const' "
Expand All @@ -1491,8 +1491,11 @@ TEST_F(MklLayoutPassTest, NodeRewrite_QuantizeV2Op_Negative_MinFirst) {
"node { name: 'E' op: 'Zeta' attr { key: 'T' value { type: DT_QUINT8 } }"
" input: ['D'] }");
EXPECT_EQ(DoMklLayoutOptimizationPass(),
"A(Input);B(Const);C(Const);D(QuantizeV2);E(Zeta)|"
"A->D;B->D:1;C->D:2;D->E");
"A(Input);B(Const);C(Const);D(_MklQuantizeV2);DMT/_0(Const);DMT/"
"_1(Const);DMT/_2(Const);E(Zeta)|"
"A->D;A:control->DMT/_0:control;A:control->DMT/"
"_1:control;A:control->DMT/_2:control;B->D:1;C->D:2;D->E;DMT/"
"_0->D:3;DMT/_1->D:4;DMT/_2->D:5");
}

TEST_F(MklLayoutPassTest, NodeRewrite_QuantizeV2Op_Negative_NarrowRange_True) {
Expand Down

0 comments on commit d6bbe8c

Please sign in to comment.