Skip to content

Commit

Permalink
[record-mimax] Add more exceptions for quantization (Samsung#7388)
Browse files Browse the repository at this point in the history
* [record-mimax] Add more exceptions for quantization

This commit adds type check exceptions for Reshape and Cast operations.

Signed-off-by: Alexander Efimov <[email protected]>

* review fix: move comments to appropritate places
  • Loading branch information
binarman authored Aug 6, 2021
1 parent 7775678 commit c4f69a6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions compiler/record-minmax/src/MinMaxObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ void MinMaxObserver::postTensorWrite(const luci::CircleNode *node,
return;
}

if (node->opcode() == luci::CircleOpcode::ARG_MAX)
{
// Output of arg_max is the index of the largest value across axes of a tensor
// this should not be quantized
return;
}

if (node->dtype() == DataType::BOOL)
{
// Bool type tensor is not quantized
Expand All @@ -61,7 +54,23 @@ void MinMaxObserver::postTensorWrite(const luci::CircleNode *node,

// Only support recording of float32 values
if (tensor->element_type() != DataType::FLOAT32)
throw std::runtime_error("Tensor's data type is not float");
{
// Exceptions that should be processed in backends
switch (node->opcode())
{
case luci::CircleOpcode::ARG_MAX:
// Output of arg_max is the index of the largest value across axes of a tensor.
// It always has integer type.
case luci::CircleOpcode::CAST:
// Cast is quantized only if it converts <type> -> float.
// Other cases should be processed in backends.
case luci::CircleOpcode::RESHAPE:
// Reshape changes only shape of input tensor, efficiently is it a no-op.
return;
default:
throw std::runtime_error("Tensor's data type is not float");
}
}

const auto data = tensor->data<float>();
const auto num_elements = tensor->shape().num_elements();
Expand Down

0 comments on commit c4f69a6

Please sign in to comment.