code: def train(args, model, device, train_loader, optimizer, epoch):
      model.train()
      for batch_idx, (data, target) in enumerate(train_loader):
          if (args["batch_num"] is not None) and batch_idx >= args[
              "batch_num"
          ]:
              break
          data, target = data.to(device), target.to(device)
          optimizer.zero_grad()
          output = model(data)
          loss = F.nll_loss(output, target)
          loss.backward()
          optimizer.step()
          if batch_idx % args["log_interval"] == 0:
              logger.info(
                  "Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}".format(
                      epoch,
                      batch_idx * len(data),
                      len(train_loader.dataset),
                      100.0 * batch_idx / len(train_loader),
                      loss.item(),
                  )
              )
  
file_path: nni/examples/trials/mnist-sharedstorage/mnist.py
imports: import os
  import argparse
  import logging
  import nni
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from nni.utils import merge_parameter
  from torchvision import datasets, transforms
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