class_docstr: An instance ``scaler`` helps perform the steps of gradient scaling
  conveniently.
class_docstr_tok: ["An","instance","``","scaler","``","helps","perform","the","steps","of","gradient","scaling","conveniently","."]
code: def _get_gradients_norm(
      self, params: List[torch.nn.Parameter]
  ) -> float:
      grads = []
      for p in params:
          if p.grad is None:
              continue
          else:
              grads.append(p.grad.detach())
  
      if len(grads) == 0:
          return 0.0
  
      if len(grads) == 1:
          total_norm = torch.norm(grads[0], p=2, dtype=torch.float32)  # type: ignore
      else:
          total_norm = torch.norm(torch.stack([torch.norm(g, p=2, dtype=torch.float32) for g in grads]))  # type: ignore
      return total_norm.item()
  
file_path: fairscale/fairscale/experimental/optim/dynamic_loss_scaler.py
imports: from collections import defaultdict
  from enum import Enum
  from typing import Dict, List, Optional
  import torch
label_desc: Use image node_id 3 for calling the DynamicLossScaler obj's underlying member method code with example usage: obj._get_gradients_norm(params) and returns: total_norm, int