Skip to content

Commit

Permalink
Fix graph vertex ordering during topological ordering (#1546)
Browse files Browse the repository at this point in the history
## Fix graph vertex ordering during topological ordering

Previous implementation returned vertices in reverse order even when
there are no dependencies in the graph. Iterate the vertices in reverse
order so input order can be retained.

## Checklist before requesting a review
- [ ] Add unit tests for this change.
- [ ] Make sure all tests can pass.
- [ ] Update documents if necessary.
- [ ] Lint and apply fixes to your code by running `lintrunner -a`
- [ ] Is this a user-facing change? If yes, give a description of this
change to be included in the release notes.
- [ ] Is this PR including examples changes? If yes, please remember to
update [example
documentation](https://github.com/microsoft/Olive/blob/main/docs/source/examples.md)
in a follow-up PR.

## (Optional) Issue link
  • Loading branch information
shaahji authored Jan 14, 2025
1 parent d27a078 commit c1e1365
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion olive/strategy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def topological_sort(self):
visited = set()
order = []

for v in self.vertices:
# Since the dependee vertex is inserted in front, iterate the vertices in
# reverse order to retain the relative order of vertices in the graph.
# Without it the graph vertices are reversed even in cases where no
# dependency exist.
for v in reversed(self.vertices):
if v not in visited:
self._topological_sort_util(v, visited, order)

Expand Down

0 comments on commit c1e1365

Please sign in to comment.