apply_gradient_clipping#
- composer.functional.apply_gradient_clipping(parameters, clipping_type, clipping_threshold)[source]#
Clips all gradients in model based on specified clipping_type.
- Parameters
parameters (Tensor or Iterable[Tensor]) โ The parameters to of the model for whose gradients we will clip
clipping_type ('adaptive', 'norm', 'value') โ String denoting which type of gradient clipping to do. The options are: โnormโ, which clips the gradient norm and uses torch.nn.utils.clip_grad_norm_, โvalueโ, which clips gradient at a specified value and uses torch.nn.utils.clip_grad_value_, and โadaptiveโ, which clips all gradients based on gradient norm:parameter norm ratio using composer.algorithms.gradient_clipping.gradient_clipping._apply_agc.
clipping_threshold (float, optional) โ Specifies what value to clip the gradients to (for โvalueโ), what values to clip the gradient norms to (for โnormโ), and threshold by which if grad_norm / weight_norm is greater than this threshold then scale gradients by this threshold * (weight_norm / grad_norm) (for โadaptiveโ).