code: def apply_dynamic_loss_scaling(
      loss_scaling,
      master_params_grads,
      incr_every_n_steps,
      decr_every_n_nan_or_inf,
      incr_ratio,
      decr_ratio,
  ):
      _incr_every_n_steps = fluid.layers.fill_constant(
          shape=[1], dtype="int32", value=incr_every_n_steps
      )
      _decr_every_n_nan_or_inf = fluid.layers.fill_constant(
          shape=[1], dtype="int32", value=decr_every_n_nan_or_inf
      )
  
      _num_good_steps = fluid.layers.create_global_var(
          name=fluid.unique_name.generate("num_good_steps"),
          shape=[1],
          value=0,
          dtype="int32",
          persistable=True,
      )
      _num_bad_steps = fluid.layers.create_global_var(
          name=fluid.unique_name.generate("num_bad_steps"),
          shape=[1],
          value=0,
          dtype="int32",
          persistable=True,
      )
  
      grads = [
          fluid.layers.reduce_sum(g) for [_, g] in master_params_grads
      ]
      all_grads = fluid.layers.concat(grads)
      all_grads_sum = fluid.layers.reduce_sum(all_grads)
      is_overall_finite = fluid.layers.isfinite(all_grads_sum)
  
      update_loss_scaling(
          is_overall_finite,
          loss_scaling,
          _num_good_steps,
          _num_bad_steps,
          _incr_every_n_steps,
          _decr_every_n_nan_or_inf,
          incr_ratio,
          decr_ratio,
      )
  
      # apply_gradient append all ops in global block, thus we shouldn't
      # apply gradient in the switch branch.
      with fluid.layers.Switch() as switch:
          with switch.case(is_overall_finite):
              pass
          with switch.default():
              for _, g in master_params_grads:
                  fluid.layers.assign(fluid.layers.zeros_like(g), g)
  
file_path: PGL/ogb_examples/linkproppred/ogbl-ppa/utils/fp16.py
imports: from __future__ import print_function
  import paddle
  import paddle.fluid
label_desc: Use image node_id 3 for calling a global function with example usage: apply_dynamic_loss_scaling(loss_scaling, master_params_grads, incr_every_n_steps, decr_every_n_nan_or_inf, incr_ratio, decr_ratio) without return types