Skip to content
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

fix shared param grad_add op_device is null #33875

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions python/paddle/fluid/backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def _addup_repetitive_outputs_(op_descs, block_idx):
var_rename_count = collections.defaultdict(int)
renamed_vars = collections.defaultdict(list)
renamed_var_start_idx = collections.defaultdict(list)
var_device = collections.defaultdict(str)
for idx, op_desc in enumerate(op_descs):
op_device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName(
)
Expand Down Expand Up @@ -528,16 +529,19 @@ def _addup_repetitive_outputs_(op_descs, block_idx):
arg_names[arg_idx] = new_name
op_desc.set_output(param_name, arg_names)
renamed_vars[var_name].append(new_name)
# record the latest device, for shared param
var_device[var_name] = op_device

for var_name, inputs in six.iteritems(renamed_vars):
if len(renamed_vars[var_name]) > 1:
if len(renamed_vars[var_name]) > _MAX_ADD_NUM_:
_accumulate_gradients_by_sum_op_(var_name, renamed_vars,
pending_sum_ops, len(op_descs))
_accumulate_gradients_by_sum_op_(
var_name, renamed_vars, pending_sum_ops,
len(op_descs), var_device[var_name])
else:
_accumulate_gradients_by_add_ops_(var_name, renamed_vars,
pending_sum_ops,
len(op_descs))
_accumulate_gradients_by_add_ops_(
var_name, renamed_vars, pending_sum_ops,
len(op_descs), var_device[var_name])

# sum_op descs are sorted according to their insert position
for key, value in collections.OrderedDict(
Expand Down