Skip to content

Commit

Permalink
Fix Fake Quantize references calculation (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Treskin authored Nov 24, 2020
1 parent f6d2cc8 commit 18d52ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const std::vector<ReshapeTransformationParam> params = {
{
ngraph::Shape{ 1, 3, 32 },
{ 1, 3, 4, 8 },
{ 256ul, ngraph::Shape{ 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
{ 256ul, ngraph::Shape{ 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
},
// 4D -> 3D
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ namespace {

const std::vector<LayerTestsDefinitions::UnsqueezeTransformationParam> params = {
{
{ 256ul, ngraph::Shape { 1, 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 256ul, ngraph::Shape { 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 0.0, 3.0 },
{ 3, 3, 5}
},
{
{ 256ul, ngraph::Shape { 1, 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 256ul, ngraph::Shape { 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 0.0, 1.0 },
{ 3, 3, 3 }
},
{
{ 256ul, ngraph::Shape { 1, 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 256ul, ngraph::Shape { 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 3.0 },
{ 3, 4, 5, 6 }
},
{
{ 256ul, ngraph::Shape { 1, 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 256ul, ngraph::Shape { 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 0.0, 3.0 },
{ 1, 32, 2}
},
{
{ 256ul, ngraph::Shape { 1, 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 256ul, ngraph::Shape { 1, 1, 1 }, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f } },
{ 0.0, 1.0 },
{ 46, 128, 2 }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ namespace ngraph
{
broadcast_offsets[i] = memory_offsets[i];
}
else
{
broadcast_offsets[i] = std::accumulate(broadcast_offsets.begin() + i,
broadcast_offsets.end(),
0,
std::plus<size_t>());
}
}
if (!std::all_of(broadcast_shape.begin(),
broadcast_shape.end(),
Expand All @@ -58,6 +51,17 @@ namespace ngraph
{
broadcast_offsets[broadcast_offsets.size() - 1] = 1;
}
if (broadcast_shape.back() == 1)
{
for (int i = broadcast_shape.size() - 1; i >= 0; --i)
{
if (broadcast_shape[i] != 1)
{
broadcast_offsets[i] = memory_offsets[i] - 1;
break;
}
}
}
return broadcast_offsets;
}

Expand Down Expand Up @@ -115,6 +119,18 @@ namespace ngraph
Shape in_high_shape(_in_high_shape);
Shape out_low_shape(_out_low_shape);
Shape out_high_shape(_out_high_shape);

if (in_low_shape.size() > arg_shape.size() ||
in_high_shape.size() > arg_shape.size() ||
out_low_shape.size() > arg_shape.size() ||
out_high_shape.size() > arg_shape.size())
{
throw std::runtime_error(
std::string("Tensors with inout\\output ranges should have rank less or "
"equal to data tensor rank equal to ") +
std::to_string(arg_shape.size()));
}

std::vector<size_t> arg_memory_offsets(arg_shape.size(), 0);
for (int i = arg_shape.size() - 2; i >= 0; i--)
{
Expand Down Expand Up @@ -184,9 +200,10 @@ namespace ngraph
else
{
size_t index_offset = calc_full_broadcast_offset(current_dim, offsets);

NGRAPH_CHECK(idx >= index_offset && index_offset < shape_size(offsets),
"Incorrect index offset value!");
if (index_offset != 0)
{
NGRAPH_CHECK(idx >= index_offset, "Incorrect index offset value!");
}
val = data[idx - index_offset];
}
return val;
Expand Down
2 changes: 0 additions & 2 deletions ngraph/test/runtime/interpreter/unit_test.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ onnx_model_lstm_bdir_short_input_seq_peepholes
lstm_cell_bias_peepholes
lstm_cell_bias_peepholes_clip_input_forget

# Refs mismatch
quant_dequant_pattern_axis

# Check 'n_data_channels % groups == 0' failed
dyn_group_convolution_backprop_data
Expand Down

0 comments on commit 18d52ed

Please sign in to comment.