Skip to content

Commit

Permalink
Revert "fast inverse_sort_op (#69980)" (#70158)
Browse files Browse the repository at this point in the history
This reverts commit a162cf0.
  • Loading branch information
cubehan3 authored Dec 16, 2024
1 parent b432d27 commit b67c88f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions python/paddle/autograd/backward_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,18 @@ def inverse_sort_op(old_ops):
# pending edges for its grad_op

pending_count = collections.defaultdict(int)
ops_set = set(old_ops)
ops = []
[ops.append(x) for x in old_ops if x not in ops]
ops_set = set(ops)
sorted_list = []
for op in ops_set:
for op in ops:
for x in get_real_op_inputs(op):
if not pir.is_fake_value(x) and x.get_defining_op() in ops_set:
pending_count[x.get_defining_op()] += 1

queue = collections.deque()

for op in ops_set:
for op in ops:
if pending_count[op] == 0:
queue.append(op)

Expand All @@ -456,7 +458,7 @@ def inverse_sort_op(old_ops):
if pending_count[x_op] == 0:
queue.append(x_op)

if len(sorted_list) != len(ops_set):
if len(sorted_list) != len(ops):
raise ValueError(
"inverse_sort_op wrong, sorted_list size is not equal to origin_list size"
)
Expand Down

0 comments on commit b67c88f

Please sign in to comment.