code: def test_pytorch_single_output(torch_device):
      """Testing single outputs"""
      torch = pytest.importorskip("torch")
  
      from sklearn.datasets import fetch_california_housing
      from torch import nn
      from torch.nn import functional as F
      from torch.utils.data import DataLoader, TensorDataset
  
      class Net(nn.Module):
          """Test model."""
  
          def __init__(self, num_features):
              super().__init__()
              self.linear = nn.Linear(num_features // 2, 2)
              self.conv1d = nn.Conv1d(1, 1, 1)
              self.convt1d = nn.ConvTranspose1d(1, 1, 1)
              self.leaky_relu = nn.LeakyReLU()
              self.aapool1d = nn.AdaptiveAvgPool1d(
                  output_size=num_features // 2
              )
              self.maxpool2 = nn.MaxPool1d(kernel_size=2)
  
          def forward(self, X):
              """Run the model."""
              x = self.aapool1d(
                  self.convt1d(self.conv1d(X.unsqueeze(1)))
              ).squeeze(1)
              return self.maxpool2(
                  self.linear(self.leaky_relu(x)).unsqueeze(1)
              ).squeeze(1)
  
      def train(model, device, train_loader, optimizer, epoch):
          model.train()
          num_examples = 0
          for batch_idx, (data, target) in enumerate(train_loader):
              num_examples += target.shape[0]
              data, target = data.to(device), target.to(device)
              optimizer.zero_grad()
              output = model(data)
              loss = F.mse_loss(output.squeeze(1), target)
              loss.backward()
              optimizer.step()
              if batch_idx % 2 == 0:
                  print(
                      "Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}".format(
                          epoch,
                          batch_idx * len(data),
                          len(train_loader.dataset),
                          100.0 * batch_idx / len(train_loader),
                          loss.item(),
                      )
                  )
  
      # FIXME: this test should ideally pass with any random seed. See #2960
      random_seed = 0
      torch.manual_seed(random_seed)
      rs = np.random.RandomState(random_seed)
  
      X, y = fetch_california_housing(return_X_y=True)
  
      num_features = X.shape[1]
  
      data = TensorDataset(
          torch.tensor(X).float(),
          torch.tensor(y).float(),
      )
  
      loader = DataLoader(data, batch_size=128)
  
      model = Net(num_features)
      optimizer = torch.optim.Adam(model.parameters())
  
      device = torch.device(torch_device)
  
      model.to(device)
  
      train(model, device, loader, optimizer, 1)
  
      next_x, _ = next(iter(loader))
      inds = rs.choice(next_x.shape[0], 20, replace=False)
  
      next_x_random_choices = next_x[inds, :].to(device)
  
      e = shap.DeepExplainer(model, next_x_random_choices)
      test_x_tmp, _ = next(iter(loader))
      test_x = test_x_tmp[:1].to(device)
  
      shap_values = e.shap_values(test_x)
  
      model.eval()
      model.zero_grad()
  
      with torch.no_grad():
          diff = (
              (model(test_x) - model(next_x_random_choices))
              .detach()
              .cpu()
              .numpy()
              .mean(0)
          )
  
      sums = np.array(
          [shap_values[i].sum() for i in range(len(shap_values))]
      )
      d = np.abs(sums - diff).sum() / np.abs(diff).sum()
  
      assert (
          d < 0.001
      ), f"Sum of SHAP values does not match difference! {d}"
  
file_path: shap/tests/explainers/test_deep.py
imports: import numpy
  import pandas
  import pytest
  from packaging import version
  import shap
  from shap import DeepExplainer
label_desc: Use image node_id 8 for calling a global function with example usage: test_pytorch_single_output(torch_device) and returns: self