code: def _batchnorm_to_groupnorm(
      module: BATCHNORM, *, num_groups: Optional[int] = None
  ) -> nn.GroupNorm:
      """
      Converts a BatchNorm ``module`` to GroupNorm module.
      This is a helper function.
  
      Args:
          module: BatchNorm module to be replaced
  
      Returns:
          GroupNorm module that can replace the BatchNorm module provided
  
      Notes:
          A default value of 32 is chosen for the number of groups based on the
          paper *Group Normalization* https://arxiv.org/abs/1803.08494
      """
      if num_groups is None:
          num_groups = math.gcd(32, module.num_features)
  
      return nn.GroupNorm(
          num_groups, module.num_features, affine=module.affine
      )
  
file_path: opacus/opacus/validators/batch_norm.py
imports: import logging
  import math
  from typing import List, Optional, Union
  import torch.nn
  from .errors import ShouldReplaceModuleError, UnsupportableModuleError, UnsupportedModuleError
  from .utils import register_module_fixer, register_module_validator
label_desc: Use image node_id 3 for calling a global function with example usage: _batchnorm_to_groupnorm(module) and returns: nn