megengine.optimizer.clip_grad_value

clip_grad_value(tensors, lower, upper)[源代码]

Clips gradient of an iterable of parameters to a specified lower and upper. Gradients are modified in-place.

The gradients are clipped in the range:

\[\left[\text{lower}, \text{upper}\right]\]
参数
  • tensors (Union[Tensor, Iterable[Tensor]]) – an iterable of Tensors or a single Tensor.

  • lower (float) – minimum allowed value of the gradients.

  • upper (float) – maximum allowed value of the gradients.