code: def run(
      epochs,
      lr,
      momentum,
      log_interval,
      params,
      trainloader,
      testloader,
      model,
  ):
      device = "cuda" if torch.cuda.is_available() else "cpu"
      net = Net(params).to(device)
      criterion = nn.CrossEntropyLoss()
      optimizer = optim.SGD(net.parameters(), lr=lr, momentum=momentum)
  
      trainer = create_supervised_trainer(
          net, optimizer, criterion, device=device
      )
      trainer.logger = setup_logger("trainer")
  
      val_metrics = {
          "accuracy": Accuracy(),
          "loss": Loss(criterion),
          "recall": Recall(),
      }
      evaluator = create_supervised_evaluator(
          net, metrics=val_metrics, device=device
      )
      evaluator.logger = setup_logger("evaluator")
  
      # Attach handler to plot trainer's loss every 100 iterations
      tb_logger = TensorboardLogger(log_dir="cifar-output")
      tb_logger.attach_output_handler(
          trainer,
          event_name=Events.ITERATION_COMPLETED(
              every=params.get("loss_report")
          ),
          tag="training",
          output_transform=lambda loss: {"loss": loss},
      )
  
      # Attach handler to dump evaluator's metrics every epoch completed
      for tag, evaluator in [
          ("training", trainer),
          ("validation", evaluator),
      ]:
          tb_logger.attach_output_handler(
              evaluator,
              event_name=Events.EPOCH_COMPLETED,
              tag=tag,
              metric_names="all",
              global_step_transform=global_step_from_engine(trainer),
          )
  
      # Attach function to build debug images and report every epoch end
      tb_logger.attach(
          evaluator,
          log_handler=predictions_gt_images_handler,
          event_name=Events.EPOCH_COMPLETED(once=1),
      )
  
      desc = "ITERATION - loss: {:.2f}"
      pbar = tqdm(
          initial=0,
          leave=False,
          total=len(trainloader),
          desc=desc.format(0),
      )
  
      @trainer.on(Events.ITERATION_COMPLETED(every=log_interval))
      def log_training_loss(engine):
          pbar.desc = desc.format(engine.state.output)
          pbar.update(log_interval)
  
      @trainer.on(Events.EPOCH_COMPLETED)
      def log_training_results(engine):
          pbar.refresh()
          evaluator.run(trainloader)
          metrics = evaluator.state.metrics
          avg_accuracy = metrics["accuracy"]
          avg_nll = metrics["loss"]
          tqdm.write(
              "Training Results - Epoch: {}  Avg accuracy: {:.2f} Avg loss: {:.2f}".format(
                  engine.state.epoch, avg_accuracy, avg_nll
              )
          )
  
      @trainer.on(Events.EPOCH_COMPLETED)
      def log_validation_results(engine):
          evaluator.run(testloader)
          metrics = evaluator.state.metrics
          avg_accuracy = metrics["accuracy"]
          avg_nll = metrics["loss"]
          tqdm.write(
              "Validation Results - Epoch: {}  Avg accuracy: {:.2f} Avg loss: {:.2f}".format(
                  engine.state.epoch, avg_accuracy, avg_nll
              )
          )
  
          pbar.n = pbar.last_print_n = 0
  
      @trainer.on(Events.EPOCH_COMPLETED | Events.COMPLETED)
      def log_time():
          tqdm.write(
              "{} took {} seconds".format(
                  trainer.last_event_name.name,
                  trainer.state.times[trainer.last_event_name.name],
              )
          )
  
      trainer.run(trainloader, max_epochs=epochs)
      pbar.close()
  
      PATH = "./cifar_net.pth"
  
      # CONDITION depicts a custom condition for when to save the model. The model is saved and then updated in ClearML
      CONDITION = True
  
      if CONDITION:
          torch.save(net.state_dict(), PATH)
          model.update_weights(weights_filename=PATH)
      print("Finished Training")
      print("Task ID number is: {}".format(Task.current_task().id))
  
imports: from pathlib import Path
  import matplotlib.pyplot
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  import torchvision.datasets
  import torchvision.transforms
  from ignite.contrib.handlers import TensorboardLogger
  from ignite.engine import Events, create_supervised_trainer, create_supervised_evaluator
  from ignite.handlers import global_step_from_engine
  from ignite.metrics import Accuracy, Loss, Recall
  from ignite.utils import setup_logger
  from torch.utils.tensorboard import SummaryWriter
  from tqdm import tqdm
  from clearml import Task, StorageManager, OutputModel
label_desc: Use image node_id 3 for calling a global function with example usage: run(epochs, lr, momentum, log_interval, params, trainloader, testloader, model) without return types