code: def run(
      train_batch_size,
      val_batch_size,
      epochs,
      lr,
      momentum,
      log_interval,
  ):
      vis = visdom.Visdom()
  
      # if not vis.check_connection():
      #     raise RuntimeError("Visdom server not running. Please run python -m visdom.server")
  
      train_loader, val_loader = get_data_loaders(
          train_batch_size, val_batch_size
      )
      model = Net()
      device = "cpu"
  
      if torch.cuda.is_available():
          device = "cuda"
  
      model.to(device)  # Move model before creating optimizer
      optimizer = SGD(model.parameters(), lr=lr, momentum=momentum)
      trainer = create_supervised_trainer(
          model, optimizer, F.nll_loss, device=device
      )
      evaluator = create_supervised_evaluator(
          model,
          metrics={"accuracy": Accuracy(), "nll": Loss(F.nll_loss)},
          device=device,
      )
  
      train_loss_window = create_plot_window(
          vis, "#Iterations", "Loss", "Training Loss"
      )
      train_avg_loss_window = create_plot_window(
          vis, "#Iterations", "Loss", "Training Average Loss"
      )
      train_avg_accuracy_window = create_plot_window(
          vis, "#Iterations", "Accuracy", "Training Average Accuracy"
      )
      val_avg_loss_window = create_plot_window(
          vis, "#Epochs", "Loss", "Validation Average Loss"
      )
      val_avg_accuracy_window = create_plot_window(
          vis, "#Epochs", "Accuracy", "Validation Average Accuracy"
      )
  
      @trainer.on(Events.ITERATION_COMPLETED(every=log_interval))
      def log_training_loss(engine):
          print(
              f"Epoch[{engine.state.epoch}] Iteration[{engine.state.iteration}/{len(train_loader)}] "
              f"Loss: {engine.state.output:.2f}"
          )
          vis.line(
              X=np.array([engine.state.iteration]),
              Y=np.array([engine.state.output]),
              update="append",
              win=train_loss_window,
          )
  
      @trainer.on(Events.EPOCH_COMPLETED)
      def log_training_results(engine):
          evaluator.run(train_loader)
          metrics = evaluator.state.metrics
          avg_accuracy = metrics["accuracy"]
          avg_nll = metrics["nll"]
          print(
              f"Training Results - Epoch: {engine.state.epoch} Avg accuracy: {avg_accuracy:.2f} Avg loss: {avg_nll:.2f}"
          )
          vis.line(
              X=np.array([engine.state.epoch]),
              Y=np.array([avg_accuracy]),
              win=train_avg_accuracy_window,
              update="append",
          )
          vis.line(
              X=np.array([engine.state.epoch]),
              Y=np.array([avg_nll]),
              win=train_avg_loss_window,
              update="append",
          )
  
      @trainer.on(Events.EPOCH_COMPLETED)
      def log_validation_results(engine):
          evaluator.run(val_loader)
          metrics = evaluator.state.metrics
          avg_accuracy = metrics["accuracy"]
          avg_nll = metrics["nll"]
          print(
              f"Validation Results - Epoch: {engine.state.epoch} Avg accuracy: {avg_accuracy:.2f} Avg loss: {avg_nll:.2f}"
          )
          vis.line(
              X=np.array([engine.state.epoch]),
              Y=np.array([avg_accuracy]),
              win=val_avg_accuracy_window,
              update="append",
          )
          vis.line(
              X=np.array([engine.state.epoch]),
              Y=np.array([avg_nll]),
              win=val_avg_loss_window,
              update="append",
          )
  
      # kick everything off
      trainer.run(train_loader, max_epochs=epochs)
  
file_path: ignite/examples/mnist/mnist_with_visdom.py
imports: from argparse import ArgumentParser
  import numpy
  import torch
  import torch.nn.functional
  from torch import nn
  from torch.optim import SGD
  from torch.utils.data import DataLoader
  from torchvision.datasets import MNIST
  from torchvision.transforms import Compose, Normalize, ToTensor
  from ignite.engine import create_supervised_evaluator, create_supervised_trainer, Events
  from ignite.metrics import Accuracy, Loss
label_desc: Use image node_id 3 for calling a global function with example usage: run(train_batch_size, val_batch_size, epochs, lr, momentum, log_interval) without return types