MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / GlobalNormClip

Class GlobalNormClip

tensorpack/tfutils/gradproc.py:83–102  ·  view source on GitHub ↗

Clip by global norm. The global norm is the sum of norm for **all** gradients. See :func:`tf.clip_by_global_norm` for more information.

Source from the content-addressed store, hash-verified

81
82
83class GlobalNormClip(GradientProcessor):
84 """ Clip by global norm.
85 The global norm is the sum of norm for **all** gradients.
86
87 See :func:`tf.clip_by_global_norm` for more information.
88 """
89
90 def __init__(self, global_norm):
91 """
92 Args:
93 global_norm(float): the threshold to clip with.
94 """
95 super(GlobalNormClip, self).__init__()
96 self._norm = float(global_norm)
97
98 def _process(self, grads):
99 g = [k[0] for k in grads]
100 v = [k[1] for k in grads]
101 g, _ = tf.clip_by_global_norm(g, self._norm, name='clip_by_global_norm')
102 return list(zip(g, v))
103
104
105class MapGradient(GradientProcessor):

Callers 2

optimizerMethod · 0.90
optimizerMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…