Skip to content

Commit

Permalink
fix_dp_grad_merge_with_grad_clip_by_global_norm (#36334)
Browse files Browse the repository at this point in the history
  • Loading branch information
FeixLiu authored Oct 11, 2021
1 parent 00245cf commit 1026052
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

0 comments on commit 1026052

Please sign in to comment.