Skip to content

Commit

Permalink
fix_dp_grad_merge_with_grad_clip_by_global_norm
Browse files Browse the repository at this point in the history
  • Loading branch information
FeixLiu committed Oct 11, 2021
1 parent 71cb3ff commit a60d597
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/paddle/fluid/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .data_feeder import check_variable_and_dtype
from .framework import in_dygraph_mode
from .layer_helper import LayerHelper
from .framework import default_main_program

__all__ = [
'set_gradient_clip', 'ErrorClipByValue', 'ClipGradByValue',
Expand Down Expand Up @@ -547,7 +548,12 @@ def _static_clip(self, params_grads):
scale_input = (scale_var.astype('float16')
if g.dtype == core.VarDesc.VarType.FP16 else
scale_var)
p.block.append_op(
# NOTE(Yuang Liu): For pure dp with gradient merge, the p and g
# will be in different blocks with the gradient clip related ops.
# We need to handle the correct block, otherwise will encounter
# a 'NotFoundError' during compile time.
block = default_main_program().current_block()
block.append_op(
type='elementwise_mul',
inputs={'X': g,
'Y': scale_input},
Expand Down

1 comment on commit a60d597

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.