code: def _test_bn_update(
      self, data_tensor, dnn, device, label_tensor=None
  ):
      class DatasetFromTensors(data.Dataset):
          def __init__(self, X, y=None):
              self.X = X
              self.y = y
              self.N = self.X.shape[0]
  
          def __getitem__(self, index):
              x = self.X[index]
              if self.y is None:
                  return x
              else:
                  y = self.y[index]
                  return x, y
  
          def __len__(self):
              return self.N
  
      with_y = label_tensor is not None
      ds = DatasetFromTensors(data_tensor, y=label_tensor)
      dl = data.DataLoader(ds, batch_size=5, shuffle=True)
  
      preactivation_sum = torch.zeros(dnn.n_features, device=device)
      preactivation_squared_sum = torch.zeros(
          dnn.n_features, device=device
      )
      total_num = 0
      for x in dl:
          if with_y:
              x, _ = x
          x = x.to(device)
  
          dnn(x)
          preactivations = dnn.compute_preactivation(x)
          if len(preactivations.shape) == 4:
              preactivations = preactivations.transpose(1, 3)
          preactivations = preactivations.reshape(-1, dnn.n_features)
          total_num += preactivations.shape[0]
  
          preactivation_sum += torch.sum(preactivations, dim=0)
          preactivation_squared_sum += torch.sum(
              preactivations**2, dim=0
          )
  
      preactivation_mean = preactivation_sum / total_num
      preactivation_var = preactivation_squared_sum / total_num
      preactivation_var = preactivation_var - preactivation_mean**2
  
      swa = StochasticWeightAveraging(
          optim.SGD(dnn.parameters(), lr=1e-3)
      )
      swa.bn_update(dl, dnn, device=device)
      assert equal(preactivation_mean, dnn.bn.running_mean)
      assert equal(preactivation_var, dnn.bn.running_var, prec=1e-1)
  
imports: import contextlib
  import functools
  import re
  import warnings
  from unittest import TestCase
  import torch
  from pytext.optimizer import Lamb, StochasticWeightAveraging
  from torch import nn, optim, sparse
  from torch.autograd import Variable
  from torch.utils import data
label_desc: Use image node_id 17 for calling the TestSWA obj's underlying member method code with example usage: obj._test_bn_update(data_tensor, dnn, device, label_tensor) and returns: self, x, x,  y