GradientClipByValue

class paddle.fluid.clip.GradientClipByValue(max, min=None)[source]

Clips gradient values to the range [min, max].

Given a tensor t, this operation clips its value to min and max inplace.

  • Any values less than min are set to min.

  • Any values greater than max are set to max.

Parameters
  • max (float) – The maximum value to clip by.

  • min (float, optional) – The minimum value to clip by. if not set by user, will be set to -max by framework.

Examples

import paddle.fluid as fluid
w_param_attrs = fluid.ParamAttr(name=None,
  initializer=fluid.initializer.UniformInitializer(low=-1.0, high=1.0, seed=0),
  learning_rate=1.0,
  regularizer=fluid.regularizer.L1Decay(1.0),
  trainable=True,
  gradient_clip=fluid.clip.GradientClipByValue(-1.0, 1.0))
x = fluid.layers.data(name='x', shape=[10], dtype='float32')
y_predict = fluid.layers.fc(input=x, size=1, param_attr=w_param_attrs)