Skip to content
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

[WIP] Various bugs in passes #6906

Closed
wants to merge 7 commits into from

Conversation

mbrookhart
Copy link
Contributor

This adds regression tests for a number of bugs uncovered while testing ONNX Object Detection models, and adds regression tests for the fixes

@tqchen

@@ -1076,7 +1076,7 @@ Examples::
.set_support_level(3)
.add_type_rel("Take", TakeRel)
.set_attr<FTVMCompute>("FTVMCompute", TakeCompute)
.set_attr<TOpPattern>("TOpPattern", kInjective);
.set_attr<TOpPattern>("TOpPattern", kOpaque);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope we could come up with a way to avoid this. This would hurt performance on hummingbird workload and possibly other models.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, maybe we can use annotation.stop_fusion when we encounter take + dynamic, solving this problem at the frontend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thing I have a typo in CI.

I'm not sure I see a clean way to do this in the frontends, it demands we already have infer_type run to check for dynamic inputs.

Maybe we write a pass that selectively stops fusion on certain ops under certain conditions?

Copy link
Member

@masahi masahi Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes a new pass that inserts stop_fusion sounds good. I can work on this. We can make take opaque for now until I have that new pass ready (or take compute being fixed).

Anyway I think graph runtime shouldn't be affected by the issue of take + dynamic, so take should be injective eventually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookhart Can you add TODO(masahi) there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@masahi want to request changes so this doesn't merge while we chat about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure done. But I think it is good to go after adding a comment on why we make this change temporary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the other option is to edit the relay take function that creates the op. We could remove the normalization that causes this problem from the take kernel in topi, and do in it relay with select/shape_of, but that might end up causing some performance degradation, it's hard to predict.

@mbrookhart mbrookhart mentioned this pull request Nov 12, 2020
@@ -243,7 +243,18 @@ class ForwardPrep : private ExprVisitor {
}
}
// Visitor pattern override.
void VisitExpr_(const LetNode* call) { LOG(FATAL) << "FoldScaleAxis only accept dataflow-form"; }
void VisitExpr_(const LetNode* op) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @kevinthesun This might be of interest to you

Copy link
Member

@masahi masahi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block merging until we settle on the take fusion issue

@tqchen
Copy link
Member

tqchen commented Nov 13, 2020

@mbrookhart perhaps we can separate out the other things (fold scale axis and bound) into separate PRs so we can merge them in first. It would also makes the PR itself more informative.

@mbrookhart mbrookhart changed the title Various bugs in passes [WIP] Various bugs in passes Nov 13, 2020
@mbrookhart
Copy link
Contributor Author

@tqchen @masahi That sounds good, I'll split the other parts off into a new PR, and we can wait on take until we have a more robust solution.

@masahi
Copy link
Member

masahi commented Nov 13, 2020

@mbrookhart maybe you can summarize what the issue is with take + dynamic (for me + others to comment)? I haven't looked into take topi compute in detail, so I haven't understood what's wrong with it.

I also want to know why this could lead to infinite loop inside rewrite_simplify (visiting the same node over and over again) @tqchen

@mbrookhart
Copy link
Contributor Author

I've been working on other things, sorry for the delay on this.

take with dynamic input shapes is a bit of an issue because take folds the input shape into the compute:

auto idx = tvm::min(tvm::max(0, indices(out_index)), a_size - 1);

If the input tensor to take is fused into other ops, that input shape maybe removed in the fusion, and then we'll have a reference to an input dimension that no longer exists, so the fused function will fail to compile.

As @masahi and I discussed above, there are two main ways to get around this: We can write a pass that breaks the fusion at an earlier step, or we can remove the clip and wrapmodes from the topi op and raise that logic into relay. I have a branch where I've done the second and it passes forward tests, but I'm having some issues getting gradient tests and ADT tests working.

A third option I've thought of in the meantime is to do the raising of the logic in a legalization pass only for dynamic input shapes. This would allow us to remove the dynamic issue but keep the current code everywhere else.

Any thoughts on the best way to proceed?

@mbrookhart mbrookhart closed this Nov 25, 2020
@mbrookhart mbrookhart deleted the mbrookhart/pass_bugs branch December 3, 2020 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants