code: def train(args, model, device, train_loader, optimizer, epoch):
      model.train()
      for batch_idx, (data, target) in enumerate(train_loader):
          data, target = data.to(device), target.to(device)
          optimizer.zero_grad()
          output = model(data)
          loss = F.nll_loss(output, target)
          loss.backward()
  
          for p in model.parameters():
              if (
                  not hasattr(p, "skip_allreduce")
                  and p.grad is not None
              ):
                  p.grad = net.simple_all_reduce(p.grad)
  
          optimizer.step()
  
          pred = output.argmax(dim=1, keepdim=True)
          correct = pred.eq(target.view_as(pred)).sum().item()
          total_items = int(output.size(0))
  
          if batch_idx % args.log_interval == 0:
              penv.dist_print(
                  "Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}\tTrain Accuracy: {}/{} ({:.2f}%)".format(
                      epoch,
                      batch_idx * len(data),
                      len(train_loader.dataset),
                      100.0 * batch_idx / len(train_loader),
                      loss.item(),
                      correct,
                      total_items,
                      100.0 * correct / total_items,
                  )
              )
              if args.dry_run:
                  break
  
file_path: tutel/tutel/examples/moe_mnist.py
imports: import argparse
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torchvision import datasets, transforms
  from torch.optim.lr_scheduler import StepLR
  from tutel import system
  from tutel import moe
  from tutel import net
  import logging
label_desc: Use image node_id 1 for calling a global function with example usage: train(args, model, device, train_loader, optimizer, epoch) without return types