code: def rescale_gradients(model: Model, grad_norm: Optional[float] = None) -> Optional[float]:
      
      if grad_norm:
          parameters_to_clip = [p for p in model.parameters()
                                if p.grad is not None]
          return sparse_clip_norm(parameters_to_clip, grad_norm)
      return None
docs: Performs gradient rescaling. Is a no-op if gradient rescaling is not enabled.