-
Notifications
You must be signed in to change notification settings - Fork 159
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
[onert] Add check for topological order validity #12602
Conversation
The model on #12325 (comment) is now correctly rejected as follows.
|
if (p > q) | ||
throw std::runtime_error{ | ||
"Invalid " + order_type + " topological order: inversion between @" + | ||
std::to_string(index.value()) + " and @" + std::to_string(use.value())}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an inversion between node u
and v
in an ordering if there is an edge from u
to v
and v
preceeds u
.
A valid topological order should not contain any inversion.
void TrainableGraph::assertValidBackwardTopologicalOrder( | ||
std::vector<ir::OperationIndex> order) const | ||
{ | ||
std::reverse(order.begin(), order.end()); | ||
assertValidTopologicalOrder(order, "backward"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An order is a backward topological order if and only if its reverse is a forward topological order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been moved to
ONE/runtime/onert/core/src/ir/train/TrainableGraph.cc
Lines 132 to 133 in 6f0884b
if (!is_forward) | |
std::reverse(order.begin(), order.end()); |
void assertValidTopologicalOrder(const std::vector<ir::OperationIndex> &order, | ||
const std::string &order_type) const; | ||
void assertValidBackwardTopologicalOrder(std::vector<ir::OperationIndex> order) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the name of assert...
, are these for test only? If so, what about moving this into test code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intended ONERT to throw error upon finding an invalid topological order.
Adding them as unittest instead would only catch some specific pre-determined cases and ONERT could still end up using some invalid topological order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO,
- I believe
backwardTopologicalOrder
should always return correct answer. It is well-known problem. We already have several ones from compiler frontend in this repo, and internal repo. - If there was a bug, I would add regression testcase for
backwardTopologicalOrder
with your validate function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read the code. The logic looks good to me. 👍
But I agree with this opinion - https://github.com/Samsung/ONE/pull/12602/files#r1479151257
If this code is only for ensuring that topological sorting is done right,
I'd prefer to make it run only in debug mode(sorry but i either don't know how to make specific code run only on debug mode) or move it into the test.
May I ask why? I think I expect ONERT to reject such incorrect result regardless of I'm in debug mode or not, and I believe this check is not a performance bottleneck either. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
std::vector<ir::OperationIndex> TrainableGraph::topolSortOperations() const | ||
{ | ||
return _graph.topolSortOperations(); | ||
auto ret = _graph.topolSortOperations(); | ||
assertValidForwardTopologicalOrder(ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to use verify
instead of assert
for the function name, but this depends on the developer's taste. So your function naming is okay. In addition, the assertValidTopologicalOrder
function can be called directly, but the current code is also good. :)
In my understanding overall view is that :
In the point of So I thought the direction that this logic runs for only debug mode for developer, to get help to update sorting algorithm. I don't know the detailed thing about this issue. Is there a near-plan to fix I don't have a strong opinion about this. |
void assertValidTopologicalOrder(const std::vector<ir::OperationIndex> &order, | ||
const std::string &order_type) const; | ||
void assertValidBackwardTopologicalOrder(std::vector<ir::OperationIndex> order) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO,
- I believe
backwardTopologicalOrder
should always return correct answer. It is well-known problem. We already have several ones from compiler frontend in this repo, and internal repo. - If there was a bug, I would add regression testcase for
backwardTopologicalOrder
with your validate function.
This commit introduces the following functions - assertValidTopologicalOrder - assertValidBackwardTopologicalOrder which will catch any potential bugs on forward or backward topological ordering used in onert. ONE-DCO-1.0-Signed-off-by: YongHyun An <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This commit introduces the following functions
which will catch any potential bugs on forward or backward topological ordering used in onert.
ONE-DCO-1.0-Signed-off-by: YongHyun An [email protected]
From draft #12562