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

[Unity] Improve FuseOps error messages #15899

Merged
merged 1 commit into from
Oct 11, 2023
Merged
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
21 changes: 14 additions & 7 deletions src/relax/transform/fuse_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ class GraphCreator : public ExprVisitor {
SetNodePattern(binding_var_node, pattern);
// Visit all call args
for (const Expr& arg : args) {
ICHECK(IsLeafOrTuple(arg));
ICHECK(IsLeafOrTuple(arg))
<< "FuseOps expects all relax::Call nodes to have non-nested arguments, "
<< "but " << GetRef<Expr>(call) << " has argument " << arg
<< ", which is neither a leaf node nor a relax::Tuple";
VisitLeaf(arg, binding_var_node, pattern);
}
}
Expand Down Expand Up @@ -281,7 +284,7 @@ class GraphCreator : public ExprVisitor {
*/
IndexedForwardGraph::Node* CreateNode(const Object* key) {
ICHECK(graph_.node_map.find(key) == graph_.node_map.end())
<< "The node corresponding to the input key is not supposed to be created before";
<< "The object " << GetRef<ObjectRef>(key) << " appears at multiple definition sites.";
auto* node = arena_->make<IndexedForwardGraph::Node>();
graph_.node_map[key] = node;
return node;
Expand All @@ -296,12 +299,14 @@ class GraphCreator : public ExprVisitor {
void AddToPostDFSOrder(IndexedForwardGraph::Node* node, const Object* key) {
auto it = graph_.node_map.find(key);
ICHECK(it != graph_.node_map.end() && it->second == node)
<< "The node must have been created before adding to the post-dfs order";
<< "Cannot add node " << GetRef<ObjectRef>(key) << " to the post-DFS order, "
<< "because the node for this object has not yet been created.";

// We only set the reference of the node when adding it to the post-dfs order. Thus, if the
// reference of a node is already set, it must have been appended to the post-dfs order.
ICHECK(node->ref == nullptr)
<< "The node is not supposed to be added into the post-dfs order before";
ICHECK(node->ref == nullptr) << "Cannot add node " << GetRef<ObjectRef>(key)
<< " to the post-DFS order, "
<< "because it has already been added.";

node->ref = key;
node->index = graph_.post_dfs_order.size();
Expand Down Expand Up @@ -336,7 +341,8 @@ class GraphCreator : public ExprVisitor {
*/
void SetNodePattern(IndexedForwardGraph::Node* node, OpPatternKind pattern) {
ICHECK(initialized_nodes_.find(node) == initialized_nodes_.end())
<< "The input node is supposed to be set pattern for only once";
<< "The input node " << GetRef<ObjectRef>(node->ref)
<< " cannot have have its OpPatternKind set more than once.";
initialized_nodes_.insert(node);
node->pattern = pattern;
}
Expand Down Expand Up @@ -915,7 +921,8 @@ class OperatorFusor : public ExprMutator {
*/
Group* GetGroupFromVar(const Var& var) {
const auto& it_group = obj2group_.find(var.get());
ICHECK(it_group != obj2group_.end());
ICHECK(it_group != obj2group_.end())
<< "Variable " << var << " could not be found in any group";
Group* group = it_group->second;
return group->FindRoot();
}
Expand Down