diff --git a/olive/strategy/utils.py b/olive/strategy/utils.py index ab8bd82e9..4839b7701 100644 --- a/olive/strategy/utils.py +++ b/olive/strategy/utils.py @@ -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)