code: def train(epoch, batches=-1):
      global trainloader
      global testloader
      global net
      global criterion
      global optimizer
  
      print("\nEpoch: %d" % epoch)
      net.train()
      train_loss = 0
      correct = 0
      total = 0
      for batch_idx, (inputs, targets) in enumerate(trainloader):
          inputs, targets = inputs.to(device), targets.to(device)
          optimizer.zero_grad()
          outputs = net(inputs)
          loss = criterion(outputs, targets)
          loss.backward()
          optimizer.step()
  
          train_loss += loss.item()
          _, predicted = outputs.max(1)
          total += targets.size(0)
          correct += predicted.eq(targets).sum().item()
  
          acc = 100.0 * correct / total
  
          progress_bar(
              batch_idx,
              len(trainloader),
              "Loss: %.3f | Acc: %.3f%% (%d/%d)"
              % (
                  train_loss / (batch_idx + 1),
                  100.0 * correct / total,
                  correct,
                  total,
              ),
          )
  
          if batches > 0 and (batch_idx + 1) >= batches:
              return
  
file_path: nni/examples/trials/cifar10_pytorch/main.py
imports: from __future__ import print_function
  import argparse
  import torch
  import torch.nn
  import torch.optim
  import torch.nn.functional
  import torch.backends.cudnn
  import torchvision
  import torchvision.transforms
  import os
  import argparse
  import logging
  from models import *
  from utils import progress_bar
  import nni
label_desc: Use image node_id 2 for calling a global function with example usage: train(epoch, batches) without return types