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

[Node] Utility methods for ObjectPathPair handling #14498

Merged
merged 4 commits into from
Apr 6, 2023

Conversation

Lunderberg
Copy link
Contributor

This commit adds a templated overload to SEqualReducer::operator() that accepts a lambda function to update the path of the LHS and RHS of the comparison.

// Usage prior to this utility function
if (equal.IsPathTracingEnabled()) {
  const ObjectPathPair& self_paths = equal.GetCurrentObjectPaths();
  ObjectPathPair attr_paths = {self_paths->lhs_path->Attr("value"),
                               self_paths->rhs_path->Attr("value")};
  if (!equal(this->value, other->value, attr_paths)) return false;
} else {
  if (!equal(this->value, other->value)) return false;
}

// Usage after this utility function
if (!equal(this->value, other->value,
           [](const auto& path) { return path->Attr("value"); })) {
  return false;
}

This commit adds a templated overload to `SEqualReducer::operator()`
that accepts a lambda function to update the path of the LHS and RHS
of the comparison.

```c++
// Usage prior to this utility function
if (equal.IsPathTracingEnabled()) {
  const ObjectPathPair& self_paths = equal.GetCurrentObjectPaths();
  ObjectPathPair attr_paths = {self_paths->lhs_path->Attr("value"),
                               self_paths->rhs_path->Attr("value")};
  if (!equal(this->value, other->value, attr_paths)) return false;
} else {
  if (!equal(this->value, other->value)) return false;
}

// Usage after this utility function
if (!equal(this->value, other->value,
           [](const auto& path) { return path->Attr("value"); })) {
  return false;
}
```
@tvm-bot
Copy link
Collaborator

tvm-bot commented Apr 4, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: node See #10317 for details

Generated by tvm-bot

@Lunderberg
Copy link
Contributor Author

This arose during debugging for #14486, but wasn't strictly necessary for it.

if (!equal.DefEqual(gtv, other->GetGlobalTypeVar(gtv->name_hint))) return false;
// Checking functions and type definitions
if (!equal(this->functions, other->functions,
[](const auto& path) { return path->Attr("functions"); })) {
Copy link
Member

Choose a reason for hiding this comment

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

Is func_path (adding function name to the path) handled like before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, yes. The IRModule's handler only needs to handle appending .functions to the path, with the function name added by the equality check on Map. This results in a path of <root>.functions[I.GlobalVar("func")].body....

I've added a unit test that verifies that the error message includes the function name, as that's definitely a good thing to verify for user-friendliness.

@Lunderberg
Copy link
Contributor Author

@tvm-bot rerun

@vinx13 vinx13 merged commit af39b34 into apache:main Apr 6, 2023
@Lunderberg Lunderberg deleted the objectpathpair_reduce_duplication branch April 6, 2023 19:53
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