megengine.optimizer.clip_grad_value¶
- clip_grad_value(tensors, lower, upper)[source]¶
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]\]- Parameters
- Returns
None.
Examples
>>> import megengine.optimizer as optim >>> net = Net() >>> optim.clip_grad_value(net.parameters(), lower=-2, upper=5)