Skip to content

Commit

Permalink
fix chunk id of recv_v2 by find the next non -1 recusively (#69201)
Browse files Browse the repository at this point in the history
* fix chunk id of recv_v2 by find the next non -1 recusively

* reduce recursion
  • Loading branch information
zhiqiu authored Nov 7, 2024
1 parent 7edf283 commit e7a1936
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions python/paddle/distributed/passes/pass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
from paddle.distributed.auto_parallel.static.dist_attribute import (
OperatorDistAttr,
)
from paddle.distributed.auto_parallel.static.mix_to_dist_pass import (
dist_skip_op_list,
)
from paddle.distributed.auto_parallel.static.utils import (
get_logger,
is_backward_op,
Expand Down Expand Up @@ -803,16 +800,24 @@ def get_chunk_id(op_idx):


def find_var_used_op_chunk_id(var):
all_used_ops = var.all_used_ops()
for used_op in all_used_ops:
if used_op.name() in dist_skip_op_list:
for output_var in used_op.results():
chunk_id = find_var_used_op_chunk_id(output_var)
if chunk_id != -1:
return chunk_id
elif used_op.dist_attr and used_op.dist_attr.chunk_id != -1:
return used_op.dist_attr.chunk_id
return -1
visited = set()

def dfs(var):
all_used_ops = var.all_used_ops()
for used_op in all_used_ops:
if used_op in visited:
return -1
visited.add(used_op)
if used_op.dist_attr and used_op.dist_attr.chunk_id != -1:
return used_op.dist_attr.chunk_id
else:
for output_var in used_op.results():
chunk_id = dfs(output_var)
if chunk_id != -1:
return chunk_id
return -1

return dfs(var)


def _split_program_into_forward_backward_optimize(
Expand Down

0 comments on commit e7a1936

Please sign in to comment.