code: def train(
      args,
      model,
      device,
      train_loader,
      optimizer,
      epoch_idx,
      core_context,
  ):
      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()
          optimizer.step()
  
          # NEW: Print training progress and loss at specified intervals
          # starting from the first batch.
          batches_completed = batch_idx + 1
          if batches_completed % args.log_interval == 0:
              print(
                  "Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}".format(
                      epoch_idx,
                      batch_idx * len(data),
                      len(train_loader.dataset),
                      100.0 * batch_idx / len(train_loader),
                      loss.item(),
                  )
              )
              # Docs snippet start: report training metrics
              # NEW: Report training metrics to Determined
              # master via core_context.
              # Index by (batch_idx + 1) * (epoch-1) * len(train_loader)
              # to continuously plot loss on one graph for consecutive
              # epochs.
              core_context.train.report_training_metrics(
                  steps_completed=batches_completed
                  + epoch_idx * len(train_loader),
                  metrics={"train_loss": loss.item()},
              )
              # Docs snippet end: report training metrics
              if args.dry_run:
                  break
  
file_path: determined/examples/tutorials/core_api_pytorch_mnist/model_def_metrics.py
imports: from __future__ import print_function
  import argparse
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torch.optim.lr_scheduler import StepLR
  from torchvision import datasets, transforms
  import determined
label_desc: Use image node_id 1 for calling a global function with example usage: train(args, model, device, train_loader, optimizer, epoch_idx, core_context) without return types