Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/simplify_qdq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,14 @@ bool compare_literals(instruction_ref ins1, instruction_ref ins2)
auto x = ins1->eval();
if(x.empty())
return false;
auto literal1 = ins1->get_literal();
if(ins2->name() == "broadcast" or ins2->name() == "multibroadcast")
ins2 = ins2->inputs().front();
auto y = ins2->eval();
if(y.empty())
return false;
auto literal2 = ins2->get_literal();

bool diff_shapes_equal_vals = false;
visit_all(ins1->get_literal(), ins2->get_literal())([&](const auto l1, const auto l2) {
visit_all(x, y)([&](const auto l1, const auto l2) {
diff_shapes_equal_vals =
std::all_of(l1.begin() + 1,
l1.end(),
Expand Down
36 changes: 35 additions & 1 deletion test/simplify_qdq_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ TEST_CASE(dot_reused)
auto out_scale2 = add_scale_mul(m2, scale, scale, 1, 1, sh.lens());
auto d2 = add_quantize_op(m2, "dequantizelinear", dot2, out_scale2);
auto d3 = add_quantize_op(m2, "dequantizelinear", q3, q3->inputs()[1]);
auto add2 = m2.add_instruction(migraphx::make_op("add"), d2, d3);
auto add2 = m2.add_instruction(migraphx::make_op("add"), d2, d3);
m2.add_return({add2});
}

Expand Down Expand Up @@ -1985,4 +1985,38 @@ TEST_CASE(fp4x2_odd_remove_qdq)
EXPECT(m1 == m2);
}

TEST_CASE(qdq_computed_scale)
{
migraphx::shape sh{migraphx::shape::float_type, {2, 2}};

migraphx::module m1;
{
auto a = m1.add_parameter("a", sh);
auto b = m1.add_parameter("b", sh);

auto scale = m1.add_instruction(
migraphx::make_op("add"), m1.add_literal(0.5f), m1.add_literal(0.0f));
auto zero = m1.add_literal(std::int8_t{0});

auto qa = add_quantize_op(m1, "quantizelinear", a, scale, zero);
auto da = add_quantize_op(m1, "dequantizelinear", qa, scale, zero);
auto qb = add_quantize_op(m1, "quantizelinear", b, scale, zero);
auto db = add_quantize_op(m1, "dequantizelinear", qb, scale, zero);

auto add = m1.add_instruction(migraphx::make_op("add"), da, db);
m1.add_return({add});
}

migraphx::module m2;
{
auto a = m2.add_parameter("a", sh);
auto b = m2.add_parameter("b", sh);
auto add = m2.add_instruction(migraphx::make_op("add"), a, b);
m2.add_return({add});
}

run_pass(m1);
EXPECT(m1 == m2);
}

int main(int argc, const char* argv[]) { test::run(argc, argv); }
Loading