Skip to content

Commit

Permalink
fix pnnx crash on dynamic pads, do not eliminate upsample for dynamic…
Browse files Browse the repository at this point in the history
… shape
  • Loading branch information
nihui committed Jul 21, 2022
1 parent 30ab31c commit e33c85c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/pnnx/src/pass_level5/eliminate_noop_pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ void eliminate_noop_pad(Graph& graph)
if (op->type != "F.pad")
continue;

if (op->params.find("pad") == op->params.end())
continue;

const std::vector<int>& pad = op->params.at("pad").ai;

bool noop_pad = true;
Expand Down
10 changes: 10 additions & 0 deletions tools/pnnx/src/pass_level5/eliminate_noop_upsample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ void eliminate_noop_upsample(Graph& graph)
if (!op->inputs[0]->shape.empty() && op->inputs[0]->shape == op->outputs[0]->shape)
{
matched = true;

// dynamic shape comparison always fail
for (auto s : op->inputs[0]->shape)
{
if (s == -1)
{
matched = false;
break;
}
}
}

// delete noop-like upsample
Expand Down

0 comments on commit e33c85c

Please sign in to comment.