Skip to content

Fix a check in GE for avg_pool2d #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: pytorch_fusion
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions torch/csrc/jit/passes/guard_elimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,19 @@ struct GuardElimination {

// `checkInputs` check the invariants specified in `removableGuard`
// on inputs to `n`. The invariants must hold, or an input must
// be a `prim::Constant` or be of `NumberType` or be included
// as an exception in `except`
bool checkInputs(Node* n, const std::unordered_set<size_t>& except) {
// be a `prim::Constant` or be of `NumberType` if `allow_numbers` is `true`
// or be included as an exception in `except`
bool checkInputs(
Node* n,
const std::unordered_set<size_t>& except,
bool allow_numbers = true) {
bool all_inputs_guarded = true;
size_t i = 0;
for (auto input : n->inputs()) {
if ((input->node()->kind() == prim::Guard &&
!input->type()->expect<TensorType>()->isSummarized()) ||
input->node()->kind() == prim::Constant ||
input->type()->isSubtypeOf(NumberType::get()) ||
(allow_numbers && input->type()->isSubtypeOf(NumberType::get())) ||
except.count(i) != 0) {
AT_ASSERT(
input->node()->kind() != prim::Guard ||
Expand Down Expand Up @@ -260,7 +263,6 @@ struct GuardElimination {
case aten::pow:
case aten::relu:
case aten::threshold:
case aten::avg_pool2d:
case prim::AutogradAdd:
case prim::AutogradZero:
case aten::rand_like:
Expand Down Expand Up @@ -296,6 +298,8 @@ struct GuardElimination {
n->input(3)->node()->kind() == prim::Constant &&
// the stride is constant
n->input(4)->node()->kind() == prim::Constant;
case aten::avg_pool2d:
return checkInputs(n, no_exceptions, false);
case aten::unsqueeze:
// check that the dimension argument is constant
return !n->input(0)->type()->expect<TensorType>()->isSummarized() &&
Expand Down