code: def train_and_eval_model(model, mnist_dataset, pruner, num_epochs):
      # setup data loaders
      train, test = mnist_dataset
      train_loader = torch.utils.data.DataLoader(
          train, batch_size=batch_size, shuffle=True
      )
      test_loader = torch.utils.data.DataLoader(
          test, batch_size=batch_size
      )
  
      # train the model
      optimizer = torch.optim.Adam(
          model.parameters(), eps=1e-07, weight_decay=1e-4
      )
  
      # train one epoch
      for epoch in range(num_epochs):
          model.train()
          for batch_idx, (data, target) in enumerate(train_loader):
              optimizer.zero_grad()
              output = model(data)
              loss = F.nll_loss(output, target)
              loss.backward()
              optimizer.step()
              pruner.step()
              if batch_idx % 100 == 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(),
                      )
                  )
                  # if not isinstance(pruner, GlobalChannelPruner):
                  #     print(pruner.get_submodule_sparsity_summaries())
  
      accuracy = eval_model(model, test_loader)
      return accuracy
  
file_path: coremltools/coremltools/test/optimize/torch/pruning/pruning_utils.py
imports: import numpy
  import torch
  import torch.nn.functional
  import os
label_desc: Use image node_id 2 for calling a global function with example usage: train_and_eval_model(model, mnist_dataset, pruner, num_epochs) and returns: accuracy