Browse Source

eliminate math expression with torch.zeros/ones input (#4083)

tags/20220729
nihui GitHub 4 years ago
parent
commit
402001128d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      tools/pnnx/src/pass_level3/eliminate_noop_math.cpp

+ 7
- 1
tools/pnnx/src/pass_level3/eliminate_noop_math.cpp View File

@@ -130,6 +130,12 @@ static bool operator_is_all_constant(const Operator* op, float vf, int vi)
if (op->type == "prim::Constant")
return constant_is_all_constant(op, vf, vi);

if (op->type == "torch.zeros" || op->type == "torch.zeros_like")
return (vf == 0.f && vi == 0);

if (op->type == "torch.ones" || op->type == "torch.ones_like")
return (vf == 1.f && vi == 1);

return false;
}

@@ -163,7 +169,7 @@ void eliminate_noop_math(Graph& graph)
need_eliminate = true;
identity_input_id = 0;
}
else if (operator_is_all_constant(op0, 0.f, 0) && operator_is_all_constant(op0, 1.f, 1))
else if (operator_is_all_constant(op0, 0.f, 0) && operator_is_all_constant(op2, 1.f, 1))
{
// x <= 0 + b * 1
need_eliminate = true;


Loading…
Cancel
Save