Skip to content

Commit

Permalink
[luci] Support Transpose in InsertQuantizeOpOnDTypeMismatch (#14488)
Browse files Browse the repository at this point in the history
This supports Transpose Op in InsertQuantizeOpOnDTypeMismatch.

ONE-DCO-1.0-Signed-off-by: Hyukjin Jeong <[email protected]>
  • Loading branch information
jinevening authored Dec 24, 2024
1 parent 5754f4a commit 615fa81
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions compiler/luci/pass/src/InsertQuantizeOpOnDTypeMismatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,51 @@ luci::CircleQuantize *create_quantize_op(luci::CircleNode *node)
namespace luci
{

// Add Quantize Op before Transpose
//
// Before
//
// [Node] s16
// |
// [Transpose] u8
//
// After
//
// [Node] s16
// |
// [Quantize] s16->u8
// |
// [Transpose] u8
void InsertQuantizeOpOnDTypeMismatch::visit(luci::CircleTranspose *node)
{
auto input = loco::must_cast<luci::CircleNode *>(node->a());

// Input dtype == Output dtype. No problem
if (input->dtype() == node->dtype())
return;

// Only cares quantized case
if (not is_quantized(input))
return;

if (not is_quantized(node))
return;

// Let's support limited case
// TODO Extend this to another dtype
if (input->dtype() != loco::DataType::S16)
return;

if (node->dtype() != loco::DataType::U8)
return;

// Create Quantize Op
auto quant_op = create_quantize_op(node);
quant_op->input(input);

node->a(quant_op);
}

void InsertQuantizeOpOnDTypeMismatch::visit(luci::CircleFullyConnected *node)
{
auto input = loco::must_cast<luci::CircleNode *>(node->input());
Expand Down
1 change: 1 addition & 0 deletions compiler/luci/pass/src/InsertQuantizeOpOnDTypeMismatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct InsertQuantizeOpOnDTypeMismatch final : public luci::CircleNodeMutableVis
void visit(luci::CircleFullyConnected *node);
void visit(luci::CircleMul *node);
void visit(luci::CircleBatchMatMul *node);
void visit(luci::CircleTranspose *node);

// TODO Support more operators
};
Expand Down

0 comments on commit 615fa81

Please sign in to comment.