code: def update_bn(loader, model, device=None):
      r"""Updates BatchNorm running_mean, running_var buffers in the model.
  
      It performs one pass over data in `loader` to estimate the activation
      statistics for BatchNorm layers in the model.
      Args:
          loader (torch.utils.data.DataLoader): dataset loader to compute the
              activation statistics on. Each data batch should be either a
              tensor, or a list/tuple whose first element is a tensor
              containing data.
          model (torch.nn.Module): model for which we seek to update BatchNorm
              statistics.
          device (torch.device, optional): If set, data will be transferred to
              :attr:`device` before being passed into :attr:`model`.
  
      Example:
          >>> # xdoctest: +SKIP("Undefined variables")
          >>> loader, model = ...
          >>> torch.optim.swa_utils.update_bn(loader, model)
  
      .. note::
          The `update_bn` utility assumes that each data batch in :attr:`loader`
          is either a tensor or a list or tuple of tensors; in the latter case it
          is assumed that :meth:`model.forward()` should be called on the first
          element of the list or tuple corresponding to the data batch.
      """
      momenta = {}
      for module in model.modules():
          if isinstance(module, torch.nn.modules.batchnorm._BatchNorm):
              module.reset_running_stats()
              momenta[module] = module.momentum
  
      if not momenta:
          return
  
      was_training = model.training
      model.train()
      for module in momenta.keys():
          module.momentum = None
  
      for input in loader:
          if isinstance(input, (list, tuple)):
              input = input[0]
          if device is not None:
              input = input.to(device)
  
          model(input)
  
      for bn_module in momenta.keys():
          bn_module.momentum = momenta[bn_module]
      model.train(was_training)
  
imports: import itertools
  import math
  from copy import deepcopy
  import warnings
  import torch
  from torch.nn import Module
  from torch.optim.lr_scheduler import LRScheduler
  from torch.utils._foreach_utils import _get_foreach_kernels_supported_devices
  from torch.utils._foreach_utils import _group_tensors_by_device_and_dtype
label_desc: Use image node_id 5 for calling a global function with example usage: update_bn(loader, model, device) without return types