Commit 73ba71a8 authored by Adam Straw's avatar Adam Straw Committed by Robert Kimball

remove TensorFlow rounding mode HALF_AWAY_FROM_ZERO (#2047)

parent 2cf9e4b2
......@@ -37,7 +37,6 @@ namespace ngraph
// 2.5 -> 3
// -3.5 -> -4
ROUND_NEAREST_TOWARD_INFINITY,
HALF_AWAY_FROM_ZERO, // TF mode for backward compatability
// round to nearest integer
// in case of two equidistant integers round toward zero e.g.
......
......@@ -567,7 +567,7 @@ void ngraph::pass::ConstantFolding::construct_constant_quantize()
make_shared<pattern::op::Label>(element::f32, Shape{2}, pattern::has_class<op::Constant>());
auto q_scale = op::Constant::create(element::f32, Shape{}, {1});
auto q_offset = op::Constant::create(element::i8, Shape{}, {0});
auto mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto quant_op =
make_shared<op::Quantize>(constant_label, q_scale, q_offset, element::i8, AxisSet{}, mode);
auto quant = make_shared<pattern::op::Label>(quant_op, nullptr, NodeVector{quant_op});
......@@ -592,11 +592,6 @@ void ngraph::pass::ConstantFolding::construct_constant_quantize()
return false;
}
if (quantize_op->get_round_mode() != op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO)
{
return false;
}
if (type == element::u8)
{
replace_node(
......
......@@ -47,8 +47,7 @@ namespace ngraph
scale[scale_offset_transform.index(scale_offset_coord)];
// round
if (round_mode == op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY ||
round_mode == op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO)
if (round_mode == op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY)
{
auto abs_qvalue = std::fabs(qvalue);
auto abs_qvalue_toward_inf = std::floor(abs_qvalue + 0.5);
......
......@@ -265,7 +265,7 @@ TEST(constant_folding, const_quantize)
auto constant = op::Constant::create(element::f32, input_shape, values_in);
auto scale = op::Constant::create(element::f32, scale_offset_shape, {2});
auto offset = op::Constant::create(quant_type, scale_offset_shape, {1});
auto mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto quantize =
make_shared<op::Quantize>(constant, scale, offset, output_type, quantization_axes, mode);
auto f = make_shared<Function>(quantize, op::ParameterVector{});
......
......@@ -12141,7 +12141,7 @@ TEST(type_prop, quantize_f32_to_i8_nchw_per_channel_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{1};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12163,7 +12163,7 @@ TEST(type_prop, quantize_f32_to_i8_nchw_per_image_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12185,7 +12185,7 @@ TEST(type_prop, quantize_f32_to_i8_nchw_per_row_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{2};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12207,7 +12207,7 @@ TEST(type_prop, quantize_f32_to_i8_nchw_per_image_channel_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12229,7 +12229,7 @@ TEST(type_prop, quantize_f32_to_i8_nchw_whole_batch_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12251,7 +12251,7 @@ TEST(type_prop, quantize_f64_to_i8_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12273,7 +12273,7 @@ TEST(type_prop, quantize_f64_to_u8_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12295,7 +12295,7 @@ TEST(type_prop, quantize_f64_to_dyn_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12328,7 +12328,7 @@ TEST(type_prop, quantize_i8_to_u8_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12363,7 +12363,7 @@ TEST(type_prop, quantize_f32_to_f32_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12398,7 +12398,7 @@ TEST(type_prop, quantize_batch_scale_type_mismatch_fails)
element::Type scale_type = element::f64;
element::Type offset_type = quantized_type;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12433,7 +12433,7 @@ TEST(type_prop, quantize_offset_type_mismatch_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = element::u8;
AxisSet axes{};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12468,7 +12468,7 @@ TEST(type_prop, quantize_oob_axis_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{3, 4};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12502,7 +12502,7 @@ TEST(type_prop, quantize_scale_shape_mismatch_same_rank_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12536,7 +12536,7 @@ TEST(type_prop, quantize_scale_shape_mismatch_different_rank_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12570,7 +12570,7 @@ TEST(type_prop, quantize_offset_shape_mismatch_same_rank_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12604,7 +12604,7 @@ TEST(type_prop, quantize_offset_shape_mismatch_different_rank_fails)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12638,7 +12638,7 @@ TEST(type_prop, quantize_partial_all_rank_dynamic_ok)
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1, 2000};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12661,7 +12661,7 @@ TEST(type_prop,
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1, 2000};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12685,7 +12685,7 @@ TEST(
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12721,7 +12721,7 @@ TEST(type_prop,
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1, 5, 88};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12745,7 +12745,7 @@ TEST(
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1, 5, 88};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12781,7 +12781,7 @@ TEST(
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{0, 1, 5, 88};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12817,7 +12817,7 @@ TEST(
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{1, 3, 5};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12842,7 +12842,7 @@ TEST(
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{1, 3, 6};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......@@ -12878,7 +12878,7 @@ TEST(
element::Type scale_type = unquantized_type;
element::Type offset_type = quantized_type;
AxisSet axes{1, 3, 5};
auto round_mode = op::Quantize::RoundMode::HALF_AWAY_FROM_ZERO;
auto round_mode = op::Quantize::RoundMode::ROUND_NEAREST_TOWARD_INFINITY;
auto batch = make_shared<op::Parameter>(batch_type, batch_shape);
auto scale = make_shared<op::Parameter>(scale_type, scale_shape);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment